-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
112 lines (97 loc) · 3.67 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(option VERSION 1.3.4 LANGUAGES CXX)
option(OPTION_TEST "Enable 'option-test' target" ${PROJECT_IS_TOP_LEVEL})
option(OPTION_EXAMPLES "Enable 'option-examples' target" ${PROJECT_IS_TOP_LEVEL})
option(OPTION_BENCHMARK "Enable benchmarks targets" FALSE)
option(OPTION_CODEGEN_TEST "Enable 'option-codegen-test' target" TRUE)
option(USE_SANITIZER "Enable sanitizers for test target" TRUE)
option(USE_CLANG_TIDY "Enable clang-tidy for test target" FALSE)
option(OPTION_INSTALL "Enable --install for 'option' project" FALSE)
option(OPTION_USE_NATVIS "Enable .natvis file for Visual Studio debugger" TRUE)
option(OPTION_USE_NATSTEPFILTER "Enable .natstepfilter file for Visual Studio debugger" FALSE)
option(USE_LIBASSERT "Enable libassert library integration" TRUE)
add_library(option INTERFACE
"include/opt/option.hpp"
"include/opt/option_fwd.hpp"
)
if (NOT PROJECT_IS_TOP_LEVEL)
set(include_as_system "SYSTEM")
endif()
target_include_directories(option ${include_as_system} INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
)
target_compile_features(option INTERFACE cxx_std_17)
if (OPTION_USE_NATVIS)
target_sources(option INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/debugger/option.natvis>)
endif()
if (OPTION_USE_NATSTEPFILTER)
target_sources(option INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/debugger/option.natstepfilter>)
endif()
if (NOT OPTION_INSTALL)
if (DEFINED OPTION_EXTRA_FLAGS)
separate_arguments(OPTION_EXTRA_FLAGS)
add_compile_options(${OPTION_EXTRA_FLAGS})
add_link_options(${OPTION_EXTRA_FLAGS})
endif()
if (OPTION_TEST)
add_subdirectory(test ${exclude_from_all})
endif()
if (OPTION_EXAMPLES)
add_subdirectory(examples ${exclude_from_all})
endif()
if (OPTION_BENCHMARK)
add_subdirectory(benchmark ${exclude_from_all})
endif()
if (OPTION_CODEGEN_TEST)
add_subdirectory(test/codegen ${exclude_from_all})
endif()
else() # ^^^ NOT OPTION_INSTALL / vvv OPTION_INSTALL
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# https://cmake.org/cmake/help/latest/command/find_package.html#search-modes
# Generate config file
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/option-config.cmake.in"
"${PROJECT_BINARY_DIR}/option-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/option"
)
# Generate version file
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/option-config-version.cmake"
# VERSION is implicit
COMPATIBILITY ExactVersion
ARCH_INDEPENDENT
)
# Install cmake config files
install(
FILES
"${PROJECT_BINARY_DIR}/option-config.cmake"
"${PROJECT_BINARY_DIR}/option-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/option"
)
# Generate option targets
install(
TARGETS option
EXPORT option-targets
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Install option targets
install(
EXPORT option-targets
FILE "option-targets.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/option"
)
# Install headers
install(
DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Install natvis and natstepfilter
install(
FILES "${PROJECT_SOURCE_DIR}/debugger/option.natvis"
"${PROJECT_SOURCE_DIR}/debugger/option.natstepfilter"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/debugger"
)
endif()