@@ -12,51 +12,49 @@ include(FetchContent)
12
12
13
13
set (TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME} Targets)
14
14
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)
17
23
# Fetch GoogleTest
18
24
FetchContent_Declare(
19
25
googletest
26
+ EXCLUDE_FROM_ALL
20
27
GIT_REPOSITORY https://github.com/google/googletest.git
21
28
GIT_TAG
22
29
e39786088138f2749d64e9e90e0f9902daa77c40 # release-1.15.0
23
30
)
24
31
FetchContent_MakeAvailable(googletest)
25
32
endif ()
26
33
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
38
39
)
39
40
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 ()
47
53
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)
53
56
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)
60
58
61
59
# Coverage
62
60
configure_file ("cmake/gcovr.cfg.in" gcovr.cfg @ONLY)
0 commit comments