@@ -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 (
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)
2532endif ()
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
6260configure_file ("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
0 commit comments