This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
204 lines (169 loc) · 6.84 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
cmake_minimum_required(VERSION 3.14)
cmake_policy(SET CMP0127 NEW)
if(NOT DEFINED PROJECT_NAME)
set(POLYMORPHIC_IS_NOT_SUBPROJECT ON)
endif()
set(POLYMOPHIC_VALUE_VERSION 1.3.0) # Revision 3, see paper p0201r3
project(polymorphic_value LANGUAGES CXX VERSION ${POLYMOPHIC_VALUE_VERSION})
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
endif()
option(ENABLE_SANITIZERS "Enable Address Sanitizer and Undefined Behaviour Sanitizer if available" OFF)
option(ENABLE_CODE_COVERAGE "Enable code coverage if available (Mac OS X currently not supported)" OFF)
include(CTest)
include(FetchContent)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
add_subdirectory(documentation)
add_library(polymorphic_value INTERFACE)
target_include_directories(polymorphic_value
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_sources(polymorphic_value
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_value.h>
# Only include natvis files in Visual Studio
$<BUILD_INTERFACE:$<$<CXX_COMPILER_ID:MSVC>:${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_value.natvis>>
$<INSTALL_INTERFACE:$<$<CXX_COMPILER_ID:MSVC>:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/polymorphic_value.natvis>>
)
target_compile_features(polymorphic_value
INTERFACE
cxx_std_17
)
# namespaced alias for users depending on polymorphic_value as a sub-project.
add_library(polymorphic_value::polymorphic_value ALIAS polymorphic_value)
if(POLYMORPHIC_IS_NOT_SUBPROJECT)
if (${BUILD_TESTING})
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.3.2
)
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
endif()
add_executable(polymorphic_value_test polymorphic_value_test.cpp)
target_link_libraries(polymorphic_value_test
PRIVATE
polymorphic_value::polymorphic_value
Catch2::Catch2WithMain
)
target_compile_options(polymorphic_value_test
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Werror;-Wall;-Wno-self-assign-overloaded;-Wno-unknown-warning-option>
)
set_target_properties(polymorphic_value_test PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
if (ENABLE_SANITIZERS)
set(SANITIZER_FLAGS_ASAN "-fsanitize=address -fno-omit-frame-pointer")
set(SANITIZER_FLAGS_UBSAN "-fsanitize=undefined")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("${SANITIZER_FLAGS_ASAN}" COMPILER_SUPPORTS_ASAN)
check_cxx_compiler_flag("${SANITIZER_FLAGS_UBSAN}" COMPILER_SUPPORTS_UBSAN)
if (COMPILER_SUPPORTS_ASAN)
add_library(asan INTERFACE IMPORTED)
set_target_properties(asan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_ASAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_ASAN}"
)
target_link_libraries(polymorphic_value_test
PRIVATE
asan
)
endif(COMPILER_SUPPORTS_ASAN)
if (COMPILER_SUPPORTS_UBSAN)
add_library(ubsan INTERFACE IMPORTED)
set_target_properties(ubsan PROPERTIES
INTERFACE_COMPILE_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
INTERFACE_LINK_OPTIONS "${SANITIZER_FLAGS_UBSAN}"
)
target_link_libraries(polymorphic_value_test
PRIVATE
ubsan
)
endif(COMPILER_SUPPORTS_UBSAN)
endif(ENABLE_SANITIZERS)
enable_testing()
add_test(
NAME polymorphic_value_test
COMMAND polymorphic_value_test
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
include(Catch)
catch_discover_tests(polymorphic_value_test)
endif(${BUILD_TESTING})
if (APPLE)
SET(ENABLE_CODE_COVERAGE OFF CACHE BOOL "Ensure code coverage is switched off for Mac OS until the code coverage library addresses the AppleClang issue" FORCE)
endif()
if (ENABLE_CODE_COVERAGE)
include(FetchContent)
FetchContent_Declare(
codecoverage
GIT_REPOSITORY https://github.com/RWTH-HPC/CMake-codecov.git
)
FetchContent_GetProperties(codecoverage)
if(NOT codecoverage_POPULATED)
FetchContent_Populate(codecoverage)
list(APPEND CMAKE_MODULE_PATH ${codecoverage_SOURCE_DIR}/cmake)
endif()
set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
find_package(codecov)
add_coverage(polymorphic_value_test)
list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
coverage_evaluate()
endif()
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_value.h"
"${CMAKE_CURRENT_SOURCE_DIR}/polymorphic_value.natvis"
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt"
DESTINATION
"${CMAKE_INSTALL_DATAROOTDIR}/licenses/polymorphic_value"
)
install(
TARGETS polymorphic_value
EXPORT polymorphic_value-target
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT polymorphic_value-target
NAMESPACE polymorphic_value::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/polymorphic_value"
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/polymorphic_value-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/polymorphic_value-config.cmake
INSTALL_DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/polymorphic_value"
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/polymorphic_value-version.cmake
VERSION ${POLYMOPHIC_VALUE_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/polymorphic_value-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/polymorphic_value-version.cmake
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/polymorphic_value"
)
endif(POLYMORPHIC_IS_NOT_SUBPROJECT)