Skip to content

Commit 4888aa1

Browse files
committed
Apply more Beman Standard tweaks for cmake files
1 parent 4b87aac commit 4888aa1

File tree

5 files changed

+127
-113
lines changed

5 files changed

+127
-113
lines changed

CMakeLists.txt

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,86 @@
1+
# cmake-format: off
12
# CMakeLists.txt -*-CMake-*-
2-
#
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
# cmake-format: on
45

5-
cmake_minimum_required(VERSION 3.10)
6+
cmake_minimum_required(VERSION 3.27)
67

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)
812

913
# Local helpers: required to include CompilerFeatureTest.
1014
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
1115

1216
# Includes
17+
include(CTest)
1318
include(FetchContent)
1419
include(CompilerFeatureTest)
1520

21+
# Prechecks.
1622
beman_iterator_check_deducing_this(COMPILER_SUPPORTS_DEDUCING_THIS)
1723

24+
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
25+
1826
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})
2129

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})
2332

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+
)
2639
endif()
2740

2841
configure_file(
2942
"${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)
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
62+
beman_iterator_interface_headers
63+
TYPE
64+
HEADERS
65+
BASE_DIRS
66+
src
67+
include
68+
"${PROJECT_BINARY_DIR}/include/")
3969

40-
add_subdirectory(extern)
4170
add_subdirectory(src/beman/iterator_interface)
42-
add_subdirectory(examples)
43-
44-
include(GNUInstallDirs)
71+
add_subdirectory(include/beman/iterator_interface)
4572

46-
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
73+
add_subdirectory(examples)
74+
if(ITERATOR_INTERFACE_ENABLE_TESTING)
75+
add_subdirectory(tests)
76+
endif()
4777

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)
5380

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 .)

examples/CMakeLists.txt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
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.
8-
set(EXAMPLES
9-
sample
10-
)
7+
set(EXAMPLES sample)
118

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

1613
# Add example source file.
17-
target_sources(
18-
${EXAMPLE}
19-
PRIVATE
20-
${EXAMPLE}.cpp
21-
)
14+
target_sources(${example} PRIVATE ${example}.cpp)
2215

2316
# Link example with the library.
24-
target_link_libraries(${EXAMPLE} beman.iterator_interface)
17+
target_link_libraries(${example} beman_iterator_interface)
2518

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

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-
)
6+
# Ensure that iterator_interface gets compiled at least once.
7+
target_sources(beman_iterator_interface PUBLIC iterator_interface.cpp)
228

9+
# The library is empty -- exclude it
2310
install(
24-
TARGETS beman.iterator_interface
25-
EXPORT ${TARGETS_EXPORT_NAME}1
26-
DESTINATION ${CMAKE_INSTALL_LIBDIR}
27-
)
28-
29-
string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME)
11+
TARGETS beman_iterator_interface
12+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
13+
COMPONENT beman_iterator_interface_library
14+
EXCLUDE_FROM_ALL)
3015

3116
install(
32-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
33-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}
34-
FILES_MATCHING PATTERN "*.hpp"
35-
)
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()
17+
TARGETS beman_iterator_interface FILE_SET beman_iterator_interface_headers
18+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
19+
COMPONENT beman_iterator_interface_development)

tests/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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(beman_iterator_interface_test
12+
PRIVATE iterator_interface.test.cpp)
13+
14+
target_sources(
15+
beman_iterator_interface_test
16+
PRIVATE FILE_SET beman_iterator_interface_test_headers TYPE HEADERS)
17+
18+
target_link_libraries(
19+
beman_iterator_interface_test PRIVATE beman_iterator_interface GTest::gtest
20+
GTest::gtest_main)
21+
22+
# Issue #32: Re-enable ASAN run CI/clang-19.
23+
#
24+
# Note: clang-19 + gtest_discover_tests + Asan setup causes errors on some
25+
# platforms. Temporary switch to gtest_add_tests and skip some Asan checks.
26+
# Change also applied for CI flows.
27+
gtest_add_tests(TARGET beman_iterator_interface_test "" AUTO)

0 commit comments

Comments
 (0)