forked from jbcoe/propagate_const
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
194 lines (160 loc) · 6.38 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
cmake_minimum_required(VERSION 3.14)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(PROPAGATE_CONST_IS_NOT_SUBPROJECT ON)
endif()
set(PROPAGATE_CONST_VERSION 1.0.0)
project(propagate_const LANGUAGES CXX VERSION ${PROPAGATE_CONST_VERSION})
if(EXISTS ${CMAKE_SOURCE_DIR}/conanbuildinfo.cmake)
include(${CMAKE_SOURCE_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS NO_OUTPUT_DIRS)
endif()
include(FetchContent)
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)
add_library(propagate_const INTERFACE)
target_include_directories(propagate_const
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_sources(propagate_const
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/propagate_const.h>
$<INSTALL_INTERFACE:include/propagate_const.h>
)
target_compile_features(propagate_const
INTERFACE
cxx_std_14
)
add_library(propagate_const::propagate_const ALIAS propagate_const)
if (${PROPAGATE_CONST_IS_NOT_SUBPROJECT})
include(CTest)
if (BUILD_TESTING)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
)
FetchContent_GetProperties(catch2)
if(NOT catch2_POPULATED)
FetchContent_Populate(catch2)
add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
endif()
add_executable(test_propagate_const test_propagate_const.cpp)
target_link_libraries(test_propagate_const
PRIVATE
propagate_const::propagate_const
Catch2::Catch2
)
target_compile_options(test_propagate_const
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>:-Werror;-Wall;-Wno-self-assign-overloaded;-Wno-unknown-warning-option>
)
set_target_properties(test_propagate_const 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(test_propagate_const
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(test_propagate_const
PRIVATE
ubsan
)
endif(COMPILER_SUPPORTS_UBSAN)
endif(ENABLE_SANITIZERS)
add_test(
NAME test_propagate_const
COMMAND test_propagate_const
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/contrib)
include(Catch)
catch_discover_tests(test_propagate_const)
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)
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(test_propagate_const)
list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'")
coverage_evaluate()
endif()
endif(BUILD_TESTING)
include(GNUInstallDirs)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/propagate_const.h"
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt"
DESTINATION
"${CMAKE_INSTALL_DATAROOTDIR}/licenses/propagate_const"
)
install(
TARGETS propagate_const
EXPORT propagate_const-target
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT propagate_const-target
NAMESPACE propagate_const::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/propagate_const"
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/propagate_const-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/propagate_const-config.cmake
INSTALL_DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/propagate_const"
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/propagate_const-version.cmake
VERSION ${PROPAGATE_CONST_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/propagate_const-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/propagate_const-version.cmake
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/propagate_const"
)
endif()