|
| 1 | +# cmake-format: off |
1 | 2 | # CMakeLists.txt -*-CMake-*- |
2 | | -# |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | +# cmake-format: on |
4 | 5 |
|
5 | | -cmake_minimum_required(VERSION 3.10) |
| 6 | +cmake_minimum_required(VERSION 3.27) |
6 | 7 |
|
7 | | -project(beman_iterator_interface VERSION 0.0.0 LANGUAGES CXX) |
| 8 | +project( |
| 9 | + beman_iterator_interface |
| 10 | + VERSION 0.0.0 |
| 11 | + LANGUAGES CXX) |
8 | 12 |
|
9 | 13 | # Local helpers: required to include CompilerFeatureTest. |
10 | 14 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") |
11 | 15 |
|
12 | 16 | # Includes |
| 17 | +include(CTest) |
13 | 18 | include(FetchContent) |
14 | 19 | include(CompilerFeatureTest) |
15 | 20 |
|
| 21 | +# Prechecks. |
16 | 22 | beman_iterator_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS) |
17 | 23 |
|
| 24 | +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) |
| 25 | + |
18 | 26 | option(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS |
19 | | - "Make use of deducing this. Turn this off for non-conforming compilers." |
20 | | - ${COMPILER_SUPPORTS_DEDUCING_THIS}) |
| 27 | + "Make use of deducing this. Turn this off for non-conforming compilers." |
| 28 | + ${COMPILER_SUPPORTS_DEDUCING_THIS}) |
21 | 29 |
|
22 | | -option(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING "Build beman.iterator_interface tests" ${PROJECT_IS_TOP_LEVEL}) |
| 30 | +option(ITERATOR_INTERFACE_ENABLE_TESTING |
| 31 | + "Enable building tests and test infrastructure" ${PROJECT_IS_TOP_LEVEL}) |
23 | 32 |
|
24 | | -if(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS AND NOT COMPILER_SUPPORTS_DEDUCING_THIS) |
25 | | - message(WARNING "Building with deducing this support despite of the compiler's lack of support for it") |
| 33 | +if(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS |
| 34 | + AND NOT COMPILER_SUPPORTS_DEDUCING_THIS) |
| 35 | + message( |
| 36 | + WARNING |
| 37 | + "Building with deducing this support despite of the compiler's lack of support for it" |
| 38 | + ) |
26 | 39 | endif() |
27 | 40 |
|
28 | 41 | configure_file( |
29 | 42 | "${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in" |
30 | | - "${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp" |
31 | | - @ONLY |
32 | | -) |
33 | | - |
34 | | -if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING) |
35 | | - enable_testing() |
| 43 | + "${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp" @ONLY) |
| 44 | + |
| 45 | +# Build the tests if enabled via the option ITERATOR_INTERFACE_ENABLE_TESTING |
| 46 | +if(ITERATOR_INTERFACE_ENABLE_TESTING) |
| 47 | + # Fetch GoogleTest |
| 48 | + FetchContent_Declare( |
| 49 | + googletest |
| 50 | + EXCLUDE_FROM_ALL |
| 51 | + GIT_REPOSITORY https://github.com/google/googletest.git |
| 52 | + GIT_TAG e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0 |
| 53 | + ) |
| 54 | + FetchContent_MakeAvailable(googletest) |
36 | 55 | endif() |
37 | 56 |
|
38 | | -set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) |
| 57 | +# Create the library target and named header set for beman_iterator_interface |
| 58 | +add_library(beman_iterator_interface STATIC) |
| 59 | +target_sources( |
| 60 | + beman_iterator_interface |
| 61 | + PUBLIC FILE_SET |
| 62 | + beman_iterator_interface_headers |
| 63 | + TYPE |
| 64 | + HEADERS |
| 65 | + BASE_DIRS |
| 66 | + src |
| 67 | + include |
| 68 | + "${PROJECT_BINARY_DIR}/include/") |
39 | 69 |
|
40 | | -add_subdirectory(extern) |
41 | 70 | add_subdirectory(src/beman/iterator_interface) |
42 | | -add_subdirectory(examples) |
43 | | - |
44 | | -include(GNUInstallDirs) |
| 71 | +add_subdirectory(include/beman/iterator_interface) |
45 | 72 |
|
46 | | -set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake) |
| 73 | +add_subdirectory(examples) |
| 74 | +if(ITERATOR_INTERFACE_ENABLE_TESTING) |
| 75 | + add_subdirectory(tests) |
| 76 | +endif() |
47 | 77 |
|
48 | | -install( |
49 | | - EXPORT ${TARGETS_EXPORT_NAME} |
50 | | - NAMESPACE ${CMAKE_PROJECT_NAME} |
51 | | - DESTINATION ${INSTALL_CONFIGDIR} |
52 | | - ) |
| 78 | +# Coverage |
| 79 | +configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY) |
53 | 80 |
|
54 | | -include(CMakePackageConfigHelpers) |
55 | | - |
56 | | -write_basic_package_version_file( |
57 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake |
58 | | - VERSION ${PROJECT_VERSION} |
59 | | - COMPATIBILITY AnyNewerVersion |
60 | | -) |
61 | | - |
62 | | -configure_package_config_file( |
63 | | - "cmake/Config.cmake.in" |
64 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake |
65 | | - INSTALL_DESTINATION ${INSTALL_CONFIGDIR} |
66 | | -) |
67 | | - |
68 | | -install(FILES |
69 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake |
70 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake |
71 | | - DESTINATION ${INSTALL_CONFIGDIR} |
72 | | -) |
| 81 | +add_custom_target( |
| 82 | + process_coverage |
| 83 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 84 | + COMMENT "Running gcovr to process coverage results" |
| 85 | + COMMAND mkdir -p coverage |
| 86 | + COMMAND gcovr --config gcovr.cfg .) |
0 commit comments