Skip to content

Commit 9847480

Browse files
authored
Merge pull request bemanproject#73 from steve-downey/install_sets
Install sets
2 parents 31c4462 + 50ded6a commit 9847480

File tree

8 files changed

+79
-70
lines changed

8 files changed

+79
-70
lines changed

CMakeLists.txt

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,49 @@ include(FetchContent)
1212

1313
set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets)
1414

15-
# Build the tests only if enabled via the CLI flag: BUILD_TESTING.
16-
if(BUILD_TESTING)
15+
option(
16+
OPTIONAL26_ENABLE_TESTING
17+
"Enable building tests and test infrastructure"
18+
${PROJECT_IS_TOP_LEVEL}
19+
)
20+
21+
# Build the tests if enabled via the option OPTIONAL26_ENABLE_TESTING
22+
if(OPTIONAL26_ENABLE_TESTING)
1723
# Fetch GoogleTest
1824
FetchContent_Declare(
1925
googletest
26+
EXCLUDE_FROM_ALL
2027
GIT_REPOSITORY https://github.com/google/googletest.git
2128
GIT_TAG
2229
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
2330
)
2431
FetchContent_MakeAvailable(googletest)
2532
endif()
2633

27-
add_subdirectory(src/beman/optional26)
28-
add_subdirectory(examples)
29-
30-
include(GNUInstallDirs)
31-
32-
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
33-
34-
install(
35-
EXPORT ${TARGETS_EXPORT_NAME}
36-
NAMESPACE ${CMAKE_PROJECT_NAME}
37-
DESTINATION ${INSTALL_CONFIGDIR}
34+
# Create the library target and named header set for beman_optional26
35+
add_library(beman_optional26 STATIC)
36+
target_sources(
37+
beman_optional26
38+
PUBLIC FILE_SET beman_optional26_headers TYPE HEADERS BASE_DIRS src include
3839
)
3940

40-
include(CMakePackageConfigHelpers)
41-
42-
write_basic_package_version_file(
43-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
44-
VERSION ${PROJECT_VERSION}
45-
COMPATIBILITY AnyNewerVersion
46-
)
41+
if(OPTIONAL26_ENABLE_TESTING)
42+
# Create the library target and named header set for testing beman_optional26
43+
# and mark the set private
44+
add_executable(beman_optional26_test)
45+
target_sources(
46+
beman_optional26_test
47+
PRIVATE
48+
FILE_SET beman_optional26_test_headers
49+
TYPE HEADERS
50+
BASE_DIRS src
51+
)
52+
endif()
4753

48-
configure_package_config_file(
49-
"cmake/Config.cmake.in"
50-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
51-
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
52-
)
54+
add_subdirectory(src/beman/optional26)
55+
add_subdirectory(include/beman/optional26)
5356

54-
install(
55-
FILES
56-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake
57-
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
58-
DESTINATION ${INSTALL_CONFIGDIR}
59-
)
57+
add_subdirectory(examples)
6058

6159
# Coverage
6260
configure_file("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ TARGET:=all
6363
compile: $(_build_path)/CMakeCache.txt ## Compile the project
6464
cmake --build $(_build_path) --config $(CONFIG) --target all -- -k 0
6565

66-
install: $(_build_path)/CMakeCache.txt ## Install the project
67-
DESTDIR=$(abspath $(DEST)) ninja -C $(_build_path) -k 0 install
66+
install: $(_build_path)/CMakeCache.txt compile ## Install the project
67+
cmake --install $(_build_path) --config $(CONFIG) --component beman_optional26_development --verbose
6868

6969
ctest: $(_build_path)/CMakeCache.txt ## Run CTest on current build
7070
cd $(_build_path) && ctest --output-on-failure -C $(CONFIG)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ This should build and run the tests with GCC 14 with the address and undefined b
202202
CI current build and test flows:
203203

204204
```shell
205-
# Configure build: default build production code + tests (BUILD_TESTING=ON by default).
205+
# Configure build: default build production code + tests (OPTIONAL26_ENABLE_TESTING=ON by default).
206206
$ cmake -G "Ninja Multi-Config" \
207207
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
208208
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
@@ -228,14 +228,14 @@ Total Test time (real) = 0.67 sec
228228

229229
##### Build Production, but Skip Tests
230230

231-
By default, we build and run tests. You can provide `-DBUILD_TESTING=OFF` and completely disable building tests:
231+
By default, we build and run tests. You can provide `-DOPTIONAL26_ENABLE_TESTING=OFF` and completely disable building tests:
232232

233233
```shell
234-
# Configure build: build production code, skip tests (BUILD_TESTING=OFF).
234+
# Configure build: build production code, skip tests (OPTIONAL26_ENABLE_TESTING=OFF).
235235
$ cmake -G "Ninja Multi-Config" \
236236
-DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \
237237
-DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \
238-
-DBUILD_TESTING=OFF \
238+
-DOPTIONAL26_ENABLE_TESTING=OFF \
239239
-B .build -S .
240240
-- The CXX compiler identification is Clang 19.0.0
241241
...

examples/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ foreach(example ${EXAMPLES})
2929

3030
# Install .
3131
install(
32-
TARGETS ${example}
33-
EXPORT ${TARGETS_EXPORT_NAME}
34-
DESTINATION
35-
${CMAKE_INSTALL_BINDIR}
32+
TARGETS
33+
${example}
34+
COMPONENT
35+
beman_optional26_examples
36+
DESTINATION
37+
${CMAKE_INSTALL_BINDIR}
3638
)
3739
endforeach()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# include/beman/optional26/CMakeLists.txt -*-cmake-*-
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
target_sources(
5+
beman_optional26
6+
PUBLIC
7+
FILE_SET beman_optional26_headers
8+
TYPE HEADERS
9+
FILES
10+
optional.hpp
11+
detail/iterator.hpp
12+
detail/stl_interfaces/config.hpp
13+
detail/stl_interfaces/fwd.hpp
14+
detail/stl_interfaces/iterator_interface.hpp
15+
)

src/beman/optional26/CMakeLists.txt

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
1-
# cmake-format: off
2-
# src/beman/optional26/CMakeLists.txt -*-makefile-*-
1+
# src/beman/optional26/CMakeLists.txt -*-cmake-*-
32
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4-
# cmake-format: on
53

6-
add_library(beman_optional26 STATIC optional.cpp detail/iterator.cpp)
7-
8-
include(GNUInstallDirs)
9-
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
10-
11-
target_include_directories(
12-
beman_optional26
13-
PUBLIC
14-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../include>
15-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../../src/>
16-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}>
17-
)
4+
# Ensure that optional and iterator get compiled at least once
5+
target_sources(beman_optional26 PUBLIC optional.cpp detail/iterator.cpp)
186

7+
# The library is empty -- exclude it
198
install(
209
TARGETS beman_optional26
21-
EXPORT ${TARGETS_EXPORT_NAME}
22-
DESTINATION
23-
${CMAKE_INSTALL_LIBDIR}
10+
ARCHIVE
11+
DESTINATION ${CMAKE_INSTALL_LIBDIR}
12+
COMPONENT beman_optional26_library
13+
EXCLUDE_FROM_ALL
2414
)
2515

26-
string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_LOWER_PROJECT_NAME)
27-
2816
install(
29-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
30-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_LOWER_PROJECT_NAME}
31-
FILES_MATCHING
32-
PATTERN "*.hpp"
17+
TARGETS beman_optional26
18+
FILE_SET beman_optional26_headers
19+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
20+
COMPONENT beman_optional26_development
3321
)
3422

35-
target_link_libraries(beman_optional26)
36-
3723
# Tests
38-
if(BUILD_TESTING)
24+
if(OPTIONAL26_ENABLE_TESTING)
3925
add_subdirectory(tests)
4026
endif()

src/beman/optional26/tests/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
include(GoogleTest)
77

88
# Tests
9-
add_executable(beman_optional26_test)
9+
# add_executable(beman_optional26_test)
1010

1111
target_sources(
1212
beman_optional26_test
@@ -21,6 +21,14 @@ target_sources(
2121
test_utilities.cpp
2222
)
2323

24+
target_sources(
25+
beman_optional26_test
26+
PRIVATE
27+
FILE_SET beman_optional26_test_headers
28+
TYPE HEADERS
29+
FILES test_types.hpp test_utilities.hpp
30+
)
31+
2432
target_link_libraries(
2533
beman_optional26_test
2634
PRIVATE beman_optional26 GTest::gtest GTest::gtest_main

src/beman/optional26/tests/test_constructor_fail.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// src/Beman/Optional26/tests/test_constructor_fail.t.cpp -*-C++-*-
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
#include <Beman/Optional26/optional.hpp>
4+
#include <beman/optional26/optional.hpp>
55
#include <string>
66
#include <utility>
77

0 commit comments

Comments
 (0)