forked from mavlink/MAVSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
340 lines (278 loc) · 9.88 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
cmake_minimum_required(VERSION 2.8.12)
set(CMAKE_INSTALL_PREFIX "../install" CACHE PATH "default cache path")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
project(dronecore)
# Add DEBUG define for Debug target
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG")
# This finds thread libs on Linux, Mac, and Windows.
find_package(Threads REQUIRED)
if(NOT MSVC)
# Clang and GCC
# We want C++11 and lots of warnings.
# We are not using exceptions to make it easier to write wrappers.
add_definitions(
-std=c++11
-fno-exceptions
)
set(warnings "-Wall -Wextra -Werror -Wshadow -Wno-strict-aliasing -Wold-style-cast -Wdouble-promotion -Wformat=2")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
set(warnings "${warnings} -Wduplicated-cond -Wnull-dereference")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7)
set(warnings "${warnings} -Wduplicated-branches")
endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5)
set(warnings "${warnings} -Wno-missing-field-initializers")
endif()
set(warnings "${warnings} -Wuseless-cast -Wlogical-op")
endif()
set(curl_lib "curl")
else()
# MSBuild
add_definitions(
-std=c++11
-DWINDOWS
-DCURL_STATICLIB
)
set(CMAKE_CXX_FLAGS_RELEASE "/MD")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
set(warnings "-WX -W2")
# You need to call cmake with -DWIN_CURL_INCLUDE_DIR:STRING="C:\\curl-7.54.1\\include"
if(NOT WIN_CURL_INCLUDE_DIR)
message(FATAL_ERROR "Please provide argument -DWIN_CURL_INCLUDE_DIR:STRING=\"path_to_curl_include\"")
endif()
if(NOT WIN_CURL_LIB)
message(FATAL_ERROR "Please provide argument -DWIN_CURL_LIBSTRING=\"path_to_curl_lib\"")
endif()
include_directories(${WIN_CURL_INCLUDE_DIR})
set(curl_lib ${WIN_CURL_LIB})
endif()
# Clang needs this warning disabled.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Some time ago we needed `-stdlib=libc++` but that does not seem to be true anymore.
set(warnings "${warnings} -Wno-missing-braces")
endif()
# We need a define if on APPLE
if(APPLE)
add_definitions("-DAPPLE")
endif()
if (ANDROID)
add_definitions(-frtti)
# Workaround for a plugin where the __androidx86__ is necessary.
if (ANDROID_ABI STREQUAL "x86")
add_definitions(-D__androidx86__)
endif()
endif()
# Add definition for __FILENAME__ so we don't need to use __FILE__ because it also
# contains the path.
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
# Set these in a module to add a library.
set (additional_includes "")
set (additional_libs "")
# Autogenerate the device_plugin_container.{h|cpp} to include all plugins.
include(autogenerate_plugin_container.cmake)
# Header files in include denote public facing header files, the rest is in
# core or the respective plugin directories.
include_directories(
include
libs/include
core
${plugins}
${external_plugins}
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/core
SYSTEM ${EXTERNAL_DIR}/${additional_includes}
)
if (DEFINED additional_includes AND NOT additional_includes STREQUAL "")
message(STATUS "Additional includes: ${additional_includes}")
endif()
if (ANDROID)
include_directories(curl-android-ios/prebuilt-with-ssl/android/include)
endif()
if (IOS)
include_directories(curl-android-ios/prebuilt-with-ssl/ios/include)
endif()
if (IOS OR ANDROID OR MSVC OR APPLE)
set(library_type "STATIC")
# We need tinyxml2 for the camera definition parsing.
# We use the submodule when linking statically.
add_subdirectory(libs/tinyxml2 EXCLUDE_FROM_ALL)
include_directories(SYSTEM libs/tinyxml2)
else()
set(library_type "SHARED")
endif()
# We build one static library.
add_library(dronecore ${library_type}
core/global_include.cpp
core/connection.cpp
core/device.cpp
core/device_impl.cpp
core/mavlink_parameters.cpp
core/mavlink_commands.cpp
core/dronecore.cpp
core/dronecore_impl.cpp
core/mavlink_channels.cpp
core/mavlink_receiver.cpp
core/serial_connection.cpp
core/tcp_connection.cpp
core/udp_connection.cpp
core/plugin_impl_base.cpp
core/curl_wrapper.cpp
core/http_loader.cpp
core/timeout_handler.cpp
core/call_every_handler.cpp
${CMAKE_CURRENT_BINARY_DIR}/core/device_plugin_container.cpp
${plugin_source_files}
)
target_link_libraries(dronecore
${CMAKE_THREAD_LIBS_INIT}
${curl_lib}
tinyxml2
)
if (MSVC)
target_link_libraries(dronecore
ws2_32
)
endif()
# cmake should check for C++11
set_property(TARGET dronecore PROPERTY CXX_STANDARD 11)
set_property(TARGET dronecore PROPERTY CXX_STANDARD_REQUIRED ON)
set_target_properties(dronecore
PROPERTIES COMPILE_FLAGS ${warnings}
)
# Use tinyxml2 from the host system for Linux.
if(NOT IOS AND NOT ANDROID AND NOT MSVC AND NOT APPLE)
endif()
# We support install in order to use the header and library files in
# other applications.
if(ANDROID)
set(lib_path "lib/android/${ANDROID_ABI}")
elseif(IOS)
set(lib_path "lib/ios")
else()
set(lib_path "lib")
endif()
install(TARGETS dronecore
EXPORT dronecore-targets
DESTINATION ${lib_path}
)
install(FILES
include/dronecore.h
include/device.h
${CMAKE_CURRENT_BINARY_DIR}/include/device_plugin_container.h
${plugin_header_paths}
DESTINATION "include/dronecore"
)
if(NOT IOS AND NOT ANDROID)
add_subdirectory(integration_tests)
if (DEFINED EXTERNAL_DIR AND NOT EXTERNAL_DIR STREQUAL "")
add_subdirectory(${EXTERNAL_DIR}/integration_tests
${CMAKE_CURRENT_BINARY_DIR}/${EXTERNAL_DIR}/integration_tests)
endif()
enable_testing()
add_subdirectory(libs/gtest EXCLUDE_FROM_ALL)
# SYSTEM because we don't want warnings for gtest headers.
include_directories(SYSTEM libs/gtest/googletest/include)
include_directories(SYSTEM libs/gtest/googlemock/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTESTING")
add_executable(unit_tests_runner
core/global_include_test.cpp
core/mavlink_channels_test.cpp
core/unittests_main.cpp
core/http_loader_test.cpp
core/timeout_handler_test.cpp
core/call_every_handler_test.cpp
${plugin_unittest_source_files}
${unit_tests_src}
)
if (MSVC)
# We need this to prevent linking errors from happening in the Windows build.
target_compile_definitions(unit_tests_runner PRIVATE -DGTEST_LINKED_AS_SHARED_LIBRARY)
target_compile_options(unit_tests_runner PUBLIC "/wd4251" "/wd4275")
endif()
target_compile_definitions(unit_tests_runner PRIVATE FAKE_TIME=1)
set_target_properties(unit_tests_runner
PROPERTIES COMPILE_FLAGS ${warnings}
)
target_link_libraries(unit_tests_runner
dronecore
gtest
gtest_main
gmock
${additional_libs}
)
add_test(unit_tests
unit_tests_runner
)
# `make test` does not show output, but `make check` does
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
# This includes all GTests that run integration tests
add_executable(integration_tests_runner
core/unittests_main.cpp
${integration_tests_src}
)
set_target_properties(integration_tests_runner
PROPERTIES COMPILE_FLAGS ${warnings}
)
target_link_libraries(integration_tests_runner
dronecore
gtest
gtest_main
gmock
${additional_libs}
)
if (MSVC)
# We need this to prevent linking errors from happening in the Windows build.
target_compile_definitions(integration_tests_runner PRIVATE -DGTEST_LINKED_AS_SHARED_LIBRARY)
target_compile_options(integration_tests_runner PUBLIC "/wd4251" "/wd4275")
endif()
add_test(integration_tests
integration_tests_runner
)
add_custom_command(TARGET integration_tests_runner
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/start_px4_sitl.sh
${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_command(TARGET integration_tests_runner
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/stop_px4_sitl.sh
${CMAKE_CURRENT_BINARY_DIR}
)
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
find_package(GRPC)
if(GRPC_FOUND)
# If protobuf is installed to e.g. /opt/protobuf, you need to specifiy this via environment variable:
# `export PROTOBUF_DIR=/opt/protobuf`
#
if (DEFINED ENV{PROTOBUF_DIR})
message(STATUS "PROTOBUF_DIR manually set, using protobuf from $ENV{PROTOBUF_DIR}")
set(Protobuf_INCLUDE_DIRS "$ENV{PROTOBUF_DIR}/include")
set(Protobuf_PROTOC_EXECUTABLE "$ENV{PROTOBUF_DIR}/bin/protoc")
set(Protobuf_PROTOC_LIBRARY_DIR "$ENV{PROTOBUF_DIR}/lib")
set(Protobuf_PROTOC_LIBRARIES "$ENV{PROTOBUF_DIR}/lib/libprotoc.so")
set(Protobuf_LIBRARIES "$ENV{PROTOBUF_DIR}/lib/libprotobuf.so")
else()
message(STATUS "PROTOBUF_DIR not set, checking automatically for Protobuf")
find_package(Protobuf REQUIRED)
endif()
add_subdirectory(grpc/server)
add_subdirectory(grpc/python_client)
else()
message(STATUS "gRPC not found, skipping gRPC build")
endif()
endif()
if (DROP_DEBUG EQUAL 1)
add_definitions(-DDROP_DEBUG=${DROP_DEBUG})
add_executable(drop_debug
debug_helpers/drop_debug_main.cpp
)
target_link_libraries(drop_debug
dronecore
)
endif()