-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·662 lines (423 loc) · 22.5 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# Apache License 2.0
## Project Properties
SET (PROJECT_NAME "OpenSpaceToolkitAstrodynamics")
SET (PROJECT_DESCRIPTION "Astrodynamics library.")
SET (PROJECT_PATH "OpenSpaceToolkit/Astrodynamics")
SET (PROJECT_PACKAGE_NAME "open-space-toolkit-astrodynamics")
SET (PROJECT_LICENSE "Apache License 2.0")
SET (PROJECT_VENDOR_ID "org.open-space-collective")
SET (PROJECT_VENDOR_NAME "Open Space Collective")
SET (PROJECT_VENDOR_CONTACT "[email protected]")
SET (PROJECT_VENDOR_URL "open-space-collective.org")
## Project Options
OPTION (BUILD_SHARED_LIBRARY "Build shared library." ON)
OPTION (BUILD_STATIC_LIBRARY "Build static library." OFF)
OPTION (BUILD_UNIT_TESTS "Build unit tests" ON)
OPTION (BUILD_VALIDATION_TESTS "Build validation tests" OFF)
OPTION (BUILD_PYTHON_BINDINGS "Build Python bindings." ON)
OPTION (BUILD_CODE_COVERAGE "Build code coverage" OFF)
OPTION (BUILD_DOCUMENTATION "Build documentation" OFF)
OPTION (BUILD_WITH_DEBUG_SYMBOLS "Build with debug symbols" ON)
OPTION (BUILD_BENCHMARK "Build benchmark" ON)
## Setup
### Compatibility Check
CMAKE_MINIMUM_REQUIRED (VERSION "2.8.12" FATAL_ERROR)
### Paths
SET (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
### Policies
CMAKE_POLICY (SET "CMP0048" NEW)
## Version
INCLUDE ("GetGitRevisionDescription" OPTIONAL)
IF (COMMAND "GET_GIT_HEAD_REVISION" AND COMMAND "GIT_DESCRIBE")
# Versioning using current git branch tag
GET_GIT_HEAD_REVISION (GIT_REFSPEC GIT_HASH)
GIT_DESCRIBE (GIT_TAGS "--tags")
STRING (REPLACE "." ";" VERSION_LIST ${GIT_TAGS})
IF (VERSION_LIST)
LIST (GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
LIST (GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
LIST (GET VERSION_LIST 2 PROJECT_VERSION_PATCH_TWEAK)
STRING (REPLACE "-" ";" PROJECT_VERSION_PATCH_TWEAKS ${PROJECT_VERSION_PATCH_TWEAK})
LIST (GET PROJECT_VERSION_PATCH_TWEAKS 0 PROJECT_VERSION_PATCH)
LIST (LENGTH PROJECT_VERSION_PATCH_TWEAKS PROJECT_VERSION_PATCH_TWEAKS_LENGTH)
IF (PROJECT_VERSION_PATCH_TWEAKS_LENGTH GREATER 1)
LIST (GET PROJECT_VERSION_PATCH_TWEAKS 1 PROJECT_VERSION_TWEAK)
ENDIF ()
SET (PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
IF (DEFINED "PROJECT_VERSION_TWEAK")
SET (PROJECT_VERSION_STRING "${PROJECT_VERSION_STRING}.${PROJECT_VERSION_TWEAK}")
ENDIF ()
ENDIF ()
ENDIF ()
IF (NOT DEFINED PROJECT_VERSION_STRING)
# Versioning using current date / time
STRING (TIMESTAMP CURRENT_YEAR %Y UTC)
STRING (TIMESTAMP CURRENT_MONTH %m UTC)
STRING (TIMESTAMP CURRENT_DAY %d UTC)
STRING (TIMESTAMP CURRENT_DAY_OF_YEAR %j UTC)
SET (PROJECT_VERSION_MAJOR ${CURRENT_YEAR})
SET (PROJECT_VERSION_MINOR ${CURRENT_MONTH})
SET (PROJECT_VERSION_PATCH ${CURRENT_DAY})
SET (PROJECT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
ENDIF ()
MESSAGE (STATUS "Version: ${PROJECT_VERSION_STRING}")
## Project Configuration
PROJECT (${PROJECT_NAME} VERSION ${PROJECT_VERSION_STRING} LANGUAGES "C" "CXX")
SET (CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited Configs" FORCE)
IF (BUILD_CODE_COVERAGE)
SET (CMAKE_BUILD_TYPE "Debug")
ELSEIF (NOT CMAKE_BUILD_TYPE)
SET (CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type [None|Debug|Release|RelWithDebInfo|MinSizeRel]." FORCE)
ENDIF ()
## Flags
### Warnings
IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
MESSAGE (FATAL_ERROR "GCC version must be at least 4.8")
ENDIF ()
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Wno-deprecated")
ENDIF ()
### C++ 17 support
SET (CMAKE_CXX_STANDARD 17)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (CMAKE_CXX_EXTENSIONS OFF)
### Debug Symbols
IF (BUILD_WITH_DEBUG_SYMBOLS)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
ENDIF ()
### Debugging Options
SET (CMAKE_VERBOSE_MAKEFILE 0) # Use 1 for debugging, 0 for release
## Paths
### Search Paths
LIST (APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}")
LIST (APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/tools")
LIST (APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/thirdparty")
### Output Paths
SET (EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin")
SET (LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/lib")
SET (DOCS_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/docs")
IF (WIN32)
SET (INSTALL_ROOT ".") # C:\Programme\<project>
SET (INSTALL_DATA "bin") # C:\Programme\<project>
SET (INSTALL_BIN "bin") # C:\Programme\<project>
SET (INSTALL_LIB "lib") # C:\Programme\<project>\lib
SET (INSTALL_INCLUDE "include") # C:\Programme\<project>\include
SET (INSTALL_DOC "doc") # C:\Programme\<project>\doc
SET (INSTALL_SHORTCUTS ".") # Not available under Windows
SET (INSTALL_ICONS ".") # Not available under Windows
SET (INSTALL_INIT ".") # Not available under Windows
ELSE ()
SET (INSTALL_ROOT "share/${PROJECT_PATH}") # /usr/[local]/share/<project>
SET (INSTALL_DATA "share/${PROJECT_PATH}") # /usr/[local]/share/<project>
SET (INSTALL_BIN "bin") # /usr/[local]/bin
SET (INSTALL_LIB "lib") # /usr/[local]/lib
SET (INSTALL_TEST "test/${PROJECT_PATH}") # /usr/[local]/test/<project>
SET (INSTALL_INCLUDE "include/${PROJECT_PATH}") # /usr/[local]/include/<project>
SET (INSTALL_DOC "share/doc/${PROJECT_PATH}") # /usr/[local]/share/doc/<project>
SET (INSTALL_SHORTCUTS "share/applications") # /usr/[local]/share/applications
SET (INSTALL_INIT "/etc/init") # /etc/init (upstart init scripts)
ENDIF ()
## Configure Files
FILE (GLOB_RECURSE CONFIGINPUTS1 "include/*.in.hpp.cmake")
FILE (GLOB_RECURSE CONFIGINPUTS2 "include/*.hpp.in.cmake")
FILE (GLOB_RECURSE CONFIGINPUTS3 "src/*.in.hpp.cmake")
FILE (GLOB_RECURSE CONFIGINPUTS4 "src/*.hpp.in.cmake")
FILE (GLOB_RECURSE CONFIGINPUTS5 "test/*.in.hpp.cmake")
FILE (GLOB_RECURSE CONFIGINPUTS6 "test/*.hpp.in.cmake")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS1}")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS2}")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS3}")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS4}")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS5}")
LIST (APPEND CONFIGINPUTS "${CONFIGINPUTS6}")
FOREACH (CONFIGINPUT ${CONFIGINPUTS})
STRING (REPLACE ".in.hpp.cmake" ".h" CONFIGOUTPUT1 "${CONFIGINPUT}")
STRING (REPLACE ".hpp.in.cmake" ".h" CONFIGOUTPUT2 "${CONFIGOUTPUT1}")
CONFIGURE_FILE ("${CONFIGINPUT}" "${CONFIGOUTPUT2}")
ENDFOREACH ()
## Dependencies
### Boost [1.82.0]
SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_MULTITHREADED ON)
FIND_PACKAGE ("Boost" "1.82" REQUIRED COMPONENTS log log_setup thread)
ADD_DEFINITIONS(-DBOOST_THREAD_DYN_LINK -DBOOST_STACKTRACE_USE_BACKTRACE -DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/9/include/backtrace.h>)
IF (NOT Boost_FOUND)
MESSAGE (SEND_ERROR "[Boost] not found.")
ENDIF ()
### Eigen [3]
FIND_PACKAGE ("Eigen3" REQUIRED)
IF (EIGEN3_FOUND)
INCLUDE_DIRECTORIES (${EIGEN3_INCLUDE_DIR})
ELSE ()
MESSAGE (SEND_ERROR "[Eigen 3] not found.")
ENDIF ()
### SGP4
FIND_PACKAGE ("SGP4" REQUIRED)
IF (SGP4_FOUND)
INCLUDE_DIRECTORIES (${SGP4_INCLUDE_DIRS})
LINK_DIRECTORIES (${SGP4_LIBRARY_DIRS})
ELSE ()
MESSAGE (SEND_ERROR "[SGP4] not found.")
ENDIF ()
### NLopt
FIND_PACKAGE ("NLopt" REQUIRED)
IF (NLopt_FOUND)
INCLUDE_DIRECTORIES (${NLopt_INCLUDE_DIRS})
LINK_DIRECTORIES (${NLopt_LIBRARY_DIRS})
ELSE ()
MESSAGE (SEND_ERROR "[NLopt] not found.")
ENDIF ()
### Open Space Toolkit ▸ Core
FIND_PACKAGE ("OpenSpaceToolkitCore" "1.0" REQUIRED)
IF (NOT OpenSpaceToolkitCore_FOUND)
MESSAGE (SEND_ERROR "[Open Space Toolkit ▸ Core] not found.")
ENDIF ()
### Open Space Toolkit ▸ I/O
FIND_PACKAGE ("OpenSpaceToolkitIO" "1.0" REQUIRED)
IF (NOT OpenSpaceToolkitIO_FOUND)
MESSAGE (SEND_ERROR "[Open Space Toolkit ▸ I/O] not found.")
ENDIF ()
### Open Space Toolkit ▸ Mathematics
FIND_PACKAGE ("OpenSpaceToolkitMathematics" "1.0" REQUIRED)
IF (NOT OpenSpaceToolkitMathematics_FOUND)
MESSAGE (SEND_ERROR "[Open Space Toolkit ▸ Mathematics] not found.")
ENDIF ()
### Open Space Toolkit ▸ Physics
FIND_PACKAGE ("OpenSpaceToolkitPhysics" "4.0" REQUIRED)
IF (NOT OpenSpaceToolkitPhysics_FOUND)
MESSAGE (SEND_ERROR "[Open Space Toolkit ▸ Physics] not found.")
ENDIF ()
#####################################################################################3###########################################################################
## Versioning
IF (DEFINED PROJECT_VERSION_STRING AND EXISTS "${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/Utilities/Version.cpp.in")
CONFIGURE_FILE ("${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/Utilities/Version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/src/${PROJECT_PATH}/Utilities/Version.cpp" @ONLY)
ENDIF ()
## Targets
### Shared Library
IF (BUILD_SHARED_LIBRARY)
SET (SHARED_LIBRARY_NAME "${PROJECT_PACKAGE_NAME}")
SET (SHARED_LIBRARY_TARGET "lib${SHARED_LIBRARY_NAME}.so")
FILE (GLOB_RECURSE SHARED_LIBRARY_HEADERS "${PROJECT_SOURCE_DIR}/include/${PROJECT_PATH}/*.hpp")
FILE (GLOB_RECURSE SHARED_LIBRARY_SRCS "${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/*.cpp")
IF (APPLE)
SET (CMAKE_MACOSX_RPATH ON)
ENDIF (APPLE)
ADD_LIBRARY (${SHARED_LIBRARY_TARGET} SHARED ${SHARED_LIBRARY_SRCS})
TARGET_INCLUDE_DIRECTORIES (${SHARED_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include/")
TARGET_INCLUDE_DIRECTORIES (${SHARED_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/src/")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "pthread")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} "dl")
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${SGP4_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${NLopt_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${OpenSpaceToolkitCore_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${OpenSpaceToolkitIO_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${OpenSpaceToolkitMathematics_LIBRARIES})
TARGET_LINK_LIBRARIES (${SHARED_LIBRARY_TARGET} ${OpenSpaceToolkitPhysics_LIBRARIES})
SET_TARGET_PROPERTIES (${SHARED_LIBRARY_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME ${SHARED_LIBRARY_NAME} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
INSTALL (DIRECTORY "${PROJECT_SOURCE_DIR}/include/${PROJECT_PATH}/" DESTINATION ${INSTALL_INCLUDE} COMPONENT "headers" FILES_MATCHING PATTERN "*.hpp")
INSTALL (DIRECTORY "${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/" DESTINATION ${INSTALL_INCLUDE} COMPONENT "headers" FILES_MATCHING PATTERN "*.tpp")
INSTALL (TARGETS ${SHARED_LIBRARY_TARGET} DESTINATION ${INSTALL_LIB} COMPONENT "libraries")
ENDIF ()
### Static Library
IF (BUILD_STATIC_LIBRARY)
SET (STATIC_LIBRARY_NAME "${PROJECT_PACKAGE_NAME}")
SET (STATIC_LIBRARY_TARGET "lib${STATIC_LIBRARY_NAME}.a")
FILE (GLOB_RECURSE STATIC_LIBRARY_HEADERS "${PROJECT_SOURCE_DIR}/include/${PROJECT_PATH}/*.hpp")
FILE (GLOB_RECURSE STATIC_LIBRARY_SRCS "${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/*.cpp")
ADD_LIBRARY (${STATIC_LIBRARY_TARGET} STATIC ${STATIC_LIBRARY_SRCS})
TARGET_INCLUDE_DIRECTORIES (${STATIC_LIBRARY_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include/")
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "pthread")
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} "dl")
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${SGP4_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${NLopt_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${OpenSpaceToolkitCore_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${OpenSpaceToolkitIO_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${OpenSpaceToolkitMathematics_LIBRARIES})
TARGET_LINK_LIBRARIES (${STATIC_LIBRARY_TARGET} ${OpenSpaceToolkitPhysics_LIBRARIES})
SET_TARGET_PROPERTIES (${STATIC_LIBRARY_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${STATIC_LIBRARY_NAME} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
INSTALL (DIRECTORY "${PROJECT_SOURCE_DIR}/include/${PROJECT_PATH}/" DESTINATION ${INSTALL_INCLUDE} COMPONENT "headers" FILES_MATCHING PATTERN "*.hpp")
INSTALL (DIRECTORY "${PROJECT_SOURCE_DIR}/src/${PROJECT_PATH}/" DESTINATION ${INSTALL_INCLUDE} COMPONENT "headers" FILES_MATCHING PATTERN "*.tpp")
INSTALL (TARGETS ${STATIC_LIBRARY_TARGET} DESTINATION ${INSTALL_LIB} COMPONENT "libraries")
ENDIF ()
### Unit Tests
IF (BUILD_UNIT_TESTS)
IF (NOT BUILD_SHARED_LIBRARY)
MESSAGE (SEND_ERROR "[Unit Tests] cannot be built without [Shared Library].")
ENDIF ()
SET (UNIT_TESTS_TARGET "${PROJECT_PACKAGE_NAME}.test")
ENABLE_TESTING ()
FILE (GLOB_RECURSE TEST_SRCS "${PROJECT_SOURCE_DIR}/test/${PROJECT_PATH}/*.test.cpp" "${PROJECT_SOURCE_DIR}/test/${PROJECT_PATH}/*.validation.cpp")
ADD_EXECUTABLE (${UNIT_TESTS_TARGET} ${TEST_SRCS})
ADD_DEPENDENCIES (${UNIT_TESTS_TARGET} ${SHARED_LIBRARY_TARGET})
FIND_PACKAGE ("GTest" QUIET)
IF (NOT GTEST_FOUND)
ADD_SUBDIRECTORY ("${PROJECT_SOURCE_DIR}/thirdparty/gtest")
ADD_DEPENDENCIES (${UNIT_TESTS_TARGET} "googletest")
LIST (APPEND GTEST_BOTH_LIBRARIES "${GTEST_LIBS_DIR}/libgtest.a")
LIST (APPEND GTEST_BOTH_LIBRARIES "${GTEST_LIBS_DIR}/libgtest_main.a")
ENDIF ()
TARGET_INCLUDE_DIRECTORIES (${UNIT_TESTS_TARGET} PUBLIC ${GTEST_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES (${UNIT_TESTS_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include")
TARGET_INCLUDE_DIRECTORIES (${UNIT_TESTS_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/test")
# TARGET_LINK_LIBRARIES (${UNIT_TESTS_TARGET} "GTest::GTest" "GTest::Main")
TARGET_LINK_LIBRARIES (${UNIT_TESTS_TARGET} "${GTEST_BOTH_LIBRARIES}")
TARGET_LINK_LIBRARIES (${UNIT_TESTS_TARGET} "gmock")
TARGET_LINK_LIBRARIES (${UNIT_TESTS_TARGET} "${SHARED_LIBRARY_TARGET}")
GTEST_DISCOVER_TESTS (${UNIT_TESTS_TARGET})
SET_TARGET_PROPERTIES (${UNIT_TESTS_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${UNIT_TESTS_TARGET} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
INSTALL (TARGETS ${UNIT_TESTS_TARGET} DESTINATION ${INSTALL_TEST} COMPONENT "tests")
#### Code Coverage
IF (BUILD_CODE_COVERAGE)
SET (COVERAGE_TARGET "coverage")
INCLUDE (CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS ()
SET (COVERAGE_EXCLUDES '*.test.cpp' '/usr/*' '/app/bindings/*' '*.benchmark.cpp')
SETUP_TARGET_FOR_COVERAGE (
NAME ${COVERAGE_TARGET}
EXECUTABLE ${UNIT_TESTS_TARGET}
DEPENDENCIES "coverage"
)
ENDIF ()
ENDIF ()
### Validation Tests
IF (BUILD_VALIDATION_TESTS)
IF (NOT BUILD_SHARED_LIBRARY)
MESSAGE (SEND_ERROR "[Validation Tests] cannot be built without [Shared Library].")
ENDIF ()
SET (VALIDATION_TESTS_TARGET "${PROJECT_PACKAGE_NAME}.validation")
ENABLE_TESTING ()
FILE (GLOB_RECURSE TEST_SRCS "${PROJECT_SOURCE_DIR}/validation/${PROJECT_PATH}/*.cpp" "${PROJECT_SOURCE_DIR}/validation/${PROJECT_PATH}/*.test.cpp" "${PROJECT_SOURCE_DIR}/validation/${PROJECT_PATH}/*.validation.cpp")
ADD_EXECUTABLE (${VALIDATION_TESTS_TARGET} ${TEST_SRCS})
ADD_DEPENDENCIES (${VALIDATION_TESTS_TARGET} ${SHARED_LIBRARY_TARGET})
FIND_PACKAGE ("GTest" QUIET)
IF (NOT GTEST_FOUND)
ADD_SUBDIRECTORY ("${PROJECT_SOURCE_DIR}/thirdparty/gtest")
ADD_DEPENDENCIES (${VALIDATION_TESTS_TARGET} "googletest")
LIST (APPEND GTEST_BOTH_LIBRARIES "${GTEST_LIBS_DIR}/libgtest.a")
LIST (APPEND GTEST_BOTH_LIBRARIES "${GTEST_LIBS_DIR}/libgtest_main.a")
ENDIF ()
TARGET_INCLUDE_DIRECTORIES (${VALIDATION_TESTS_TARGET} PUBLIC ${GTEST_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES (${VALIDATION_TESTS_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include")
TARGET_INCLUDE_DIRECTORIES (${VALIDATION_TESTS_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/validation")
# TARGET_LINK_LIBRARIES (${VALIDATION_TESTS_TARGET} "GTest::GTest" "GTest::Main")
TARGET_LINK_LIBRARIES (${VALIDATION_TESTS_TARGET} "${GTEST_BOTH_LIBRARIES}")
TARGET_LINK_LIBRARIES (${VALIDATION_TESTS_TARGET} "gmock")
TARGET_LINK_LIBRARIES (${VALIDATION_TESTS_TARGET} "${SHARED_LIBRARY_TARGET}")
GTEST_DISCOVER_TESTS (${VALIDATION_TESTS_TARGET})
SET_TARGET_PROPERTIES (${VALIDATION_TESTS_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${VALIDATION_TESTS_TARGET} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
INSTALL (TARGETS ${VALIDATION_TESTS_TARGET} DESTINATION ${INSTALL_TEST} COMPONENT "validation")
ENDIF ()
### Benchmarks
IF (BUILD_BENCHMARK)
IF (NOT BUILD_SHARED_LIBRARY)
MESSAGE (SEND_ERROR "[Benchmark] cannot be built without [Shared Library].")
ENDIF ()
SET (BENCHMARK_TARGET "${PROJECT_PACKAGE_NAME}.benchmark")
FILE (GLOB_RECURSE BENCHMARK_SRCS "${PROJECT_SOURCE_DIR}/benchmark/${PROJECT_PATH}/*.benchmark.cpp")
ADD_EXECUTABLE (${BENCHMARK_TARGET} ${BENCHMARK_SRCS})
ADD_DEPENDENCIES (${BENCHMARK_TARGET} ${SHARED_LIBRARY_TARGET})
### benchmark
FIND_PACKAGE ("benchmark" REQUIRED)
TARGET_INCLUDE_DIRECTORIES (${BENCHMARK_TARGET} PUBLIC ${benchmark_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES (${BENCHMARK_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/include")
TARGET_INCLUDE_DIRECTORIES (${BENCHMARK_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/benchmark")
TARGET_LINK_LIBRARIES (${BENCHMARK_TARGET} ${benchmark_LIBRARIES})
TARGET_LINK_LIBRARIES (${BENCHMARK_TARGET} ${SHARED_LIBRARY_TARGET})
message (STATUS "benchmark_LIBRARIES: ${benchmark_LIBRARIES}")
SET_TARGET_PROPERTIES (${BENCHMARK_TARGET} PROPERTIES VERSION ${PROJECT_VERSION_STRING} OUTPUT_NAME ${BENCHMARK_TARGET} CLEAN_DIRECT_OUTPUT 1 INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
INSTALL (TARGETS ${BENCHMARK_TARGET} DESTINATION ${INSTALL_TEST} COMPONENT "benchmarks")
ENDIF ()
### Python Bindings
IF (BUILD_PYTHON_BINDINGS)
ADD_SUBDIRECTORY ("${PROJECT_SOURCE_DIR}/bindings/python")
ENDIF ()
### Documentation
IF (BUILD_DOCUMENTATION)
ADD_SUBDIRECTORY ("${PROJECT_SOURCE_DIR}/docs")
ENDIF ()
### Configuration
CONFIGURE_FILE (
"${CMAKE_MODULE_PATH}/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY)
CONFIGURE_FILE (
"${CMAKE_MODULE_PATH}/${PROJECT_NAME}ConfigVersion.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
@ONLY)
INSTALL (FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "${INSTALL_LIB}/${PROJECT_NAME}" COMPONENT "libraries")
INSTALL (FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION "${INSTALL_LIB}/${PROJECT_NAME}" COMPONENT "libraries")
### Uninstall
CONFIGURE_FILE (
"${CMAKE_MODULE_PATH}/UninstallTarget.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/UninstallTarget.cmake"
IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET ("uninstall" COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/UninstallTarget.cmake")
### Misc
INSTALL (FILES "LICENSE" DESTINATION ${INSTALL_ROOT} COMPONENT "documentation")
IF (EXISTS "${PROJECT_SOURCE_DIR}/share")
INSTALL (DIRECTORY "${PROJECT_SOURCE_DIR}/share/" DESTINATION ${INSTALL_DATA} COMPONENT "data")
ENDIF ()
## Packaging
SET (CPACK_PACKAGE_NAME ${PROJECT_PACKAGE_NAME})
SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_DESCRIPTION})
SET (CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
SET (CPACK_PACKAGE_SUMMARY ${PROJECT_NAME})
SET (CPACK_PACKAGE_VENDOR ${PROJECT_VENDOR_NAME})
SET (CPACK_PACKAGE_CONTACT ${PROJECT_VENDOR_CONTACT})
SET (CPACK_PACKAGE_LICENSE ${PROJECT_LICENSE})
SET (CPACK_PACKAGE_VERSION ${PROJECT_VERSION_STRING})
SET (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
SET (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
SET (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
SET (CPACK_PACKAGE_RELEASE 1)
SET (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
SET (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
SET (CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
SET (CPACK_COMPONENTS_ALL "applications" "headers" "libraries" "documentation" "tests" "data" "python")
SET (CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "Applications")
SET (CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Headers")
SET (CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
SET (CPACK_COMPONENT_DOCUMENTATION_DISPLAY_NAME "Documentation")
SET (CPACK_COMPONENT_TESTS_DISPLAY_NAME "Unit Tests")
SET (CPACK_COMPONENT_DATA_DISPLAY_NAME "Shared Data")
SET (CPACK_COMPONENT_PYTHON_DISPLAY_NAME "Python Bindings")
SET (CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "Applications")
SET (CPACK_COMPONENT_HEADERS_DESCRIPTION "Headers")
SET (CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Libraries")
SET (CPACK_COMPONENT_DOCUMENTATION_DESCRIPTION "Documentation")
SET (CPACK_COMPONENT_TESTS_DESCRIPTION "Unit Tests")
SET (CPACK_COMPONENT_DATA_DESCRIPTION "Shared Data")
SET (CPACK_COMPONENT_PYTHON_DESCRIPTION "Python Bindings")
SET (CPACK_COMPONENT_APPLICATIONS_DEPENDS "libraries")
SET (CPACK_COMPONENT_HEADERS_DEPENDS "libraries")
SET (CPACK_COMPONENT_LIBRARIES_DEPENDS "data")
SET (CPACK_COMPONENT_PYTHON_DEPENDS "libraries")
SET (CPACK_COMPONENT_APPLICATIONS_GROUP "runtime")
SET (CPACK_COMPONENT_HEADERS_GROUP "devel")
SET (CPACK_COMPONENT_LIBRARIES_GROUP "runtime")
SET (CPACK_COMPONENT_DOCUMENTATION_GROUP "devel")
SET (CPACK_COMPONENT_TESTS_GROUP "devel")
SET (CPACK_COMPONENT_DATA_GROUP "runtime")
SET (CPACK_COMPONENT_PYTHON_GROUP "python")
SET (CPACK_COMPONENT_GROUP_RUNTIME_DESCRIPTION "Runtime")
SET (CPACK_COMPONENT_GROUP_DEVEL_DESCRIPTION "Development tools")
SET (CPACK_COMPONENT_GROUP_PYTHON_DESCRIPTION "Python bindings")
SET (CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
SET (CPACK_DEB_COMPONENT_INSTALL "ON")
SET (CPACK_RPM_COMPONENT_INSTALL "ON")
SET (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
/usr
/usr/bin
/usr/include
/usr/lib
/usr/share
/usr/local
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/share/man
)
INCLUDE (CPack)