Skip to content

Commit 051ab21

Browse files
committed
Apply more Beman Standard tweaks for cmake files
1 parent 4b87aac commit 051ab21

File tree

5 files changed

+131
-109
lines changed

5 files changed

+131
-109
lines changed

CMakeLists.txt

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,80 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
cmake_minimum_required(VERSION 3.10)
5+
cmake_minimum_required(VERSION 3.27)
66

77
project(beman_iterator_interface VERSION 0.0.0 LANGUAGES CXX)
88

99
# Local helpers: required to include CompilerFeatureTest.
1010
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
1111

1212
# Includes
13+
include(CTest)
1314
include(FetchContent)
1415
include(CompilerFeatureTest)
1516

17+
# Prechecks.
1618
beman_iterator_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS)
1719

18-
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})
20+
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
21+
22+
option(
23+
BEMAN_ITERATOR_INTERFACE_USE_DEDUCING_THIS
24+
"Make use of deducing this. Turn this off for non-conforming compilers."
25+
${COMPILER_SUPPORTS_DEDUCING_THIS}
26+
)
2127

22-
option(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING "Build beman.iterator_interface tests" ${PROJECT_IS_TOP_LEVEL})
28+
option(
29+
ITERATOR_INTERFACE_ENABLE_TESTING
30+
"Enable building tests and test infrastructure"
31+
${PROJECT_IS_TOP_LEVEL}
32+
)
2333

2434
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")
35+
message(WARNING "Building with deducing this support despite of the compiler's lack of support for it")
2636
endif()
2737

2838
configure_file(
29-
"${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in"
30-
"${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp"
31-
@ONLY
39+
"${PROJECT_SOURCE_DIR}/include/beman/iterator_interface/config.hpp.in"
40+
"${PROJECT_BINARY_DIR}/include/beman/iterator_interface/config.hpp"
41+
@ONLY
3242
)
3343

34-
if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING)
35-
enable_testing()
44+
# Build the tests if enabled via the option ITERATOR_INTERFACE_ENABLE_TESTING
45+
if(ITERATOR_INTERFACE_ENABLE_TESTING)
46+
# Fetch GoogleTest
47+
FetchContent_Declare(
48+
googletest
49+
EXCLUDE_FROM_ALL
50+
GIT_REPOSITORY https://github.com/google/googletest.git
51+
GIT_TAG
52+
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
53+
)
54+
FetchContent_MakeAvailable(googletest)
3655
endif()
3756

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 beman_iterator_interface_headers TYPE HEADERS BASE_DIRS src include "${PROJECT_BINARY_DIR}/include/"
62+
)
3963

40-
add_subdirectory(extern)
4164
add_subdirectory(src/beman/iterator_interface)
42-
add_subdirectory(examples)
43-
44-
include(GNUInstallDirs)
65+
add_subdirectory(include/beman/iterator_interface)
4566

46-
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
47-
48-
install(
49-
EXPORT ${TARGETS_EXPORT_NAME}
50-
NAMESPACE ${CMAKE_PROJECT_NAME}
51-
DESTINATION ${INSTALL_CONFIGDIR}
52-
)
53-
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-
)
67+
add_subdirectory(examples)
68+
if(ITERATOR_INTERFACE_ENABLE_TESTING)
69+
add_subdirectory(tests)
70+
endif()
6171

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-
)
72+
# Coverage
73+
configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
6774

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}
75+
add_custom_target(
76+
process_coverage
77+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
78+
COMMENT "Running gcovr to process coverage results"
79+
COMMAND mkdir -p coverage
80+
COMMAND gcovr --config gcovr.cfg .
7281
)

examples/CMakeLists.txt

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
# examples/CMakeLists.txt -*-CMake-*-
2-
#
1+
# cmake-format: off
2+
# examples/CMakeLists.txt -*-makefile-*-
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4-
5-
include(GNUInstallDirs)
4+
# cmake-format: on
65

76
# List of all buildable examples.
87
set(EXAMPLES
9-
sample
8+
sample
109
)
1110

12-
foreach(EXAMPLE ${EXAMPLES})
13-
# Add example executable.
14-
add_executable(${EXAMPLE} "")
11+
foreach(example ${EXAMPLES})
12+
# Add example executable.
13+
add_executable(${example} "")
1514

16-
# Add example source file.
17-
target_sources(
18-
${EXAMPLE}
19-
PRIVATE
20-
${EXAMPLE}.cpp
21-
)
15+
# Add example source file.
16+
target_sources(${example} PRIVATE ${example}.cpp)
2217

23-
# Link example with the library.
24-
target_link_libraries(${EXAMPLE} beman.iterator_interface)
18+
# Link example with the library.
19+
target_link_libraries(${example} beman_iterator_interface)
2520

26-
# Install .
27-
install(
28-
TARGETS ${EXAMPLE}
29-
EXPORT ${TARGETS_EXPORT_NAME}
30-
DESTINATION ${CMAKE_INSTALL_BINDIR}
31-
)
21+
# Install.
22+
install(
23+
TARGETS
24+
${example}
25+
COMPONENT
26+
beman_iterator_interface_examples
27+
DESTINATION
28+
${CMAKE_INSTALL_BINDIR}
29+
)
3230
endforeach()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# include/beman/iterator_interface/CMakeLists.txt -*-cmake-*-
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
target_sources(
5+
beman_iterator_interface
6+
PUBLIC
7+
FILE_SET beman_iterator_interface_headers
8+
TYPE HEADERS
9+
FILES
10+
iterator_interface.hpp
11+
iterator_interface_access.hpp
12+
detail/stl_interfaces/config.hpp
13+
detail/stl_interfaces/fwd.hpp
14+
detail/stl_interfaces/iterator_interface.hpp
15+
)
Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,21 @@
1-
# src/beman/iterator_interface/CMakeLists.txt -*-CMake-*-
2-
#
1+
# src/beman/iterator_interface/CMakeLists.txt -*-cmake-*-
32
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
43

5-
add_library(beman.iterator_interface)
6-
add_library(beman::iterator_interface ALIAS beman.iterator_interface)
7-
8-
target_sources(
9-
beman.iterator_interface
10-
PRIVATE
11-
iterator_interface.cpp
12-
)
13-
14-
include(GNUInstallDirs)
15-
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
16-
17-
target_include_directories(beman.iterator_interface PUBLIC
18-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
19-
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
20-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}> # <prefix>/include/scratch
21-
)
4+
# Ensure that iterator_interface gets compiled at least once.
5+
target_sources(beman_iterator_interface PUBLIC iterator_interface.cpp)
226

7+
# The library is empty -- exclude it
238
install(
24-
TARGETS beman.iterator_interface
25-
EXPORT ${TARGETS_EXPORT_NAME}1
26-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
9+
TARGETS beman_iterator_interface
10+
ARCHIVE
11+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
12+
COMPONENT beman_iterator_interface_library
13+
EXCLUDE_FROM_ALL
2714
)
2815

29-
string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME)
30-
3116
install(
32-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
33-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}
34-
FILES_MATCHING PATTERN "*.hpp"
17+
TARGETS beman_iterator_interface
18+
FILE_SET beman_iterator_interface_headers
19+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
20+
COMPONENT beman_iterator_interface_development
3521
)
36-
37-
target_link_libraries(beman.iterator_interface)
38-
39-
## Tests
40-
if(BEMAN_ITERATOR_INTERFACE_ENABLE_TESTING)
41-
add_executable(iterator_interface_test "")
42-
43-
target_sources(
44-
iterator_interface_test
45-
PRIVATE
46-
iterator_interface.t.cpp
47-
)
48-
49-
target_link_libraries(iterator_interface_test beman.iterator_interface)
50-
target_link_libraries(iterator_interface_test GTest::gtest)
51-
target_link_libraries(iterator_interface_test GTest::gtest_main)
52-
53-
include(GoogleTest)
54-
gtest_discover_tests(iterator_interface_test)
55-
endif()

tests/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# cmake-format: off
2+
# src/beman/iterator_interface/tests/CMakeLists.txt -*-makefile-*-
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
# cmake-format: on
5+
6+
include(GoogleTest)
7+
8+
# Tests
9+
add_executable(beman_iterator_interface_test)
10+
11+
target_sources(
12+
beman_iterator_interface_test
13+
PRIVATE
14+
iterator_interface.test.cpp
15+
)
16+
17+
target_sources(
18+
beman_iterator_interface_test
19+
PRIVATE
20+
FILE_SET beman_iterator_interface_test_headers
21+
TYPE HEADERS
22+
)
23+
24+
target_link_libraries(
25+
beman_iterator_interface_test
26+
PRIVATE beman_iterator_interface GTest::gtest GTest::gtest_main
27+
)
28+
29+
# Issue #32: Re-enable ASAN run CI/clang-19.
30+
#
31+
# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some
32+
# platforms. Temporary switch to gtest_add_tests and skip some Asan checks.
33+
# Change also applied for CI flows.
34+
gtest_add_tests(TARGET beman_iterator_interface_test "" AUTO)

0 commit comments

Comments
 (0)