-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
271 lines (221 loc) · 6.96 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
cmake_minimum_required(VERSION 3.15)
project(Rexo
VERSION 0.2.3
LANGUAGES C CXX)
# ------------------------------------------------------------------------------
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# ------------------------------------------------------------------------------
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(MSVC)
add_compile_options(/W4)
else()
add_compile_options(
-Wpedantic -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual
-Wconversion -Wfloat-equal -Wpointer-arith -Wshadow -Wstrict-overflow=5
-Wswitch -Wswitch-default -Wundef -Wunreachable-code -Wwrite-strings
-Wformat-nonliteral -fsanitize=undefined,address)
add_link_options(
-fsanitize=undefined,address
)
endif()
if(UNIX)
add_definitions(-D_POSIX_C_SOURCE=199309L)
endif()
# ------------------------------------------------------------------------------
add_library(rexo INTERFACE)
target_include_directories(rexo
INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
install(
TARGETS rexo
EXPORT ${PROJECT_NAME}Targets)
add_library(${PROJECT_NAME}::rexo ALIAS rexo)
if(APPLE)
target_compile_options(rexo INTERFACE -Wno-implicit-function-declaration)
endif()
if(UNIX)
target_link_libraries(rexo INTERFACE m)
endif()
# ------------------------------------------------------------------------------
option(REXO_BUILD_TESTS "Build the test targets for Rexo" ON)
if(REXO_BUILD_TESTS)
set(RX_TEST_TARGETS)
macro(rx_add_test)
set(RX_ADD_TEST_OPTIONS)
set(RX_ADD_TEST_SINGLE_VALUE_ARGS NAME)
set(RX_ADD_TEST_MULTI_VALUE_ARGS FILES DEPENDS PROPERTIES)
cmake_parse_arguments(
RX_ADD_TEST
"${RX_ADD_TEST_OPTIONS}"
"${RX_ADD_TEST_SINGLE_VALUE_ARGS}"
"${RX_ADD_TEST_MULTI_VALUE_ARGS}"
${ARGN})
add_executable(test-${RX_ADD_TEST_NAME} ${RX_ADD_TEST_FILES})
set_target_properties(test-${RX_ADD_TEST_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests
OUTPUT_NAME ${RX_ADD_TEST_NAME}
${RX_ADD_TEST_PROPERTIES})
target_link_libraries(test-${RX_ADD_TEST_NAME}
PRIVATE ${RX_ADD_TEST_DEPENDS})
add_test(
NAME ${RX_ADD_TEST_NAME}
COMMAND test-${RX_ADD_TEST_NAME})
list(APPEND RX_TEST_TARGETS test-${RX_ADD_TEST_NAME})
endmacro()
enable_testing()
if(NOT MSVC)
rx_add_test(
NAME c89-assertion-coverage
FILES tests/c89/assertion-coverage.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
rx_add_test(
NAME c89-assertion-failure-messages
FILES tests/c89/assertion-failure-messages.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
rx_add_test(
NAME c89-config-inherit
FILES tests/c89/config-inherit.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
rx_add_test(
NAME c89-fixture
FILES tests/c89/fixture.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
rx_add_test(
NAME c89-fixture-void
FILES tests/c89/fixture-void.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
rx_add_test(
NAME c89-minimal
FILES tests/c89/minimal.c
DEPENDS rexo
PROPERTIES
C_STANDARD 90)
endif()
rx_add_test(
NAME cpp98-assertion-coverage
FILES tests/cpp98/assertion-coverage.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME cpp98-assertion-failure-messages
FILES tests/cpp98/assertion-failure-messages.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME cpp98-config-inherit
FILES tests/cpp98/config-inherit.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME cpp98-fixture
FILES tests/cpp98/fixture.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME cpp98-fixture-void
FILES tests/cpp98/fixture-void.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME cpp98-minimal
FILES tests/cpp98/minimal.cpp
DEPENDS rexo
PROPERTIES
CXX_STANDARD 98)
rx_add_test(
NAME assertion-coverage
FILES tests/assertion-coverage.c
DEPENDS rexo)
rx_add_test(
NAME assertion-failure-messages
FILES tests/assertion-failure-messages.c
DEPENDS rexo)
rx_add_test(
NAME config-inherit
FILES tests/config-inherit.c
DEPENDS rexo)
rx_add_test(
NAME config-skip
FILES tests/config-skip.c
DEPENDS rexo)
rx_add_test(
NAME empty
FILES tests/empty.c
DEPENDS rexo)
rx_add_test(
NAME explicit
FILES tests/explicit.c
DEPENDS rexo)
rx_add_test(
NAME fixture
FILES tests/fixture.c
DEPENDS rexo)
rx_add_test(
NAME fixture-data-only
FILES tests/fixture-data-only.c
DEPENDS rexo)
rx_add_test(
NAME fixture-void
FILES tests/fixture-void.c
DEPENDS rexo)
rx_add_test(
NAME minimal
FILES tests/minimal.c
DEPENDS rexo)
rx_add_test(
NAME no-discovery
FILES tests/no-discovery.c
DEPENDS rexo)
rx_add_test(
NAME semi-explicit
FILES tests/semi-explicit.c
DEPENDS rexo)
add_custom_target(tests DEPENDS ${RX_TEST_TARGETS})
endif()
# ------------------------------------------------------------------------------
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# ------------------------------------------------------------------------------
set(RX_CMAKE_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
configure_package_config_file(
cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${RX_CMAKE_INSTALL_DIR})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${RX_CMAKE_INSTALL_DIR})
install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${RX_CMAKE_INSTALL_DIR})