|
| 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_iter_interface VERSION 0.0.0 LANGUAGES CXX) |
| 8 | +project( |
| 9 | + beman.iterator_interface |
| 10 | + VERSION 0.0.0 |
| 11 | + LANGUAGES CXX) |
8 | 12 |
|
| 13 | +# Local helpers: required to include CompilerFeatureTest. |
9 | 14 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") |
| 15 | + |
| 16 | +# Includes |
| 17 | +include(CTest) |
10 | 18 | include(FetchContent) |
11 | 19 | include(CompilerFeatureTest) |
12 | 20 |
|
| 21 | +# Prechecks. |
13 | 22 | beman_iterator_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS) |
14 | 23 |
|
| 24 | +set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) |
| 25 | + |
15 | 26 | option(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS |
16 | | - "Make use of deducing this. Turn this off for non-conforming compilers." |
17 | | - ${COMPILER_SUPPORTS_DEDUCING_THIS}) |
| 27 | + "Make use of C++23 \"deducing this\" feature (P0847R7). Turn this off for non-conforming compilers." |
| 28 | + ${COMPILER_SUPPORTS_DEDUCING_THIS}) |
18 | 29 |
|
19 | | -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}) |
20 | 32 |
|
21 | | -if(BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS AND NOT COMPILER_SUPPORTS_DEDUCING_THIS) |
22 | | - 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 C++23 \"deducing this\" feature (P0847R7) despite of the compiler's lack of actual support for it." |
| 38 | + ) |
23 | 39 | endif() |
24 | 40 |
|
25 | 41 | configure_file( |
26 | 42 | "${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in" |
27 | | - "${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp" |
28 | | - @ONLY |
29 | | -) |
30 | | - |
31 | | -if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING) |
32 | | - 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) |
33 | 55 | endif() |
34 | 56 |
|
35 | | -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 | +add_library(beman::iterator_interface ALIAS beman.iterator_interface) |
| 60 | + |
| 61 | +target_sources( |
| 62 | + beman.iterator_interface |
| 63 | + PUBLIC FILE_SET |
| 64 | + beman_iterator_interface_headers |
| 65 | + TYPE |
| 66 | + HEADERS |
| 67 | + BASE_DIRS |
| 68 | + src |
| 69 | + include) |
| 70 | + |
| 71 | +target_include_directories( |
| 72 | + beman.iterator_interface |
| 73 | + PUBLIC |
| 74 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 75 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> |
| 76 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}> |
| 77 | +) |
36 | 78 |
|
37 | | -add_subdirectory(extern) |
38 | 79 | add_subdirectory(src/beman/iterator_interface) |
39 | | -add_subdirectory(examples) |
| 80 | +add_subdirectory(include/beman/iterator_interface) |
40 | 81 |
|
41 | | -include(GNUInstallDirs) |
42 | | - |
43 | | -set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake) |
44 | | - |
45 | | -install( |
46 | | - EXPORT ${TARGETS_EXPORT_NAME} |
47 | | - NAMESPACE ${CMAKE_PROJECT_NAME} |
48 | | - DESTINATION ${INSTALL_CONFIGDIR} |
49 | | - ) |
50 | | - |
51 | | -include(CMakePackageConfigHelpers) |
52 | | - |
53 | | -write_basic_package_version_file( |
54 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake |
55 | | - VERSION ${PROJECT_VERSION} |
56 | | - COMPATIBILITY AnyNewerVersion |
57 | | -) |
| 82 | +add_subdirectory(examples) |
| 83 | +if(ITERATOR_INTERFACE_ENABLE_TESTING) |
| 84 | + add_subdirectory(tests) |
| 85 | +endif() |
58 | 86 |
|
59 | | -configure_package_config_file( |
60 | | - "cmake/Config.cmake.in" |
61 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake |
62 | | - INSTALL_DESTINATION ${INSTALL_CONFIGDIR} |
63 | | -) |
| 87 | +# Coverage |
| 88 | +configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY) |
64 | 89 |
|
65 | | -install(FILES |
66 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake |
67 | | - ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake |
68 | | - DESTINATION ${INSTALL_CONFIGDIR} |
69 | | -) |
| 90 | +add_custom_target( |
| 91 | + process_coverage |
| 92 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 93 | + COMMENT "Running gcovr to process coverage results" |
| 94 | + COMMAND mkdir -p coverage |
| 95 | + COMMAND gcovr --config gcovr.cfg .) |
0 commit comments