-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
511 lines (482 loc) · 24.4 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
cmake_minimum_required(VERSION 2.8...3.16)
if(${CMAKE_VERSION} VERSION_LESS "3.12")
message(WARNING "CMake < 3.12 is not fully supported...")
endif()
#if(POLICY CMP0053)
#cmake_policy(SET CMP0053 OLD)
#endif()
set(ProgramFilesx86 "ProgramFiles(x86)")
if(POLICY CMP0076)
cmake_policy(SET CMP0076 OLD)
endif()
project(hardwarex)
if(NOT(PROJECT_BINARY_DIR STREQUAL PROJECT_SOURCE_DIR))
message(WARNING "Please set the CMake build folder to the same as the source folder if possible...")
message(WARNING "Ensure also the working directory at runtime is hardwarex folder...")
endif()
option(RPLIDARSDK200 "RPLIDARSDK200" ON)
option(RPLIDARSDK1120 "RPLIDARSDK1120" OFF)
if(WIN32)
if(NOT DEFINED ARCH)
# First attempt to guess...
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "x64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH "x86")
else()
message(WARNING "Unknown architecture, please try to set manually ARCH and RUNTIME variables...")
endif()
if(MSVC)
# Get cl target bitness
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64")
set(ARCH "x64")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win64")
set(ARCH "x64")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x86")
set(ARCH "x86")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32")
set(ARCH "x86")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM64")
set(ARCH "ARM64")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM")
set(ARCH "ARM")
endif()
endif()
endif()
if(NOT DEFINED RUNTIME)
if(MSVC)
if(MSVC_TOOLSET_VERSION EQUAL 80)
set(RUNTIME "vc8")
elseif(MSVC_TOOLSET_VERSION EQUAL 90)
set(RUNTIME "vc9")
elseif(MSVC_TOOLSET_VERSION EQUAL 100)
set(RUNTIME "vc10")
elseif(MSVC_TOOLSET_VERSION EQUAL 110)
set(RUNTIME "vc11")
elseif(MSVC_TOOLSET_VERSION EQUAL 120)
set(RUNTIME "vc12")
elseif(MSVC_TOOLSET_VERSION EQUAL 140)
set(RUNTIME "vc14")
elseif(MSVC_TOOLSET_VERSION EQUAL 141)
set(RUNTIME "vc15")
elseif(MSVC_TOOLSET_VERSION EQUAL 142)
set(RUNTIME "vc16")
elseif(MSVC_TOOLSET_VERSION EQUAL 143)
set(RUNTIME "vc17")
elseif(MSVC_TOOLSET_VERSION EQUAL 144)
set(RUNTIME "vc18")
else()
message(WARNING "Unknown Visual Studio compiler, please try to set manually ARCH and RUNTIME variables...")
set(RUNTIME "vc10") # MSVC_TOOLSET_VERSION not set probably because an old version of CMake on XP with hopefully the latest Visual Studio for XP...
endif()
elseif(MINGW)
set(RUNTIME "mingw")
else()
message(WARNING "Unknown compiler, please try to set manually ARCH and RUNTIME variables...")
endif()
endif()
else()
if(NOT DEFINED ARCH)
# CMAKE_SYSTEM_PROCESSOR...?
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH "x86_64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH "i386")
else()
message(WARNING "Unknown architecture, please try to set manually ARCH and USR_LIB_ARCH_DIR variables...")
endif()
endif()
if(NOT DEFINED USR_LIB_ARCH_DIR)
if(APPLE)
set(USR_LIB_ARCH_DIR "/usr/local/lib")
else()
if("${ARCH}" STREQUAL "x86_64")
set(USR_LIB_ARCH_DIR "/usr/lib/${ARCH}-linux-gnu")
elseif("${ARCH}" STREQUAL "i386")
set(USR_LIB_ARCH_DIR "/usr/lib/${ARCH}-linux-gnu")
else()
message(WARNING "Unknown architecture, please try to set manually ARCH and USR_LIB_ARCH_DIR variables...")
set(USR_LIB_ARCH_DIR "/usr/lib")
endif()
endif()
endif()
endif()
if(WIN32 AND ((NOT DEFINED LIBPREFIXRUNTIME) OR (NOT DEFINED LIBEXTRUNTIME)))
if(MSVC)
set(LIBPREFIXRUNTIME "")
set(LIBEXTRUNTIME ".lib")
elseif(MINGW)
set(LIBPREFIXRUNTIME "lib")
set(LIBEXTRUNTIME ".dll.a")
else()
message(WARNING "Please try to set manually LIBPREFIXRUNTIME and LIBEXTRUNTIME variables...")
endif()
endif()
option(ENABLE_AUTO_DOWNLOAD "ENABLE_AUTO_DOWNLOAD" ON)
if(WIN32)
#set(SUDO_COMMAND "elevate" CACHE STRING "SUDO_COMMAND")
#set(INSTALL_PKG_COMMAND "choco install -y" CACHE STRING "INSTALL_PKG_COMMAND")
set(MAVLINK_PKG_PREFIX "$ENV{ProgramFiles}" CACHE STRING "MAVLINK_PKG_PREFIX")
set(SBG_SDK_PKG_PREFIX "$ENV{ProgramFiles}" CACHE STRING "SBG_SDK_PKG_PREFIX")
set(RPLIDAR_SDK_PKG_PREFIX "$ENV{ProgramFiles}" CACHE STRING "RPLIDAR_SDK_PKG_PREFIX")
#option(ENABLE_FIND_PACKAGE "ENABLE_FIND_PACKAGE" ON)
elseif(APPLE)
set(SUDO_COMMAND "sudo" CACHE STRING "SUDO_COMMAND")
set(INSTALL_PKG_COMMAND "brew install" CACHE STRING "INSTALL_PKG_COMMAND")
set(MAVLINK_PKG_PREFIX "/usr/local" CACHE STRING "MAVLINK_PKG_PREFIX")
set(SBG_SDK_PKG_PREFIX "/usr/local" CACHE STRING "SBG_SDK_PKG_PREFIX")
set(RPLIDAR_SDK_PKG_PREFIX "/usr/local" CACHE STRING "RPLIDAR_SDK_PKG_PREFIX")
#option(ENABLE_FIND_PACKAGE "ENABLE_FIND_PACKAGE" ON)
else()
set(SUDO_COMMAND "sudo" CACHE STRING "SUDO_COMMAND")
set(INSTALL_PKG_COMMAND "sudo apt-get -y install" CACHE STRING "INSTALL_PKG_COMMAND")
set(MAVLINK_PKG_PREFIX "/usr/local" CACHE STRING "MAVLINK_PKG_PREFIX")
set(SBG_SDK_PKG_PREFIX "/usr/local" CACHE STRING "SBG_SDK_PKG_PREFIX")
set(RPLIDAR_SDK_PKG_PREFIX "/usr/local" CACHE STRING "RPLIDAR_SDK_PKG_PREFIX")
#option(ENABLE_FIND_PACKAGE "ENABLE_FIND_PACKAGE" ON)
endif()
option(ENABLE_STATIC "ENABLE_STATIC" OFF)
if(ENABLE_AUTO_DOWNLOAD)
if(WIN32)
message(STATUS "If behind a proxy, you might need to type e.g. \"set https_proxy=192.168.1.17:8080\" in the same terminal before running cmake-gui/cmake to configure the proxy settings...")
else()
message(STATUS "If behind a proxy, you might need to type e.g. \"export https_proxy=192.168.1.17:8080\" in the same terminal before running cmake-gui/cmake to configure the proxy settings...")
endif()
message(STATUS "If some prerequisites cannot be downloaded and installed automatically, try to install them manually and change ENABLE_AUTO_DOWNLOAD option in cmake-gui/cmake...")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_SOURCES hardwarex.cpp OSTime.c OSThread.c OSNet.c OSMisc.c OSCriticalSection.c OSCore.c OSComputerRS232Port.c)
else()
add_library(hardwarex SHARED hardwarex.cpp OSTime.c OSThread.c OSNet.c OSMisc.c OSCriticalSection.c OSCore.c OSComputerRS232Port.c)
endif()
include_directories("${PROJECT_SOURCE_DIR}")
option(_DEBUG "_DEBUG" OFF)
option(_DEBUG_DISPLAY "_DEBUG_DISPLAY" OFF)
option(_DEBUG_MESSAGES "_DEBUG_MESSAGES" OFF)
option(_DEBUG_WARNINGS "_DEBUG_WARNINGS" OFF)
option(ENABLE_MAVLINK_SUPPORT "ENABLE_MAVLINK_SUPPORT" OFF)
option(ENABLE_SBG_SDK_SUPPORT "ENABLE_SBG_SDK_SUPPORT" OFF)
option(DISABLE_SBG_TCP "DISABLE_SBG_TCP" OFF)
option(ENABLE_RPLIDAR_SDK_SUPPORT "ENABLE_RPLIDAR_SDK_SUPPORT" OFF)
if(RPLIDARSDK1120)
option(FORCE_RPLIDAR_SDK_V1 "FORCE_RPLIDAR_SDK_V1" ON)
else()
option(FORCE_RPLIDAR_SDK_V1 "FORCE_RPLIDAR_SDK_V1" OFF)
endif()
if(APPLE)
option(USE_OLD_CHRONO "USE_OLD_CHRONO" ON)
else()
option(USE_OLD_CHRONO "USE_OLD_CHRONO" OFF)
endif()
mark_as_advanced(SUDO_COMMAND INSTALL_PKG_COMMAND MAVLINK_PKG_PREFIX SBG_SDK_PKG_PREFIX RPLIDAR_SDK_PKG_PREFIX _DEBUG _DEBUG_DISPLAY _DEBUG_MESSAGES _DEBUG_WARNINGS DISABLE_AIS_SUPPORT)
if(ENABLE_MAVLINK_SUPPORT)
add_definitions(-D ENABLE_MAVLINK_SUPPORT)
if(WIN32)
set(MAVLINK_SDK_DIR "${MAVLINK_PKG_PREFIX}/MAVLinkSDK")
if(ENABLE_AUTO_DOWNLOAD)
if(NOT EXISTS "${MAVLINK_PKG_PREFIX}/MAVLinkSDK/mavlink/common/mavlink.h")
message(STATUS "Downloading mavlink...")
file(DOWNLOAD "https://github.com/mavlink/c_library_v1/archive/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip" "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${MAVLINK_SDK_DIR}")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/c_library_v1-a44ece42bc76b1f257f4f540d7283e0c874ac6d9" "${MAVLINK_SDK_DIR}/mavlink")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_SOURCE_DIR}/c_library_v1-a44ece42bc76b1f257f4f540d7283e0c874ac6d9")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
endif()
endif()
include_directories("${MAVLINK_SDK_DIR}")
else()
if(ENABLE_AUTO_DOWNLOAD)
if((NOT EXISTS "${MAVLINK_PKG_PREFIX}/include/mavlink/common/mavlink.h") AND (NOT EXISTS "/usr/include/mavlink/common/mavlink.h"))
message(STATUS "Downloading mavlink...")
file(DOWNLOAD "https://github.com/mavlink/c_library_v1/archive/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip" "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p ${MAVLINK_PKG_PREFIX}/include")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mv -f \"${PROJECT_SOURCE_DIR}/c_library_v1-a44ece42bc76b1f257f4f540d7283e0c874ac6d9\" ${MAVLINK_PKG_PREFIX}/include/mavlink")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/a44ece42bc76b1f257f4f540d7283e0c874ac6d9.zip")
endif()
endif()
include_directories("${MAVLINK_PKG_PREFIX}/include")
endif()
else()
if(WIN32)
if(EXISTS "${MAVLINK_PKG_PREFIX}/MAVLinkSDK/mavlink/common/mavlink.h")
message(STATUS "mavlink has been detected, see ENABLE_MAVLINK_SUPPORT option to try to use it...")
endif()
else()
if((EXISTS "${MAVLINK_PKG_PREFIX}/include/mavlink/common/mavlink.h") OR (EXISTS "/usr/include/mavlink/common/mavlink.h"))
message(STATUS "mavlink has been detected, see ENABLE_MAVLINK_SUPPORT option to try to use it...")
endif()
endif()
endif()
if(ENABLE_SBG_SDK_SUPPORT)
add_definitions(-D ENABLE_SBG_SDK_SUPPORT)
if(WIN32)
set(SBG_SDK_DIR "${SBG_SDK_PKG_PREFIX}/SBG Systems/Inertial SDK/Software Development/sbgECom")
if(ENABLE_AUTO_DOWNLOAD)
if((NOT EXISTS "${SBG_SDK_DIR}/common/sbgCommon.h") OR (NOT EXISTS "${SBG_SDK_DIR}/${ARCH}/vc15/lib/sbgECom.lib"))
message(STATUS "Downloading SBG SDK...")
file(DOWNLOAD "http://www.ensta-bretagne.fr/lebars/Share/SBG%20Systems.zip" "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/SBG Systems" "${SBG_SDK_PKG_PREFIX}/SBG Systems")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_SOURCE_DIR}/SBG Systems")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
endif()
endif()
include_directories("${SBG_SDK_DIR}/common")
include_directories("${SBG_SDK_DIR}/src")
if(MSVC)
if(ENABLE_STATIC)
set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${SBG_SDK_DIR}/${ARCH}/${RUNTIME}/staticlib\" ${CMAKE_SHARED_LINKER_FLAGS}")
else()
set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${SBG_SDK_DIR}/${ARCH}/${RUNTIME}/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_LIBRARIES debug sbgEComd)
list(APPEND hardwarex_LIBRARIES optimized sbgECom)
else()
target_link_libraries(hardwarex debug sbgEComd)
target_link_libraries(hardwarex optimized sbgECom)
endif()
else()
if(ENABLE_STATIC)
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${SBG_SDK_DIR}/${ARCH}/vc15/staticlib\" ${CMAKE_SHARED_LINKER_FLAGS}")
else()
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${SBG_SDK_DIR}/${ARCH}/vc15/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_LIBRARIES sbgECom)
else()
target_link_libraries(hardwarex sbgECom)
endif()
endif()
else()
if(ENABLE_AUTO_DOWNLOAD)
if(((NOT EXISTS "${SBG_SDK_PKG_PREFIX}/include/sbgECom/common/sbgCommon.h") OR (NOT EXISTS "${SBG_SDK_PKG_PREFIX}/lib/libsbgECom.a")) AND
((NOT EXISTS "/usr/include/sbgECom/common/sbgCommon.h") OR (NOT EXISTS "/usr/lib/libsbgECom.a")))
message(STATUS "Downloading SBG SDK...")
file(DOWNLOAD "http://www.ensta-bretagne.fr/lebars/Share/SBG%20Systems.zip" "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
execute_process(COMMAND sh -c "cd \"${PROJECT_SOURCE_DIR}/SBG Systems/Inertial SDK/Software Development/sbgECom/projects/unix\" && cmake . && make")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p \"${SBG_SDK_PKG_PREFIX}/include/sbgECom\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p \"${SBG_SDK_PKG_PREFIX}/lib\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/SBG Systems/Inertial SDK/Software Development/sbgECom/src/\" \"${SBG_SDK_PKG_PREFIX}/include/sbgECom/src\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/SBG Systems/Inertial SDK/Software Development/sbgECom/common/\" \"${SBG_SDK_PKG_PREFIX}/include/sbgECom/common\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/SBG Systems/Inertial SDK/Software Development/sbgECom/bin/libsbgECom.a\" \"${SBG_SDK_PKG_PREFIX}/lib/libsbgECom.a\"")
#execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_SOURCE_DIR}/SBG Systems") # To keep the possibility to use "./SBG Systems" as installation folder
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/SBG Systems.zip")
endif()
endif()
include_directories("${SBG_SDK_PKG_PREFIX}/include/sbgECom/common")
include_directories("${SBG_SDK_PKG_PREFIX}/include/sbgECom/src")
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${SBG_SDK_PKG_PREFIX}/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_LIBRARIES sbgECom)
else()
target_link_libraries(hardwarex sbgECom)
endif()
endif()
else()
if(WIN32)
if(EXISTS "${SBG_SDK_PKG_PREFIX}/SBG Systems/Inertial SDK/Software Development/sbgECom/common/sbgCommon.h")
message(STATUS "SBG SDK has been detected, see ENABLE_SBG_SDK_SUPPORT option to try to use it...")
endif()
else()
if((EXISTS "${SBG_SDK_PKG_PREFIX}/include/sbgECom/common/sbgCommon.h") OR (EXISTS "/usr/include/sbgECom/common/sbgCommon.h"))
message(STATUS "SBG SDK has been detected, see ENABLE_SBG_SDK_SUPPORT option to try to use it...")
endif()
endif()
endif()
if(ENABLE_RPLIDAR_SDK_SUPPORT)
add_definitions(-D ENABLE_RPLIDAR_SDK_SUPPORT)
if(RPLIDARSDK1120)
set(RPLIDAR_SDK_REL_DIR "rplidar_sdk/sdk")
set(RPLIDAR_SDK_DOWNLOAD_LINK "https://github.com/lebarsfa/rplidar_sdk/releases/download/release%2Fv1.12.0-enstabre/rplidar_sdk.zip")
set(RPLIDAR_SDK_HDR_NAME "sl_lidar.h")
if(WIN32)
set(RPLIDAR_SDK_LIB_NAME "rplidar_driver")
else()
set(RPLIDAR_SDK_LIB_NAME "rplidar_sdk")
endif()
else()
set(RPLIDAR_SDK_REL_DIR "rplidar_sdk")
set(RPLIDAR_SDK_DOWNLOAD_LINK "https://github.com/lebarsfa/rplidar_sdk/releases/download/release%2Fv2.0.0-enstabre/rplidar_sdk.zip")
set(RPLIDAR_SDK_HDR_NAME "rplidar.h")
if(WIN32)
set(RPLIDAR_SDK_LIB_NAME "rplidar_driver")
else()
set(RPLIDAR_SDK_LIB_NAME "sl_lidar_sdk")
endif()
endif()
if(WIN32)
if(ARCH STREQUAL "x64")
set(RPLIDAR_SDK_RUNTIME "win64")
else()
set(RPLIDAR_SDK_RUNTIME "win32")
endif()
elseif(APPLE)
set(RPLIDAR_SDK_RUNTIME "Darwin")
else()
set(RPLIDAR_SDK_RUNTIME "Linux")
endif()
if(WIN32)
set(RPLIDAR_SDK_DIR "${RPLIDAR_SDK_PKG_PREFIX}/${RPLIDAR_SDK_REL_DIR}")
if(ENABLE_AUTO_DOWNLOAD)
if((NOT EXISTS "${RPLIDAR_SDK_DIR}/sdk/include/${RPLIDAR_SDK_HDR_NAME}") OR (NOT EXISTS "${RPLIDAR_SDK_DIR}/output/win32/Release/${RPLIDAR_SDK_LIB_NAME}.lib"))
message(STATUS "Downloading RPLIDAR SDK...")
file(DOWNLOAD "${RPLIDAR_SDK_DOWNLOAD_LINK}" "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/rplidar_sdk" "${RPLIDAR_SDK_PKG_PREFIX}/rplidar_sdk")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_SOURCE_DIR}/rplidar_sdk")
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
endif()
endif()
include_directories("${RPLIDAR_SDK_DIR}/sdk/include")
include_directories("${RPLIDAR_SDK_DIR}/sdk/src")
if(MSVC)
if(ENABLE_STATIC)
#set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${RPLIDAR_SDK_DIR}/output/${ARCH}/${RUNTIME}/staticlib\" ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${RPLIDAR_SDK_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release\" ${CMAKE_SHARED_LINKER_FLAGS}")
else()
#set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${RPLIDAR_SDK_DIR}/output/${ARCH}/${RUNTIME}/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "/LIBPATH:\"${RPLIDAR_SDK_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Debug\" ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
#list(APPEND hardwarex_LIBRARIES debug ${RPLIDAR_SDK_LIB_NAME}d)
#list(APPEND hardwarex_LIBRARIES optimized ${RPLIDAR_SDK_LIB_NAME})
list(APPEND hardwarex_LIBRARIES ${RPLIDAR_SDK_LIB_NAME})
else()
#target_link_libraries(hardwarex debug ${RPLIDAR_SDK_LIB_NAME}d)
#target_link_libraries(hardwarex optimized ${RPLIDAR_SDK_LIB_NAME})
target_link_libraries(hardwarex ${RPLIDAR_SDK_LIB_NAME})
endif()
else()
if(ENABLE_STATIC)
#set(CMAKE_SHARED_LINKER_FLAGS "-L\"${RPLIDAR_SDK_DIR}/output/${ARCH}/${RUNTIME}/staticlib\" ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${RPLIDAR_SDK_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release\" ${CMAKE_SHARED_LINKER_FLAGS}")
else()
#set(CMAKE_SHARED_LINKER_FLAGS "-L\"${RPLIDAR_SDK_DIR}/output/${ARCH}/${RUNTIME}/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${RPLIDAR_SDK_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release\" ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_LIBRARIES ${RPLIDAR_SDK_LIB_NAME})
else()
target_link_libraries(hardwarex ${RPLIDAR_SDK_LIB_NAME})
endif()
endif()
else()
if(ENABLE_AUTO_DOWNLOAD)
if(((NOT EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/include/${RPLIDAR_SDK_HDR_NAME}") OR (NOT EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/lib/lib${RPLIDAR_SDK_LIB_NAME}.a")) AND
((NOT EXISTS "/usr/include/${RPLIDAR_SDK_REL_DIR}/include/${RPLIDAR_SDK_HDR_NAME}") OR (NOT EXISTS "/usr/lib/lib${RPLIDAR_SDK_LIB_NAME}.a")))
message(STATUS "Downloading RPLIDAR SDK...")
file(DOWNLOAD "${RPLIDAR_SDK_DOWNLOAD_LINK}" "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
execute_process(WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
if(APPLE)
execute_process(COMMAND sh -c "cd \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}\" && rm -Rf output && SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk make")
else()
execute_process(COMMAND sh -c "cd \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}\" && rm -Rf output && make")
endif()
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p \"${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/sdk\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p \"${RPLIDAR_SDK_PKG_PREFIX}/lib\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} mkdir -p \"${RPLIDAR_SDK_PKG_PREFIX}/bin\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}/sdk/include/\" \"${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/sdk/include\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}/sdk/src/\" \"${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/sdk/src\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release/lib${RPLIDAR_SDK_LIB_NAME}.a\" \"${RPLIDAR_SDK_PKG_PREFIX}/lib/lib${RPLIDAR_SDK_LIB_NAME}.a\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release/ultra_simple\" \"${RPLIDAR_SDK_PKG_PREFIX}/bin/ultra_simple\"")
execute_process(COMMAND sh -c "${SUDO_COMMAND} cp -Rf \"${PROJECT_SOURCE_DIR}/${RPLIDAR_SDK_REL_DIR}/output/${RPLIDAR_SDK_RUNTIME}/Release/simple_grabber\" \"${RPLIDAR_SDK_PKG_PREFIX}/bin/simple_grabber\"")
#execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_SOURCE_DIR}/rplidar_sdk") # To keep the possibility to use "./rplidar_sdk" as installation folder
execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${PROJECT_SOURCE_DIR}/rplidar_sdk.zip")
endif()
endif()
include_directories("${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/sdk/include")
include_directories("${RPLIDAR_SDK_PKG_PREFIX}/include/${RPLIDAR_SDK_REL_DIR}/sdk/src")
set(CMAKE_SHARED_LINKER_FLAGS "-L\"${RPLIDAR_SDK_PKG_PREFIX}/lib\" ${CMAKE_SHARED_LINKER_FLAGS}")
if(${CMAKE_VERSION} VERSION_LESS "3.1")
list(APPEND hardwarex_LIBRARIES ${RPLIDAR_SDK_LIB_NAME})
else()
target_link_libraries(hardwarex ${RPLIDAR_SDK_LIB_NAME})
endif()
endif()
else()
if(WIN32)
if(EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/rplidar_sdk/sdk/include/sl_lidar.h")
message(STATUS "RPLIDAR SDK v2 has been detected, see ENABLE_RPLIDAR_SDK_SUPPORT and RPLIDARSDK200 options to try to use it...")
elseif(EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/rplidar_sdk/sdk/sdk/include/rplidar.h")
message(STATUS "RPLIDAR SDK v1 has been detected, see ENABLE_RPLIDAR_SDK_SUPPORT and RPLIDARSDK1120 options to try to use it...")
endif()
else()
if((EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/include/rplidar_sdk/sdk/include/sl_lidar.h") OR (EXISTS "/usr/include/rplidar_sdk/sdk/include/sl_lidar.h"))
message(STATUS "RPLIDAR SDK v2 has been detected, see ENABLE_RPLIDAR_SDK_SUPPORT and RPLIDARSDK200 options to try to use it...")
elseif((EXISTS "${RPLIDAR_SDK_PKG_PREFIX}/include/rplidar_sdk/sdk/sdk/include/rplidar.h") OR (EXISTS "/usr/include/rplidar_sdk/sdk/sdk/include/rplidar.h"))
message(STATUS "RPLIDAR SDK v1 has been detected, see ENABLE_RPLIDAR_SDK_SUPPORT and RPLIDARSDK1120 options to try to use it...")
endif()
endif()
endif()
if(_DEBUG)
add_definitions(-D _DEBUG)
endif()
if(_DEBUG_DISPLAY)
add_definitions(-D _DEBUG_DISPLAY)
endif()
if(_DEBUG_MESSAGES)
add_definitions(-D _DEBUG_MESSAGES)
endif()
if(_DEBUG_WARNINGS)
add_definitions(-D _DEBUG_WARNINGS)
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.1")
add_library(hardwarex SHARED ${hardwarex_SOURCES})
target_link_libraries(hardwarex ${hardwarex_LIBRARIES})
endif()
if(DISABLE_SBG_TCP)
add_definitions(-D DISABLE_SBG_TCP)
endif()
if(FORCE_RPLIDAR_SDK_V1)
add_definitions(-D FORCE_RPLIDAR_SDK_V1)
endif()
if(USE_OLD_CHRONO)
add_definitions(-D USE_OLD_CHRONO)
endif()
if(WIN32)
add_definitions(-D _USRDLL -D HARDWAREX_EXPORTS)
add_definitions(-D ENABLE_GETTIMEOFDAY_WIN32)
endif()
add_definitions(-D DISABLE_AIS_SUPPORT)
if(WIN32)
if(MSVC)
if(ENABLE_STATIC)
if(CMAKE_VERSION VERSION_LESS 3.15.0)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
else()
set_target_properties(hardwarex PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
target_link_libraries(hardwarex WS2_32)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Wno-unknown-pragmas -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-unknown-pragmas -Wextra -fpermissive")
if(ENABLE_STATIC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
target_link_libraries(hardwarex WS2_32 m)
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Wno-unknown-pragmas -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-unknown-pragmas -Wextra -fpermissive")
if(ENABLE_STATIC)
if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++")
set(CMAKE_SHARED_LINKER_FLAGS "-static ${CMAKE_SHARED_LINKER_FLAGS}") # Adding -static would refuse any dynamic library left...
endif()
endif()
if(APPLE)
target_link_libraries(hardwarex pthread m)
else()
target_link_libraries(hardwarex pthread rt m)
endif()
# Remove lib prefix to get the same name as for Windows, this is better for MATLAB, but for python lib needs to be added back...
set_target_properties(hardwarex PROPERTIES PREFIX "")
endif()