Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
598 lines (550 loc) · 29.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
598 lines (550 loc) · 29.2 KB
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
# ---------------------------------------------------------------------------------------------------------------------
#
# Copyright (C) Microsoft Corporation.
# Copyright (C) 2025 IAMAI CONSULTING CORP
#
# MIT License. All rights reserved.
#
# Module Name:
#
# CMakeLists.txt
#
# Abstract:
#
# CMake build file.
#
# ---------------------------------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.15.0)
# Before making projects, set CMake policy to use MSVC_RUNTIME_LIBRARY property
cmake_policy(SET CMP0091 NEW)
# CMake 3.24+ warns unless URL-based FetchContent downloads use extraction-time
# timestamps, which avoids stale rebuild decisions when downloaded contents change.
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
# CMake 3.30+ deprecates the current FetchContent_Populate() pattern used below.
# Keep OLD behavior until this file is refactored to FetchContent_MakeAvailable().
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") # Have to match UE (uses /MD non-debug CRT for all configs)
include(FetchContent)
include(ExternalProject)
if (UNIX)
if(DEFINED ENV{UE_ROOT} AND NOT "$ENV{UE_ROOT}" STREQUAL "")
# Build/link against UE's packaged Linux toolchain instead of system-installed toolchain
# Note: This must be set BEFORE `project()` is called
message("Building/linking against Unreal packaged toolchain from UE_ROOT=$ENV{UE_ROOT}")
set(PROJECTAIRSIM_USE_UE_TOOLCHAIN ON)
set(CMAKE_TOOLCHAIN_FILE "unreal-linux-toolchain.cmake")
link_directories("$ENV{UE_ROOT}/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu")
else()
message("Building/linking against system-installed toolchain")
set(PROJECTAIRSIM_USE_UE_TOOLCHAIN OFF)
set(CMAKE_C_COMPILER clang-13)
set(CMAKE_CXX_COMPILER clang++-13)
endif()
endif()
# Set up project
project("ProjectAirSimLibs")
# Capture build commit hash once during configure. Fallback to "unknown"
# when git is unavailable (or source is not a git checkout).
set(PROJECTAIRSIM_BUILD_COMMIT_HASH "unknown")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PROJECTAIRSIM_BUILD_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE PROJECTAIRSIM_GIT_RESULT
)
if(NOT PROJECTAIRSIM_GIT_RESULT EQUAL 0 OR PROJECTAIRSIM_BUILD_COMMIT_HASH STREQUAL "")
set(PROJECTAIRSIM_BUILD_COMMIT_HASH "unknown")
endif()
endif()
message("PROJECTAIRSIM_BUILD_COMMIT_HASH set to ${PROJECTAIRSIM_BUILD_COMMIT_HASH}")
file(WRITE ${CMAKE_BINARY_DIR}/commit_hash.txt "${PROJECTAIRSIM_BUILD_COMMIT_HASH}\n")
# Set up paths for packaging the sim libs build outputs as custom post-command steps
set(SIMLIBS_PACKAGE_DIR ${CMAKE_SOURCE_DIR}/packages/projectairsim_simlibs)
set(SIMLIBS_SHARED_LIB_DIR ${SIMLIBS_PACKAGE_DIR}/shared_libs)
set(SIMLIBS_TEST_DIR ${CMAKE_BINARY_DIR}/unit_tests)
set(UE_PLUGIN_SIMLIBS_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/ProjectAirSim/SimLibs)
set(UNITY_WRAPPER_DLL_DIR ${CMAKE_SOURCE_DIR}/unity/BlocksUnity/Assets/Plugins)
set(MATLAB_PHYSICS_DIR ${CMAKE_SOURCE_DIR}/physics/matlab_sfunc)
set(MATLAB_CONTROL_DIR ${CMAKE_SOURCE_DIR}/vehicle_apis/multirotor_api/matlab_sfunc)
# set(UE_PLUGIN_CESIUM_NATIVE_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/ProjectAirSim/SimLibs)
# set(UE_CESIUM_PLUGIN_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/CesiumForUnreal/)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(WIN32)
# Note: /EHsc is for MSVC to enable unwinding stack during C++ exception handling
add_compile_options(/EHsc)
# set(CESIUM_CXX_FLAGS /EHsc)
# Disable manifest generation for executables to avoid build failures due to Windows write
# permission issues (possibly from file locks by antivirus or other OS file protection)
add_link_options(/MANIFEST:NO)
elseif(UNIX)
add_compile_definitions(__CLANG__)
add_compile_options(-stdlib=libc++ -ferror-limit=10)
# Note: Linking -lanl (for getaddrinfo) and -pthread are required because of nng
add_link_options(-stdlib=libc++ -lanl -pthread)
# set(CESIUM_CXX_FLAGS "-std=c++17 -stdlib=libc++")
# set(CESIUM_LINKER_FLAGS "-stdlib=libc++ -lc++abi")
# set(CESIUM_LINUX_TOOLCHAIN ${UE_CESIUM_PLUGIN_DIR}/extern/unreal-linux-toolchain.cmake)
endif()
# Set up dependency: nlohmann JSON
# Directly download single include file json.hpp
FetchContent_Declare(
nlohmann-json
URL https://raw.githubusercontent.com/nlohmann/json/v3.11.3/single_include/nlohmann/json.hpp
URL_HASH SHA256=9bea4c8066ef4a1c206b2be5a36302f8926f7fdc6087af5d20b417d0cf103ea6
DOWNLOAD_NO_EXTRACT True
DOWNLOAD_NO_PROGRESS True
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/_deps/nlohmann-install
)
FetchContent_GetProperties(nlohmann-json)
if(NOT nlohmann-json_POPULATED)
message("Checking if [nlohmann-json] dependency needs to be fetched...")
FetchContent_Populate(nlohmann-json)
set(JSON_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/nlohmann-install)
message("JSON_INCLUDE_DIR set to ${JSON_INCLUDE_DIR}")
message("Packaging [JSON (nlohmann)] header to ${UE_PLUGIN_SIMLIBS_DIR}/json/include")
file(COPY ${JSON_INCLUDE_DIR}/ DESTINATION ${UE_PLUGIN_SIMLIBS_DIR}/json/include)
endif()
# Set up dependency: NNG
message("Setting up [NNG] dependency as an external project...")
# CMake external projects don't adopt the parent's CMAKE_MSVC_RUNTIME_LIBRARY setting,
# so to force /MD non-debug CRT to match UE, build Debug config as Relwithdebinfo and
# build Release as Release.
set(NNG_BUILD_TYPE $<IF:$<CONFIG:Debug>,Relwithdebinfo,Release>)
if(WIN32)
set(NNG_CMAKE_LINKER_MANIFEST_FLAG "/MANIFEST:NO")
else()
set(NNG_CMAKE_LINKER_MANIFEST_FLAG "")
endif()
ExternalProject_Add(nng-external
GIT_REPOSITORY https://github.com/nanomsg/nng.git
GIT_TAG v1.11
GIT_CONFIG "advice.detachedHead=false"
PREFIX ${CMAKE_BINARY_DIR}/_deps/nng
# Use Update step override to delete unused /etc/ folder of NNG development support files that list a lot of Go reference packages
UPDATE_COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/_deps/nng/src/nng-external/etc"
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${NNG_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${NNG_BUILD_TYPE} --target install
TEST_COMMAND "" # disable test step
CMAKE_ARGS
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY}
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_EXE_LINKER_FLAGS=${NNG_CMAKE_LINKER_MANIFEST_FLAG}
-DCMAKE_POSITION_INDEPENDENT_CODE=True
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/_deps/nng-install
-DCMAKE_INSTALL_MESSAGE=LAZY # don't print out all files copied
-DCMAKE_BUILD_TYPE:STRING=${NNG_BUILD_TYPE} # for single-config generators (Ninja)
-DNNG_HAVE_GETRANDOM=False # llvm-ar fails to find symbol `getrandom` (a syscall on Linux); Requires glibc >=2.25
-DNNG_TESTS=False # don't build NNG's unit tests
EXCLUDE_FROM_ALL True
)
set(NNG_LIB_DIR ${CMAKE_BINARY_DIR}/_deps/nng-install/lib)
set(NNG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/nng-install/include)
message("NNG_LIB_DIR set to ${NNG_LIB_DIR}")
message("NNG_INCLUDE_DIR set to ${NNG_INCLUDE_DIR}")
ExternalProject_Add_Step(nng-external post-install
COMMAND ${CMAKE_COMMAND} -E echo "Packaging [nng] installed outputs to ${UE_PLUGIN_SIMLIBS_DIR}/nng/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_LIB_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/nng/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_INCLUDE_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/nng/include"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/nng/$<IF:$<CONFIG:Release>,Release,Debug>/cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/nng/$<IF:$<CONFIG:Release>,Release,Debug>/pkgconfig"
# Also copy NNG install lib to Matlab physics and control S-functions folder for building in Matlab:
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_LIB_DIR}" "${MATLAB_PHYSICS_DIR}/_deps/nng-install/lib"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_INCLUDE_DIR}" "${MATLAB_PHYSICS_DIR}/_deps/nng-install/include"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_LIB_DIR}" "${MATLAB_CONTROL_DIR}/_deps/nng-install/lib"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NNG_INCLUDE_DIR}" "${MATLAB_CONTROL_DIR}/_deps/nng-install/include"
DEPENDEES install
)
# Assimp compiler-specific flags
set(ASSIMP_EXTRA_CXX_FLAGS "")
if (MSVC)
# Assimp builds as an external project and does not inherit add_compile_options(/EHsc).
# Pass /EHsc explicitly to avoid C4530 when assimp treats warnings as errors.
set(ASSIMP_EXTRA_CXX_FLAGS "/EHsc")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
set(ASSIMP_EXTRA_CXX_FLAGS "-Wno-error=nontrivial-memcall")
endif()
# Set up dependency: assimp
message("Setting up [assimp] dependency as an external project...")
# CMake external projects don't adopt the parent's CMAKE_MSVC_RUNTIME_LIBRARY setting,
# so to force /MD non-debug CRT to match UE, build Debug config as Relwithdebinfo and
# build Release as Release.
set(ASSIMP_BUILD_TYPE $<IF:$<CONFIG:Debug>,Relwithdebinfo,Release>)
if(WIN32)
# Drop VC toolset version from library name so ProjectAirSim.Build.cs works regardless of the version of Visual Studio
set(ASSIMP_LIBRARY_SUFFIX_OVERRIDE "-DLIBRARY_SUFFIX:STRING=-mt")
else()
set(ASSIMP_LIBRARY_SUFFIX_OVERRIDE "")
endif()
ExternalProject_Add(assimp-external
GIT_REPOSITORY https://github.com/assimp/assimp.git
GIT_TAG v5.2.5
GIT_CONFIG "advice.detachedHead=false"
PREFIX ${CMAKE_BINARY_DIR}/_deps/assimp
UPDATE_COMMAND "" # disable update step
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${ASSIMP_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${ASSIMP_BUILD_TYPE} --target install
TEST_COMMAND "" # disable test step
CMAKE_ARGS
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY}
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}\ ${ASSIMP_EXTRA_CXX_FLAGS}
-DASSIMP_WARNINGS_AS_ERRORS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=True
-DBUILD_SHARED_LIBS=OFF
-DASSIMP_BUILD_ZLIB=ON # force build of assimp's packaged zlib in case it detects it existing in a python environment
-DASSIMP_BUILD_TESTS=OFF
-DASSIMP_BUILD_ASSIMP_TOOLS=OFF
${ASSIMP_LIBRARY_SUFFIX_OVERRIDE}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/_deps/assimp-install
-DCMAKE_INSTALL_MESSAGE=LAZY # don't print out all files copied
-DCMAKE_BUILD_TYPE:STRING=${ASSIMP_BUILD_TYPE} # for single-config generators (Ninja)
)
set(ASSIMP_LIB_DIR ${CMAKE_BINARY_DIR}/_deps/assimp-install/lib)
set(ASSIMP_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/assimp-install/include)
message("ASSIMP_LIB_DIR set to ${ASSIMP_LIB_DIR}")
message("ASSIMP_INCLUDE_DIR set to ${ASSIMP_INCLUDE_DIR}")
ExternalProject_Add_Step(assimp-external post-install
COMMAND ${CMAKE_COMMAND} -E echo "Packaging [assimp] installed outputs to ${UE_PLUGIN_SIMLIBS_DIR}/assimp/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ASSIMP_LIB_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/assimp/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ASSIMP_INCLUDE_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/assimp/include"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/assimp/$<IF:$<CONFIG:Release>,Release,Debug>/cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/assimp/$<IF:$<CONFIG:Release>,Release,Debug>/pkgconfig"
DEPENDEES install
)
# Set up dependency: msgpack
# "When you use msgpack on C++, you can just add msgpack-c/include to your include path"
FetchContent_Declare(
msgpack
GIT_REPOSITORY https://github.com/msgpack/msgpack-c.git
GIT_TAG cpp-6.1.0
)
FetchContent_GetProperties(msgpack)
add_definitions(-DMSGPACK_NO_BOOST)
if(NOT msgpack_POPULATED)
message("Checking if [msgpack] dependency needs to be fetched...")
FetchContent_Populate(msgpack)
# Note: msgpack is only used internally by sim libs, so no need to package it with other sim libs
# Copy msgpack headers to Matlab physics and control S-function folders for building in Matlab:
message("Packaging [msgpack] headers to ${MATLAB_PHYSICS_DIR}/msgpack")
file(COPY ${msgpack_SOURCE_DIR}/include/ DESTINATION ${MATLAB_PHYSICS_DIR}/_deps/msgpack/include)
message("Packaging [msgpack] headers to ${MATLAB_CONTROL_DIR}/msgpack")
file(COPY ${msgpack_SOURCE_DIR}/include/ DESTINATION ${MATLAB_CONTROL_DIR}/_deps/msgpack/include)
endif()
set(MSGPACK_INCLUDE_DIR ${msgpack_SOURCE_DIR}/include)
message("MSGPACK_INCLUDE_DIR set to ${MSGPACK_INCLUDE_DIR}")
# Set up dependency: Eigen3
# Using latest stable release as of from 08/18/21
find_package(Eigen3 3.4.0 QUIET NO_MODULE)
if(Eigen3_FOUND)
get_target_property(EIGEN_INCLUDE_DIR Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
message("Using system [Eigen3] dependency")
else()
if(EXISTS "/usr/include/eigen3/Eigen/Core")
set(EIGEN_INCLUDE_DIR "/usr/include/eigen3")
elseif(EXISTS "/usr/local/include/eigen3/Eigen/Core")
set(EIGEN_INCLUDE_DIR "/usr/local/include/eigen3")
endif()
if(EIGEN_INCLUDE_DIR)
message("Using local [Eigen3] headers")
else()
FetchContent_Declare(
Eigen3
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
)
FetchContent_GetProperties(Eigen3)
string(TOLOWER "Eigen3" lc_eigen)
if(NOT ${lc_eigen}_POPULATED)
message("Checking if [Eigen3] dependency needs to be fetched...")
FetchContent_Populate(Eigen3)
set(EIGEN_INCLUDE_DIR ${${lc_eigen}_SOURCE_DIR})
endif()
endif()
endif()
message("EIGEN_INCLUDE_DIR set to ${EIGEN_INCLUDE_DIR}")
message("Packaging [Eigen3] headers to ${UE_PLUGIN_SIMLIBS_DIR}/eigen")
file(COPY ${EIGEN_INCLUDE_DIR}/ DESTINATION ${UE_PLUGIN_SIMLIBS_DIR}/eigen/include)
# Set up dependency: Google Test
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
message("Checking if [GTest] dependency needs to be fetched...")
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
include(CTest) # this automatically also sets enable_testing()
# Set up dependency: tinygltf
# "When you use tinygltf on C++, you can just add to your include path since its header only library"
FetchContent_Declare(
tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.6.3
)
FetchContent_GetProperties(tinygltf)
if(NOT tinygltf_POPULATED)
message("Checking if [tinygltf] dependency needs to be fetched...")
FetchContent_Populate(tinygltf)
set(TINYGLTF_INCLUDE_DIR ${tinygltf_SOURCE_DIR})
file(REMOVE_RECURSE ${TINYGLTF_INCLUDE_DIR}/examples)
message("TINYGLTF_INCLUDE_DIR set to ${TINYGLTF_INCLUDE_DIR}")
# Note: tinygltf is only used internally by sim libs, so no need to package it with other sim libs
endif()
if(UNIX)
# Set up dependency: openssl
message("Setting up [openssl] dependency as an external project...")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OPENSSL_BUILD_TYPE debug)
else()
set(OPENSSL_BUILD_TYPE release)
endif()
# Build OpenSSL with the same compiler/sysroot as the rest of the project so that all
# glibc symbol version requirements are consistent. Use no-shared so only the static
# libraries (libcrypto.a / libssl.a) are produced, avoiding runtime dynamic-library
# glibc ABI mismatches when linking against the UE toolchain (CentOS 7 / glibc 2.17).
if(DEFINED ENV{UE_ROOT})
# UE cross-compiler targets a CentOS 7 sysroot (glibc 2.17). Tell OpenSSL to use
# the same clang and sysroot so the compiled objects only reference old glibc symbols.
set(OPENSSL_CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env
CC=${CMAKE_C_COMPILER}
"CFLAGS=--sysroot=${CMAKE_SYSROOT}"
<SOURCE_DIR>/Configure linux-x86_64
--${OPENSSL_BUILD_TYPE}
--prefix=${CMAKE_BINARY_DIR}/_deps/openssl-install
no-tests no-shared no-module
)
else()
# System toolchain: still force static-only build for consistency.
set(OPENSSL_CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env
CC=${CMAKE_C_COMPILER}
<SOURCE_DIR>/Configure
--${OPENSSL_BUILD_TYPE}
--prefix=${CMAKE_BINARY_DIR}/_deps/openssl-install
no-tests no-shared no-module
)
endif()
set(OPENSSL_LIB_DIR ${CMAKE_BINARY_DIR}/_deps/openssl-install/lib64)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIB_DIR}/libcrypto.a)
set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIB_DIR}/libssl.a)
set(OPENSSL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/openssl-install/include)
ExternalProject_Add(openssl-external
GIT_REPOSITORY https://github.com/openssl/openssl.git
GIT_TAG openssl-3.1.1
GIT_CONFIG "advice.detachedHead=false"
PREFIX ${CMAKE_BINARY_DIR}/_deps/openssl
UPDATE_COMMAND "" # disable update step
CONFIGURE_COMMAND ${OPENSSL_CONFIGURE_COMMAND}
# Build/install only static runtime + dev artifacts; avoid build_sw/install_sw
# which attempt to link provider DSOs (e.g., providers/legacy.so).
BUILD_COMMAND make build_libs
BUILD_BYPRODUCTS ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY}
INSTALL_COMMAND make install_dev
TEST_COMMAND "" # disable test step
)
message("OPENSSL_LIB_DIR set to ${OPENSSL_LIB_DIR}")
message("OPENSSL_INCLUDE_DIR set to ${OPENSSL_INCLUDE_DIR}")
ExternalProject_Add_Step(openssl-external post-install
COMMAND ${CMAKE_COMMAND} -E echo "Packaging [openssl] installed outputs to $${UE_PLUGIN_SIMLIBS_DIR}/openssl/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${OPENSSL_LIB_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/openssl/$<IF:$<CONFIG:Release>,Release,Debug>"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${OPENSSL_INCLUDE_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/openssl/include"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/openssl/$<IF:$<CONFIG:Release>,Release,Debug>/cmake"
COMMAND ${CMAKE_COMMAND} -E remove_directory "${UE_PLUGIN_SIMLIBS_DIR}/openssl/$<IF:$<CONFIG:Release>,Release,Debug>/pkgconfig"
DEPENDEES install
)
endif()
if(UNIX)
set(onnx_url https://github.com/microsoft/onnxruntime/releases/download/v1.12.1/onnxruntime-linux-x64-gpu-1.12.1.tgz)
set(onnx_hash MD5=27adfa51648d2713608f35c3c6957a4f)
message("Setting up [zlib] dependency as an external project for ONNX Runtime...")
set(ZLIB_TOOLCHAIN_CMAKE_ARGS "")
if(PROJECTAIRSIM_USE_UE_TOOLCHAIN)
list(APPEND ZLIB_TOOLCHAIN_CMAKE_ARGS
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM}
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=${CMAKE_FIND_ROOT_PATH_MODE_LIBRARY}
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE}
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}
)
endif()
set(ZLIB_BUILD_TYPE RelWithDebInfo)
set(ZLIB_BINARY_DIR ${CMAKE_BINARY_DIR}/_deps/zlib/src/zlib-external-build)
set(ZLIB_INSTALL_DIR ${CMAKE_BINARY_DIR}/_deps/zlib-install)
set(ZLIB_LIB_DIR ${ZLIB_BINARY_DIR})
set(ZLIB_INSTALL_LIB_DIR ${ZLIB_INSTALL_DIR}/lib)
set(ZLIB_SHARED_LIBRARY ${ZLIB_BINARY_DIR}/libz.so.1)
ExternalProject_Add(zlib-external
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
GIT_CONFIG "advice.detachedHead=false"
PREFIX ${CMAKE_BINARY_DIR}/_deps/zlib
UPDATE_COMMAND "" # disable update step
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${ZLIB_BUILD_TYPE}
BUILD_BYPRODUCTS ${ZLIB_SHARED_LIBRARY}
INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${ZLIB_BUILD_TYPE} --target install
TEST_COMMAND "" # disable test step
CMAKE_ARGS
${ZLIB_TOOLCHAIN_CMAKE_ARGS}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_POSITION_INDEPENDENT_CODE=True
-DBUILD_SHARED_LIBS=ON
-DCMAKE_INSTALL_PREFIX:PATH=${ZLIB_INSTALL_DIR}
-DCMAKE_INSTALL_MESSAGE=LAZY
-DCMAKE_BUILD_TYPE:STRING=${ZLIB_BUILD_TYPE}
EXCLUDE_FROM_ALL True
)
message("ZLIB_LIB_DIR set to ${ZLIB_LIB_DIR}")
ExternalProject_Add_Step(zlib-external post-install
COMMAND ${CMAKE_COMMAND} -E echo "Packaging [zlib] installed outputs to ${UE_PLUGIN_SIMLIBS_DIR}/shared_libs"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ZLIB_INSTALL_LIB_DIR}" "${UE_PLUGIN_SIMLIBS_DIR}/shared_libs"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ZLIB_INSTALL_LIB_DIR}" "${UNITY_WRAPPER_DLL_DIR}"
DEPENDEES install
)
else()
set(onnx_url https://github.com/microsoft/onnxruntime/releases/download/v1.12.1/onnxruntime-win-x64-gpu-1.12.1.zip)
set(onnx_hash MD5=dd6d6ba7aaaa58dd9ef8528dfcb822d2)
endif()
FetchContent_Declare(
onnxruntime
URL ${onnx_url}
URL_HASH ${onnx_hash} # from PowerShell: CertUtil -hashfile json.hpp MD5
DOWNLOAD_NO_PROGRESS True
DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/_deps/onnxruntime-download
)
FetchContent_GetProperties(onnxruntime)
if(NOT onnxruntime_POPULATED)
message("Checking if [onnxruntime] dependency needs to be fetched...")
FetchContent_Populate(onnxruntime)
set(ONNXRUNTIME_ROOTDIR ${onnxruntime_SOURCE_DIR})
set(ONNX_INCLUDE_DIR ${onnxruntime_SOURCE_DIR}/include)
set(ONNX_LIB_DIR ${onnxruntime_SOURCE_DIR}/lib/)
message("ONNX_INCLUDE_DIR set to ${ONNX_INCLUDE_DIR}")
message("Packaging [onnxruntime] to ${UE_PLUGIN_SIMLIBS_DIR}/shared_libs")
file(COPY "${ONNX_INCLUDE_DIR}" DESTINATION "${UE_PLUGIN_SIMLIBS_DIR}/shared_libs/onnxruntime")
file(COPY "${ONNX_LIB_DIR}" DESTINATION "${UE_PLUGIN_SIMLIBS_DIR}/shared_libs" FILES_MATCHING PATTERN "*onn*.dll" PATTERN "*onn*.lib" PATTERN "*.so*")
message("Packaging [onnxruntime] to ${UNITY_WRAPPER_DLL_DIR}")
file(COPY "${ONNX_LIB_DIR}/" DESTINATION "${UNITY_WRAPPER_DLL_DIR}/" FILES_MATCHING PATTERN "*onn*.dll" PATTERN "*onn*.lib" PATTERN "*.so*")
add_definitions(-DUSE_CUDA)
add_definitions(-DUSE_TENSORRT)
endif()
if(UNIX)
set(ONNXRUNTIME_LIBRARY "${ONNX_LIB_DIR}/libonnxruntime.so")
if(PROJECTAIRSIM_USE_UE_TOOLCHAIN)
set(ONNXRUNTIME_CXX_RUNTIME_LIBRARIES
"-Wl,--start-group"
"${CMAKE_SYSROOT}/lib64/libc++.a"
"${CMAKE_SYSROOT}/lib64/libc++abi.a"
"${CMAKE_SYSROOT}/lib64/libstdc++.so.6"
"-Wl,--end-group"
)
foreach(ONNXRUNTIME_CXX_RUNTIME_LIBRARY IN LISTS ONNXRUNTIME_CXX_RUNTIME_LIBRARIES)
if(ONNXRUNTIME_CXX_RUNTIME_LIBRARY MATCHES "^/" AND NOT EXISTS "${ONNXRUNTIME_CXX_RUNTIME_LIBRARY}")
message(FATAL_ERROR "ONNX Runtime C++ runtime dependency not found: ${ONNXRUNTIME_CXX_RUNTIME_LIBRARY}")
endif()
endforeach()
else()
set(ONNXRUNTIME_CXX_RUNTIME_LIBRARIES stdc++)
endif()
add_library(onnxruntime SHARED IMPORTED GLOBAL)
set_target_properties(onnxruntime PROPERTIES
IMPORTED_LOCATION "${ONNXRUNTIME_LIBRARY}"
INTERFACE_LINK_LIBRARIES "${ZLIB_SHARED_LIBRARY};${ONNXRUNTIME_CXX_RUNTIME_LIBRARIES};dl;rt;pthread"
INTERFACE_LINK_OPTIONS "-Wl,-rpath-link,${ZLIB_LIB_DIR}"
)
endif()
# if(WIN32)
# # Set up dependency: cesium-native
# message("Setting up [cesium-native] dependency as an external project...")
# set (CESIUM_BUILD_TYPE $<IF:$<CONFIG:Debug>,RelWithDebInfo,Release>)
# ExternalProject_Add(cesium-native
# GIT_REPOSITORY https://github.com/CesiumGS/cesium-native.git
# GIT_TAG v0.3.0
# GIT_CONFIG "advice.detachedHead=false"
# GIT_SUBMODULES_RECURSE True
# PREFIX ${CMAKE_BINARY_DIR}/_deps/cesium-native
# UPDATE_COMMAND "" # disable update step
# BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${CESIUM_BUILD_TYPE}
# INSTALL_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${CESIUM_BUILD_TYPE} --target install
# TEST_COMMAND "" # disable test step
# TEST_EXCLUDE_FROM_MAIN True
# CMAKE_ARGS
# -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
# -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
# -DCMAKE_POSITION_INDEPENDENT_CODE=True
# -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/_deps/cesium-native-install
# -DCMAKE_INSTALL_MESSAGE=LAZY # don't print out all files copied
# -DCMAKE_BUILD_TYPE:STRING=${CESIUM_BUILD_TYPE} # for single-config generators (Ninja)
# -DCMAKE_CXX_FLAGS=${CESIUM_CXX_FLAGS}
# -DCMAKE_EXE_LINKER_FLAGS=${CESIUM_LINKER_FLAGS}
# )
# set(CESIUM_LIB_DIR ${CMAKE_BINARY_DIR}/_deps/cesium-native-install/lib)
# set(CESIUM_INCLUDE_DIR ${CMAKE_BINARY_DIR}/_deps/cesium-native-install/include)
# set(CESIUM_PLUGIN_THIRDPARTY_DIR ${CMAKE_SOURCE_DIR}/unreal/Blocks/Plugins/CesiumForUnreal/Source/ThirdParty)
# message("CESIUM_LIB_DIR set to ${CESIUM_LIB_DIR}")
# message("CESIUM_INCLUDE_DIR set to ${CESIUM_INCLUDE_DIR}")
# ExternalProject_Add_Step(cesium-native post-install
# COMMAND ${CMAKE_COMMAND} -E echo "Packaging [cesium-native] installed outputs to ${SIMLIBS_PACKAGE_DIR}/cesium-native/$<IF:$<CONFIG:Release>,Release,Debug>"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${CESIUM_LIB_DIR}" "${SIMLIBS_PACKAGE_DIR}/cesium-native/$<IF:$<CONFIG:Release>,Release,Debug>"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${CESIUM_INCLUDE_DIR}" "${SIMLIBS_PACKAGE_DIR}/cesium-native/include"
# COMMAND ${CMAKE_COMMAND} -E remove_directory "${SIMLIBS_PACKAGE_DIR}/cesium-native/$<IF:$<CONFIG:Release>,Release,Debug>/cmake"
# COMMAND ${CMAKE_COMMAND} -E remove_directory "${SIMLIBS_PACKAGE_DIR}/cesium-native/$<IF:$<CONFIG:Release>,Release,Debug>/pkgconfig"
# COMMAND ${CMAKE_COMMAND} -E echo "Packaging [cesium-native] installed outputs to ${CESIUM_PLUGIN_THIRDPARTY_DIR}"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${SIMLIBS_PACKAGE_DIR}/cesium-native/$<IF:$<CONFIG:Release>,Release,Debug>" "${CESIUM_PLUGIN_THIRDPARTY_DIR}/lib/$<IF:$<CONFIG:Release>,Release,Debug>"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${SIMLIBS_PACKAGE_DIR}/cesium-native/include" "${CESIUM_PLUGIN_THIRDPARTY_DIR}/include"
# COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/_deps/cesium-native/src/cesium-native/extern/stb/stb_image_resize.h" "${CESIUM_PLUGIN_THIRDPARTY_DIR}/include"
# DEPENDEES install
# )
# endif()
# Add sub-projects
add_subdirectory(core_sim)
add_subdirectory(simserver)
add_subdirectory(samples)
add_subdirectory(physics)
add_subdirectory(mavlinkcom)
add_subdirectory(rendering)
add_subdirectory(tools)
add_subdirectory(unity)
add_subdirectory(vehicle_apis)
if(BUILD_TESTING)
set(SIMLIBS_UNIT_TEST_TARGETS
core_sim_gtests
physics_gtests
rendering_scene_gtests
multirotor_api_gtests
rover_api_gtests
)
if(WIN32)
list(APPEND SIMLIBS_UNIT_TEST_TARGETS MavLinkTest)
endif()
add_custom_target(simlibs_unit_tests)
foreach(TEST_TARGET ${SIMLIBS_UNIT_TEST_TARGETS})
if(TARGET ${TEST_TARGET})
add_dependencies(simlibs_unit_tests ${TEST_TARGET})
endif()
endforeach()
endif()