-
Notifications
You must be signed in to change notification settings - Fork 40
/
CMakeLists.txt
179 lines (155 loc) · 6.48 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
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0075 NEW)
project(MOTION LANGUAGES CXX)
set(MOTION_VERSION_MAJOR 0)
set(MOTION_VERSION_MINOR 1)
set(MOTION_VERSION_PATCH 1)
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
message(FATAL_ERROR "MOTION requires at least g++-8")
endif ()
option(MOTION_BUILD_EXE "Build executables" OFF)
option(MOTION_BUILD_TESTS "Build tests" OFF)
option(MOTION_BUILD_DOC "Build documentation" OFF)
option(MOTION_LINK_TCMALLOC "Link against tcmalloc" OFF)
set(MOTION_USE_AVX OFF CACHE STRING "Use AVX/AVX2/AVX512/AVX512VAES instructions")
set_property(CACHE MOTION_USE_AVX PROPERTY STRINGS OFF AVX AVX2 AVX512 AVX512VAES)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(OpenMP REQUIRED)
# At least boost 1.75.0 is needed to use Boost::json.
set(MOTION_Boost_VERSION "1.75.0")
list(APPEND MOTION_Boost_COMPONENTS
context
fiber
filesystem
json
log
log_setup
program_options
system
thread)
find_package(Boost QUIET ${MOTION_Boost_VERSION}
COMPONENTS
${MOTION_Boost_COMPONENTS})
set(Boost_USE_STATIC_LIBS ON)
set(MOTION_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(MOTION_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(MOTION_EXTERN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern")
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
# Set build type to `Release` if non was specified:
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release"
FORCE)
endif (NOT CMAKE_BUILD_TYPE)
message("BUILD TYPE: " ${CMAKE_BUILD_TYPE})
endif ()
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug" OR "${CMAKE_BUILD_TYPE}" MATCHES "RelWithDebInfo")
set(MOTION_DEBUG "true")
else ()
set(MOTION_DEBUG "false")
endif ()
if (Boost_FOUND)
set(MOTION_BOOST_LOG_DYN_LINK ON)
else ()
include(cmake/BuildBoostLocally.cmake)
endif ()
# Write built executables and libraries to bin/ and lib/, respectively.
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
endif ()
if (NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif ()
if (NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
endif ()
find_package(fmt QUIET)
if (fmt_FOUND)
message(STATUS "Found fmt")
elseif (NOT fmt_FOUND AND NOT TARGET fmt::fmt)
message("fmt was not found: add fmt subdirectory")
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/fmt/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/fmt")
execute_process(COMMAND git submodule update --init extern/fmt
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif ()
# we use the header-only version of fmt
# -> add `target_compile_definitions($TARGET PUBLIC FMT_HEADER_ONLY)` for
# targets using fmt
#set(FMT_TEST OFF CACHE BOOL "Enable building fmt tests" FORCE)
#add_subdirectory(extern/fmt)
endif ()
set(FBS_DIR_FULL_PREFIX "${MOTION_ROOT_DIR}/fbs")
set(FBS_INCLUDE_PREFIX "${MOTION_ROOT_DIR}/src/motioncore/communication/fbs_headers")
find_package(Flatbuffers QUIET)
if (Flatbuffers_FOUND)
message(STATUS "Found flatbuffers")
if (WIN32)
set(FLATBUFFERS_FLATC_EXECUTABLE "flatc.exe")
else()
set(FLATBUFFERS_FLATC_EXECUTABLE "flatc")
endif()
elseif (NOT Flatbuffers_FOUND AND NOT TARGET flatbuffers::flatbuffers)
message("flatbuffers was not found: add flatbuffers subdirectory")
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/flatbuffers/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/flatbuffers")
execute_process(COMMAND git submodule update --init extern/flatbuffers
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif ()
set(FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "Enable building flatlib" FORCE)
set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "Disable building flathash" FORCE)
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "Disable building flatbuffers tests" FORCE)
add_subdirectory(${PROJECT_SOURCE_DIR}/extern/flatbuffers
${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build)
if (WIN32)
set(FLATBUFFERS_FLATC_EXECUTABLE "${PROJECT_BINARY_DIR}/bin/flatc.exe")
else()
set(FLATBUFFERS_FLATC_EXECUTABLE "${PROJECT_BINARY_DIR}/bin/flatc")
endif()
endif ()
add_subdirectory(fbs)
add_subdirectory(src/motioncore)
if (MOTION_BUILD_TESTS)
find_package(GTest QUIET)
if (GTest_Found)
message(STATUS "Found GTest")
elseif (NOT GTest_Found AND NOT TARGET gtest::gtest)
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/googletest/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/googletest")
execute_process(COMMAND git submodule update --init extern/googletest
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif ()
set(BUILD_GMOCK OFF CACHE BOOL "Disable building gmock" FORCE)
add_subdirectory(extern/googletest)
add_subdirectory(src/test)
endif ()
endif (MOTION_BUILD_TESTS)
if (MOTION_BUILD_BENCHMARKS)
find_package(benchmark QUIET)
if (benchmark_Found)
message(STATUS "Found benchmark")
elseif (NOT benchmark_Found AND NOT TARGET benchmark::benchmark AND NOT TARGET benchmark::benchmark_main)
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/benchmark/CMakeLists.txt")
find_package(Git REQUIRED)
message("initialize Git submodule: extern/benchmark")
execute_process(COMMAND git submodule update --init extern/benchmark
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
endif ()
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Don't build tests for the benchmark library")
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Don't install the benchmark library")
add_subdirectory(extern/benchmark EXCLUDE_FROM_ALL)
endif ()
add_subdirectory(src/benchmark)
endif (MOTION_BUILD_BENCHMARKS)
if (MOTION_BUILD_EXE)
add_subdirectory(src/examples)
endif (MOTION_BUILD_EXE)
if (MOTION_BUILD_DOC)
add_subdirectory(doc)
endif (MOTION_BUILD_DOC)