forked from rollbear/trompeloeil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
294 lines (243 loc) · 6.26 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
cmake_minimum_required(VERSION 3.2)
project(trompeloeil)
include(GNUInstallDirs)
include(ExternalProject)
include(CMakePackageConfigHelpers)
include(CheckCXXCompilerFlag)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/trompeloeil/trompeloeil-config-version.cmake"
VERSION 34
COMPATIBILITY AnyNewerVersion)
if (CXX_STANDARD MATCHES "11")
set(CMAKE_CXX_STANDARD 11)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
add_library(trompeloeil INTERFACE)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(
trompeloeil
INTERFACE
$<BUILD_INTERFACE:${INCLUDE_DIR}>
)
target_include_directories(
trompeloeil
INTERFACE
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
)
set(MASTER_PROJECT OFF)
if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
set(MASTER_PROJECT ON)
endif()
if (MASTER_PROJECT AND CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CATCH_DIR ${CMAKE_CURRENT_BINARY_DIR}/catch)
if(NOT EXISTS ${CATCH_DIR}/catch.hpp)
if (NOT EXISTS ${CATCH_DIR})
make_directory(${CATCH_DIR})
endif()
file(
DOWNLOAD
https://github.com/catchorg/Catch2/releases/download/v2.7.0/catch.hpp ${CATCH_DIR}/catch.hpp
STATUS
status
LOG
log
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error downloading catch: ${status_string}"
"${log}")
endif()
endif()
# Assumptions:
# Clang and GNU compilers run on Linux or Linux-like platforms.
# MSVC compilers run on Windows platforms.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# kcov is only available on Linux platforms.
ExternalProject_Add(
kcov
GIT_REPOSITORY
https://github.com/simonkagstrom/kcov
GIT_TAG
v34
INSTALL_DIR
${CMAKE_CURRENT_BINARY_DIR}/kcov
CMAKE_ARGS
"-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/kcov"
)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
string(CONCAT
WARN_FLAGS
"-Weverything"
" -Wno-c++98-compat-pedantic"
" -Wno-padded"
" -Wno-weak-vtables"
" -Wno-exit-time-destructors"
" -Wno-global-constructors")
check_cxx_compiler_flag("-Wno-extra-semi-stmt" WARN_SEMI_STMT)
if (WARN_SEMI_STMT)
string(APPEND
WARN_FLAGS
" -Wno-extra-semi-stmt")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
string(CONCAT
WARN_FLAGS
"-Wall"
" -Wextra"
" -pedantic"
" -Wshadow")
endif()
set(WARN_FLAGS "${WARN_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS}")
# Default sanitizer target properties.
set(TSAN "-fsanitize=undefined,thread")
set(SSAN "-fsanitize=undefined,address")
# Exceptions to sanitizer target properties based on compiler and compiler version.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.0"))
set(SSAN "-fsanitize=undefined,address -fsanitize-address-use-after-scope")
else()
set(SSAN "-fsanitize=undefined,address")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if ((NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")) AND
(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
set(TSAN "-fsanitize=thread")
set(SSAN "-fsanitize=address")
endif()
endif()
endif() # Clang or GNU
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4)
add_compile_options(/bigobj)
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
if(HAS_PERMISSIVE_FLAG)
add_compile_options(/permissive-)
endif()
endif() # MSVC
add_executable(
self_test
EXCLUDE_FROM_ALL
test/compiling_tests.cpp
test/compiling_tests_11.cpp
test/compiling_tests_14.cpp
include/catch2/trompeloeil.hpp)
target_include_directories(
self_test
PRIVATE
${CATCH_DIR}
)
if (SANITIZE)
set_target_properties(
self_test
PROPERTIES
LINK_FLAGS
"${SSAN} -fuse-ld=gold"
COMPILE_FLAGS
${SSAN}
)
endif()
target_link_libraries(
self_test
PUBLIC
trompeloeil
)
add_executable(
thread_terror
EXCLUDE_FROM_ALL
test/thread_terror.cpp
)
target_link_libraries(
thread_terror
PUBLIC
trompeloeil
pthread
)
if (SANITIZE)
set_target_properties(
thread_terror
PROPERTIES
LINK_FLAGS
${TSAN}
COMPILE_FLAGS
${TSAN}
)
endif()
# Shameless hack to get target to work on Windows.
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_custom_target(
run_self_test
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/self_test
DEPENDS
self_test
)
else()
add_custom_target(
run_self_test
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/Debug/self_test
DEPENDS
self_test
)
endif()
if(TRAVIS_JOB_ID)
set(COVERALLS_FLAG "--coveralls-id=${TRAVIS_JOB_ID}")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_custom_target(
run_coverage
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/kcov/bin/kcov --skip-solibs --include-pattern=trompeloeil.hpp ${COVERALLS_FLAG} ./coverage ${CMAKE_CURRENT_BINARY_DIR}/self_test
DEPENDS
self_test
kcov
)
endif()
endif() # MASTER_PROJECT AND CMAKE_BUILD_TYPE MATCHES Debug
install(
TARGETS
trompeloeil
EXPORT
trompeloeil-targets
INCLUDES DESTINATION
include
)
install(
EXPORT
trompeloeil-targets
DESTINATION
lib/cmake/trompeloeil
)
install(
FILES
trompeloeil-config.cmake
"${CMAKE_CURRENT_BINARY_DIR}/trompeloeil/trompeloeil-config-version.cmake"
DESTINATION
lib/cmake/trompeloeil
COMPONENT
Devel
)
install(
DIRECTORY
include/
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
LICENSE_1_0.txt
DESTINATION
${CMAKE_INSTALL_DOCDIR}
)
install(
DIRECTORY
docs
DESTINATION
${CMAKE_INSTALL_DOCDIR}
)