diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bac071..c8e0594 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.27) project(beman_iterator_interface VERSION 0.0.0 LANGUAGES CXX) @@ -10,63 +10,72 @@ project(beman_iterator_interface VERSION 0.0.0 LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # Includes +include(CTest) include(FetchContent) include(CompilerFeatureTest) +# Prechecks. beman_iterator_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS) -option(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS - "Make use of deducing this. Turn this off for non-conforming compilers." - ${COMPILER_SUPPORTS_DEDUCING_THIS}) +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) + +option( + BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS + "Make use of deducing this. Turn this off for non-conforming compilers." + ${COMPILER_SUPPORTS_DEDUCING_THIS} +) -option(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING "Build beman.iterator_interface tests" ${PROJECT_IS_TOP_LEVEL}) +option( + ITERATOR_INTERFACE_ENABLE_TESTING + "Enable building tests and test infrastructure" + ${PROJECT_IS_TOP_LEVEL} +) if(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS AND NOT COMPILER_SUPPORTS_DEDUCING_THIS) - message(WARNING "Building with deducing this support despite of the compiler's lack of support for it") + message(WARNING "Building with deducing this support despite of the compiler's lack of support for it") endif() configure_file( - "${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in" - "${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp" - @ONLY + "${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in" + "${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp" + @ONLY ) -if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING) - enable_testing() +# Build the tests if enabled via the option ITERATOR_INTERFACE_ENABLE_TESTING +if(ITERATOR_INTERFACE_ENABLE_TESTING) + # Fetch GoogleTest + FetchContent_Declare( + googletest + EXCLUDE_FROM_ALL + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG + e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0 + ) + FetchContent_MakeAvailable(googletest) endif() -set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) +# Create the library target and named header set for beman_iterator_interface +add_library(beman_iterator_interface STATIC) +target_sources( + beman_iterator_interface + PUBLIC FILE_SET beman_iterator_interface_headers TYPE HEADERS BASE_DIRS src include "${PROJECT_BINARY_DIR}/include/" +) -add_subdirectory(extern) add_subdirectory(src/beman/iterator_interface) -add_subdirectory(examples) - -include(GNUInstallDirs) +add_subdirectory(include/beman/iterator_interface) -set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake) - -install( - EXPORT ${TARGETS_EXPORT_NAME} - NAMESPACE ${CMAKE_PROJECT_NAME} - DESTINATION ${INSTALL_CONFIGDIR} - ) - -include(CMakePackageConfigHelpers) - -write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion -) +add_subdirectory(examples) +if(ITERATOR_INTERFACE_ENABLE_TESTING) + add_subdirectory(tests) +endif() -configure_package_config_file( - "cmake/Config.cmake.in" - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake - INSTALL_DESTINATION ${INSTALL_CONFIGDIR} -) +# Coverage +configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY) -install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake - DESTINATION ${INSTALL_CONFIGDIR} +add_custom_target( + process_coverage + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running gcovr to process coverage results" + COMMAND mkdir -p coverage + COMMAND gcovr --config gcovr.cfg . ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0cb5c05..04c9a99 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,32 +1,30 @@ -# examples/CMakeLists.txt -*-CMake-*- -# +# cmake-format: off +# examples/CMakeLists.txt -*-makefile-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -include(GNUInstallDirs) +# cmake-format: on # List of all buildable examples. set(EXAMPLES - sample + sample ) -foreach(EXAMPLE ${EXAMPLES}) - # Add example executable. - add_executable(${EXAMPLE} "") +foreach(example ${EXAMPLES}) + # Add example executable. + add_executable(${example} "") - # Add example source file. - target_sources( - ${EXAMPLE} - PRIVATE - ${EXAMPLE}.cpp - ) + # Add example source file. + target_sources(${example} PRIVATE ${example}.cpp) - # Link example with the library. - target_link_libraries(${EXAMPLE} beman.iterator_interface) + # Link example with the library. + target_link_libraries(${example} beman_iterator_interface) - # Install . - install( - TARGETS ${EXAMPLE} - EXPORT ${TARGETS_EXPORT_NAME} - DESTINATION ${CMAKE_INSTALL_BINDIR} - ) + # Install. + install( + TARGETS + ${example} + COMPONENT + beman_iterator_interface_examples + DESTINATION + ${CMAKE_INSTALL_BINDIR} + ) endforeach() diff --git a/include/beman/iterator_interface/CMakeLists.txt b/include/beman/iterator_interface/CMakeLists.txt new file mode 100644 index 0000000..a8a18a2 --- /dev/null +++ b/include/beman/iterator_interface/CMakeLists.txt @@ -0,0 +1,15 @@ +# include/beman/iterator_interface/CMakeLists.txt -*-cmake-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +target_sources( + beman_iterator_interface + PUBLIC + FILE_SET beman_iterator_interface_headers + TYPE HEADERS + FILES + iterator_interface.hpp + iterator_interface_access.hpp + detail/stl_interfaces/config.hpp + detail/stl_interfaces/fwd.hpp + detail/stl_interfaces/iterator_interface.hpp +) diff --git a/src/beman/iterator_interface/CMakeLists.txt b/src/beman/iterator_interface/CMakeLists.txt index bcea9a3..a45cfde 100644 --- a/src/beman/iterator_interface/CMakeLists.txt +++ b/src/beman/iterator_interface/CMakeLists.txt @@ -1,55 +1,21 @@ -# src/beman/iterator_interface/CMakeLists.txt -*-CMake-*- -# +# src/beman/iterator_interface/CMakeLists.txt -*-cmake-*- # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -add_library(beman.iterator_interface) -add_library(beman::iterator_interface ALIAS beman.iterator_interface) - -target_sources( - beman.iterator_interface - PRIVATE - iterator_interface.cpp -) - -include(GNUInstallDirs) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - -target_include_directories(beman.iterator_interface PUBLIC - $ - $ - $ # /include/scratch -) +# Ensure that iterator_interface gets compiled at least once. +target_sources(beman_iterator_interface PUBLIC iterator_interface.cpp) +# The library is empty -- exclude it install( - TARGETS beman.iterator_interface - EXPORT ${TARGETS_EXPORT_NAME}1 - DESTINATION ${CMAKE_INSTALL_LIBDIR} + TARGETS beman_iterator_interface + ARCHIVE + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT beman_iterator_interface_library + EXCLUDE_FROM_ALL ) -string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME) - install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME} - FILES_MATCHING PATTERN "*.hpp" + TARGETS beman_iterator_interface + FILE_SET beman_iterator_interface_headers + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT beman_iterator_interface_development ) - -target_link_libraries(beman.iterator_interface) - -## Tests -if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING) - add_executable(iterator_interface_test "") - - target_sources( - iterator_interface_test - PRIVATE - iterator_interface.t.cpp - ) - - target_link_libraries(iterator_interface_test beman.iterator_interface) - target_link_libraries(iterator_interface_test GTest::gtest) - target_link_libraries(iterator_interface_test GTest::gtest_main) - - include(GoogleTest) - gtest_discover_tests(iterator_interface_test) -endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..09a2fd5 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +# cmake-format: off +# src/beman/iterator_interface/tests/CMakeLists.txt -*-makefile-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# cmake-format: on + +include(GoogleTest) + +# Tests +add_executable(beman_iterator_interface_test) + +target_sources( + beman_iterator_interface_test + PRIVATE + iterator_interface.test.cpp +) + +target_sources( + beman_iterator_interface_test + PRIVATE + FILE_SET beman_iterator_interface_test_headers + TYPE HEADERS +) + +target_link_libraries( + beman_iterator_interface_test + PRIVATE beman_iterator_interface GTest::gtest GTest::gtest_main +) + +# Issue #32: Re-enable ASAN run CI/clang-19. +# +# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some +# platforms. Temporary switch to gtest_add_tests and skip some Asan checks. +# Change also applied for CI flows. +gtest_add_tests(TARGET beman_iterator_interface_test "" AUTO)