-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
430 lines (383 loc) · 12.7 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
cmake_minimum_required(VERSION 3.19)
project(aas_core3)
set(AAS_CORE3_VERSION_MAJOR 0 CACHE STRING "major version" FORCE)
set(AAS_CORE3_VERSION_MINOR 0 CACHE STRING "minor version" FORCE)
set(AAS_CORE3_VERSION_PATCH 1 CACHE STRING "patch version" FORCE)
set(AAS_CORE3_VERSION_SUFFIX alpha.2 CACHE STRING "patch version" FORCE)
if (NOT "${AAS_CORE3_VERSION_SUFFIX}" STREQUAL "")
set(AAS_CORE3_VERSION
${AAS_CORE3_VERSION_MAJOR}.${AAS_CORE3_VERSION_MINOR}.${AAS_CORE3_VERSION_PATCH}-${AAS_CORE3_VERSION_SUFFIX}
CACHE STRING "version" FORCE
)
else ()
set(AAS_CORE3_VERSION
${AAS_CORE3_VERSION_MAJOR}.${AAS_CORE3_VERSION_MINOR}.${AAS_CORE3_VERSION_PATCH}
CACHE STRING "version" FORCE
)
endif ()
set(PROJECT_VERSION ${AAS_CORE3_VERSION})
OPTION(BUILD_TESTS "Build tests for aas-core-cpp" FALSE)
if (${BUILD_TESTS})
# NOTE (mristin):
# We need to use C++17 for the <filesystem> in tests.
set(CMAKE_CXX_STANDARD 17)
else ()
set(CMAKE_CXX_STANDARD 11)
endif ()
# NOTE (mristin):
# See: https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(nlohmann_json 3 CONFIG REQUIRED)
find_package(expat 2 CONFIG REQUIRED)
find_package(tl-optional 1 CONFIG REQUIRED)
find_package(tl-expected 1 CONFIG REQUIRED)
# NOTE (mristin):
# Since there is a lot of source code, we have to compile to large object files
# with MSVC; otherwise the error C1128 is raised.
# See: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1128
IF (MSVC)
add_compile_options(/bigobj)
ENDIF ()
if (MSVC)
add_compile_options(/W4 /WX)
else ()
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Wno-unknown-pragmas
-Wno-unused-parameter
-Wno-implicit-fallthrough
-Wno-switch
)
endif ()
# NOTE (mristin):
# We take the following tutorial as inspiration:
# https://www.foonathan.net/2016/03/cmake-install/
SET(HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/aas_core/aas_3_0")
SET(HEADER
${HEADER_PATH}/common.hpp
${HEADER_PATH}/constants.hpp
${HEADER_PATH}/enhancing.hpp
${HEADER_PATH}/iteration.hpp
${HEADER_PATH}/jsonization.hpp
${HEADER_PATH}/pattern.hpp
${HEADER_PATH}/revm.hpp
${HEADER_PATH}/stringification.hpp
${HEADER_PATH}/types.hpp
${HEADER_PATH}/verification.hpp
${HEADER_PATH}/visitation.hpp
${HEADER_PATH}/wstringification.hpp
${HEADER_PATH}/xmlization.hpp
)
SET(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src")
SET(SRC
${SRC_PATH}/common.cpp
${SRC_PATH}/constants.cpp
${SRC_PATH}/iteration.cpp
${SRC_PATH}/jsonization.cpp
${SRC_PATH}/pattern.cpp
${SRC_PATH}/revm.cpp
${SRC_PATH}/stringification.cpp
${SRC_PATH}/types.cpp
${SRC_PATH}/verification.cpp
${SRC_PATH}/visitation.cpp
${SRC_PATH}/wstringification.cpp
${SRC_PATH}/xmlization.cpp
)
# NOTE (mristin)
# MSVC does not automatically build .lib for DLLs.
# See: https://stackoverflow.com/questions/64088046/missing-lib-file-when-creating-shared-library-with-cmake-and-visual-studio-2019
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(aas_core3_static STATIC ${HEADER} ${SRC})
set_target_properties(aas_core3_static
PROPERTIES
PUBLIC_HEADER "${HEADER}"
)
# NOTE (mristin):
# We need to distinguish between BUILD and INSTALL interface,
# see: https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
target_include_directories(aas_core3_static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(aas_core3_static
PRIVATE
expat::expat
PUBLIC
nlohmann_json::nlohmann_json
tl::optional
tl::expected
)
add_library(aas_core3 SHARED ${HEADER} ${SRC})
# NOTE (mristin):
# We need to distinguish between BUILD and INSTALL interface,
# see: https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
target_include_directories(aas_core3
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(aas_core3
PROPERTIES
PUBLIC_HEADER "${HEADER}"
)
target_link_libraries(aas_core3
PRIVATE
expat::expat
PUBLIC
nlohmann_json::nlohmann_json
tl::optional
tl::expected
)
# Testing
OPTION(BUILD_TESTS "Build tests for aas-core-cpp" FALSE)
if (${BUILD_TESTS})
# NOTE (mristin):
# We need to use C++17 for the <filesystem>.
set(CMAKE_CXX_STANDARD 17)
include(CTest)
enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test-external)
# region Common in test
add_library(common_in_test test/common.hpp test/common.cpp)
target_link_libraries(common_in_test aas_core3_static)
add_library(common_jsonization_in_test
test/common_jsonization.cpp
test/common_jsonization.hpp
)
target_link_libraries(common_jsonization_in_test aas_core3_static)
add_library(common_xmlization_in_test
test/common_xmlization.cpp
test/common_xmlization.hpp
)
target_link_libraries(common_xmlization_in_test aas_core3_static)
add_library(common_examples_in_test
test/common_examples.generated.hpp
test/common_examples.generated.cpp
)
target_link_libraries(common_examples_in_test
common_in_test
common_xmlization_in_test
)
# endregion Common in test
add_executable(test_examples test/test_examples.cpp)
target_link_libraries(test_examples aas_core3_static)
add_test(
NAME test_examples
COMMAND $<TARGET_FILE:test_examples>
)
add_executable(test_revm test/test_revm.cpp)
target_link_libraries(test_revm aas_core3_static)
add_test(
NAME test_revm
COMMAND $<TARGET_FILE:test_revm>
)
# region Stringification
add_executable(
test_stringification_base64
test/test_stringification_base64.cpp
)
target_link_libraries(test_stringification_base64 aas_core3_static)
add_test(
NAME test_stringification_base64
COMMAND $<TARGET_FILE:test_stringification_base64>
)
add_executable(
test_stringification_of_enums
test/test_stringification_of_enums.generated.cpp
)
target_link_libraries(test_stringification_of_enums aas_core3_static)
add_test(
NAME test_stringification_of_enums
COMMAND $<TARGET_FILE:test_stringification_of_enums>
)
# endregion Stringification
# region Wstringification
add_executable(
test_wstringification_of_enums
test/test_wstringification_of_enums.generated.cpp
)
target_link_libraries(test_wstringification_of_enums aas_core3_static)
add_test(
NAME test_wstringification_of_enums
COMMAND $<TARGET_FILE:test_wstringification_of_enums>
)
# endregion Wstringification
# region Jsonization
add_executable(
test_jsonization_of_concrete_classes
test/test_jsonization_of_concrete_classes.generated.cpp
)
target_link_libraries(
test_jsonization_of_concrete_classes
aas_core3_static
common_in_test
common_jsonization_in_test
)
add_test(
NAME test_jsonization_of_concrete_classes
COMMAND $<TARGET_FILE:test_jsonization_of_concrete_classes>
)
add_executable(
test_jsonization_dispatch
test/test_jsonization_dispatch.generated.cpp
)
target_link_libraries(
test_jsonization_dispatch
aas_core3_static
common_examples_in_test
common_jsonization_in_test
)
add_test(
NAME test_jsonization_dispatch
COMMAND $<TARGET_FILE:test_jsonization_dispatch>
)
add_executable(
test_jsonization_of_concrete_classes_outside_container
test/test_jsonization_of_concrete_classes_outside_container.generated.cpp
)
target_link_libraries(
test_jsonization_of_concrete_classes_outside_container
aas_core3_static
common_examples_in_test
common_jsonization_in_test
)
add_test(
NAME test_jsonization_of_concrete_classes_outside_container
COMMAND $<TARGET_FILE:test_jsonization_of_concrete_classes_outside_container>
)
# endregion
# region Xmlization
add_executable(
test_xmlization_of_concrete_classes
test/test_xmlization_of_concrete_classes.generated.cpp
)
target_link_libraries(
test_xmlization_of_concrete_classes
aas_core3_static
common_in_test
common_xmlization_in_test
)
add_test(
NAME test_xmlization_of_concrete_classes
COMMAND $<TARGET_FILE:test_xmlization_of_concrete_classes>
)
add_executable(
test_xmlization_dispatch
test/test_xmlization_dispatch.generated.cpp
)
target_link_libraries(
test_xmlization_dispatch
aas_core3_static
common_in_test
common_examples_in_test
)
add_test(
NAME test_xmlization_dispatch
COMMAND $<TARGET_FILE:test_xmlization_dispatch>
)
add_executable(
test_xmlization_of_concrete_classes_outside_container
test/test_xmlization_of_concrete_classes_outside_container.generated.cpp
)
target_link_libraries(
test_xmlization_of_concrete_classes_outside_container
aas_core3_static
common_in_test
common_examples_in_test
)
add_test(
NAME test_xmlization_of_concrete_classes_outside_container
COMMAND $<TARGET_FILE:test_xmlization_of_concrete_classes_outside_container>
)
# endregion
# region Verification
add_executable(
test_verification
test/test_verification.cpp
)
target_link_libraries(
test_verification
aas_core3_static
common_in_test
)
add_test(
NAME test_verification
COMMAND $<TARGET_FILE:test_verification>
)
add_executable(
test_verification_generated
test/test_verification.generated.cpp
)
target_link_libraries(
test_verification_generated
aas_core3_static
common_in_test
common_xmlization_in_test
)
add_test(
NAME test_verification_generated
COMMAND $<TARGET_FILE:test_verification_generated>
)
# endregion
# region Descent and DescentOnce
add_executable(
test_descent_and_descent_once
test/test_descent_and_descent_once.generated.cpp
)
target_link_libraries(
test_descent_and_descent_once
aas_core3_static
common_in_test
common_examples_in_test
common_xmlization_in_test
)
add_test(
NAME test_descent_and_descent_once
COMMAND $<TARGET_FILE:test_descent_and_descent_once>
)
# endregion
# region XxxOrDefault
add_executable(
test_x_or_default
test/test_x_or_default.generated.cpp
)
target_link_libraries(
test_x_or_default
aas_core3_static
common_in_test
common_examples_in_test
)
add_test(
NAME test_x_or_default
COMMAND $<TARGET_FILE:test_x_or_default>
)
# endregion
endif ()
# Set the version
configure_file(aas_core3-config-version.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/aas_core3-config-version.cmake @ONLY
)
# Installation
include(GNUInstallDirs)
install(TARGETS aas_core3_static
EXPORT aas_core3
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aas_core/aas_3_0
)
install(TARGETS aas_core3
EXPORT aas_core3
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aas_core/aas_3_0
)
install(FILES
aas_core3-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/aas_core3-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/aas_core3
)
install(EXPORT aas_core3
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/aas_core3"
)