@@ -12,51 +12,49 @@ include(FetchContent)
1212
1313set (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 (OPTIONAL26_ENABLE_TESTING
16+ "Enable building tests and test infrastructure"
17+ ${PROJECT_IS_TOP_LEVEL} )
18+
19+ # Build the tests if enabled via the option OPTIONAL26_ENABLE_TESTING
20+ if (OPTIONAL26_ENABLE_TESTING)
1721 # Fetch GoogleTest
1822 FetchContent_Declare(
1923 googletest
24+ EXCLUDE_FROM_ALL
2025 GIT_REPOSITORY https://github.com/google/googletest.git
2126 GIT_TAG
2227 e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
2328 )
2429 FetchContent_MakeAvailable(googletest)
2530endif ()
2631
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}
32+ # Create the library target and named header set for beman_optional26
33+ add_library (beman_optional26 STATIC )
34+ target_sources (beman_optional26
35+ PUBLIC
36+ FILE_SET beman_optional26_headers TYPE HEADERS
37+ BASE_DIRS
38+ src
39+ include
3840)
3941
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
42+ if (OPTIONAL26_ENABLE_TESTING)
43+ # Create the library target and named header set for testing beman_optional26
44+ # and mark the set private
45+ add_executable (beman_optional26_test)
46+ target_sources (beman_optional26_test
47+ PRIVATE
48+ FILE_SET beman_optional26_test_headers TYPE HEADERS
49+ BASE_DIRS
50+ src
4651)
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
6260configure_file ("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
0 commit comments