-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathCMakeLists.txt
319 lines (281 loc) · 8.93 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
add_subdirectory(rendering)
add_subdirectory(gui)
add_subdirectory(systems)
file(GLOB gz_msgs_proto_files
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/sim/private_msgs/*.proto
)
get_target_property(msgs_desc_file
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER} GZ_MSGS_DESC_FILE)
gz_msgs_generate_messages_impl(
MSGS_GEN_SCRIPT
${gz-msgs10_PROTO_GENERATOR_SCRIPT}
FACTORY_GEN_SCRIPT
${gz-msgs10_FACTORY_GENERATOR_SCRIPT}
GZ_PROTOC_PLUGIN
${gz-msgs10_PROTO_GENERATOR_PLUGIN}
INPUT_PROTOS
${gz_msgs_proto_files}
PROTO_PACKAGE
"gz.sim.private_msgs"
PROTO_PATH
${CMAKE_CURRENT_SOURCE_DIR}/proto
OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/gz_msgs_gen
OUTPUT_SOURCES
msgs_sources
OUTPUT_HEADERS
msgs_headers
OUTPUT_DETAIL_HEADERS
msgs_detail_headers
OUTPUT_PYTHON
msgs_python
DEPENDENCY_DESCRIPTIONS ${msgs_desc_file}
)
set(network_sources
network/NetworkConfig.cc
network/NetworkManager.cc
network/NetworkManagerPrimary.cc
network/NetworkManagerSecondary.cc
network/PeerInfo.cc
network/PeerTracker.cc
)
set(comms_sources
comms/Broker.cc
comms/ICommsModel.cc
comms/MsgManager.cc
)
set(gui_sources
${gui_sources}
PARENT_SCOPE
)
set(cli_sources
gz.cc
cmd/ModelCommandAPI.cc
)
set(material_sources
rendering/MaterialParser/MaterialParser.cc
rendering/MaterialParser/ConfigLoader.cc
)
set (sources
Actor.cc
Barrier.cc
BaseView.cc
Conversions.cc
ComponentFactory.cc
EntityComponentManager.cc
EntityComponentManagerDiff.cc
InstallationDirectories.cc
Joint.cc
LevelManager.cc
Light.cc
Link.cc
MeshInertiaCalculator.cc
Model.cc
Primitives.cc
SdfEntityCreator.cc
SdfGenerator.cc
Sensor.cc
Server.cc
ServerConfig.cc
ServerPrivate.cc
SimulationRunner.cc
SystemLoader.cc
SystemManager.cc
TestFixture.cc
Util.cc
View.cc
World.cc
${network_sources}
${comms_sources}
${msgs_sources}
${material_sources}
)
set (gtest_sources
${gtest_sources}
Actor_TEST.cc
AddedMass_TEST.cc
Barrier_TEST.cc
BaseView_TEST.cc
ComponentFactory_TEST.cc
Component_TEST.cc
Conversions_TEST.cc
EntityComponentManager_TEST.cc
EventManager_TEST.cc
Joint_TEST.cc
Light_TEST.cc
Link_TEST.cc
Model_TEST.cc
Primitives_TEST.cc
SdfEntityCreator_TEST.cc
SdfGenerator_TEST.cc
Sensor_TEST.cc
ServerConfig_TEST.cc
Server_TEST.cc
SimulationRunner_TEST.cc
SystemLoader_TEST.cc
SystemManager_TEST.cc
TestFixture_TEST.cc
Util_TEST.cc
World_TEST.cc
comms/Broker_TEST.cc
comms/MsgManager_TEST.cc
network/NetworkConfig_TEST.cc
network/PeerTracker_TEST.cc
network/NetworkManager_TEST.cc
)
# gz_TEST and ModelCommandAPI_TEST are not supported with multi config
# CMake generators, see also cmd/CMakeLists.txt
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND gtest_sources gz_TEST.cc)
endif()
# Tests that require a valid display
set(tests_needing_display
Server_Rendering_TEST.cc
)
if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND tests_needing_display ModelCommandAPI_TEST.cc)
endif()
# Add systems that need a valid display here.
# \todo(anyone) Find a way to run these tests with a virtual display such Xvfb
# or Xdummy instead of skipping them
if(VALID_DISPLAY AND VALID_DRI_DISPLAY)
list(APPEND gtest_sources ${tests_needing_display})
else()
message(STATUS
"Skipping these UNIT tests because a valid display was not found:")
foreach(test ${tests_needing_display})
message(STATUS " ${test}")
endforeach(test)
endif()
if (MSVC)
# Warning #4251 is the "dll-interface" warning that tells you when types used
# by a class are not being exported. These generated source files have private
# members that don't get exported, so they trigger this warning. However, the
# warning is not important since those members do not need to be interfaced
# with.
set_source_files_properties(${sources} ${gtest_sources} ${cli_sources} COMPILE_FLAGS "/wd4251 /wd4146")
endif()
# CLI
gz_add_component(gz
SOURCES
${cli_sources}
GET_TARGET_NAME gz_lib_target)
target_link_libraries(${gz_lib_target}
PUBLIC
${PROJECT_LIBRARY_TARGET_NAME}
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-sim${PROJECT_VERSION_MAJOR}
gz-sim${PROJECT_VERSION_MAJOR}-gui
)
# Executable target that runs the GUI without ruby for debugging purposes.
add_executable(runGui cmd/runGui_main.cc)
target_link_libraries(runGui PRIVATE ${gz_lib_target})
# Create the library target
gz_create_core_library(SOURCES ${sources} CXX_STANDARD 17)
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION gz::sim::getInstallPrefix
GET_INSTALL_PREFIX_HEADER gz/sim/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GZ_SIM_INSTALL_PREFIX)
set_property(
SOURCE InstallationDirectories.cc
PROPERTY COMPILE_DEFINITIONS
GZ_SIM_GUI_CONFIG_RELATIVE_PATH="${GZ_DATA_INSTALL_DIR}/gui"
GZ_SIM_SYSTEM_CONFIG_RELATIVE_PATH="${GZ_DATA_INSTALL_DIR}/systems"
GZ_SIM_SERVER_CONFIG_RELATIVE_PATH="${GZ_DATA_INSTALL_DIR}"
GZ_SIM_PLUGIN_RELATIVE_INSTALL_DIR="${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
GZ_SIM_GUI_PLUGIN_RELATIVE_INSTALL_DIR="${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/gui"
GZ_SIM_WORLD_RELATIVE_INSTALL_DIR="${GZ_DATA_INSTALL_DIR}/worlds"
GZ_SIM_MEDIA_RELATIVE_INSTALL_DIR="${GZ_DATA_INSTALL_DIR}/media"
)
install(FILES "rendering/MaterialParser/gazebo.material" DESTINATION ${GZ_DATA_INSTALL_DIR}/media)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
gz-math${GZ_MATH_VER}
gz-plugin${GZ_PLUGIN_VER}::core
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
gz-common${GZ_COMMON_VER}::graphics
gz-common${GZ_COMMON_VER}::profiler
gz-fuel_tools${GZ_FUEL_TOOLS_VER}::gz-fuel_tools${GZ_FUEL_TOOLS_VER}
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
gz-physics${GZ_PHYSICS_VER}::core
gz-rendering${GZ_RENDERING_VER}::core
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
gz-transport${GZ_TRANSPORT_VER}::parameters
sdformat${SDF_VER}::sdformat${SDF_VER}
protobuf::libprotobuf
PRIVATE
gz-plugin${GZ_PLUGIN_VER}::loader
)
if (pybind11_FOUND)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE pybind11::embed)
target_compile_definitions(${PROJECT_LIBRARY_TARGET_NAME} PUBLIC -DHAVE_PYBIND11)
endif()
if (UNIX AND NOT APPLE)
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PRIVATE stdc++fs)
endif()
target_include_directories(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/gz_msgs_gen>
)
include_directories(${PROJECT_SOURCE_DIR}/test)
# Build the unit tests
gz_build_tests(TYPE UNIT
SOURCES
${gtest_sources}
LIB_DEPS
${PROJECT_LIBRARY_TARGET_NAME}
${EXTRA_TEST_LIB_DEPS}
gz-sim${PROJECT_VERSION_MAJOR}
ENVIRONMENT
GZ_SIM_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
# Some server unit tests require rendering.
if (TARGET UNIT_Server_Rendering_TEST)
target_link_libraries(UNIT_Server_Rendering_TEST
gz-rendering${GZ_RENDERING_VER}::gz-rendering${GZ_RENDERING_VER}
)
endif()
# Command line tests need extra settings
foreach(CMD_TEST
UNIT_gz_TEST
UNIT_ModelCommandAPI_TEST)
if(NOT TARGET ${CMD_TEST})
continue()
endif()
# Running `gz sim` on macOS has problems when run with /usr/bin/ruby
# due to System Integrity Protection (SIP). Try to find ruby from
# homebrew as a workaround.
if (APPLE)
find_program(BREW_RUBY ruby HINTS /usr/local/opt/ruby/bin)
endif()
add_dependencies(${CMD_TEST}
${gz_lib_target}
TestModelSystem
TestSensorSystem
TestWorldSystem
)
target_compile_definitions(${CMD_TEST} PRIVATE
"BREW_RUBY=\"${BREW_RUBY} \"")
target_compile_definitions(${CMD_TEST} PRIVATE
"GZ_PATH=\"${GZ_TOOLS_PROGRAM}\"")
set(_env_vars)
list(APPEND _env_vars "GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf")
list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:TestModelSystem>")
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT "${_env_vars}")
# On Windows there is no RPATH, so an alternative way for tests for finding .dll libraries
# in build directory in necessary. For regular tests, the trick is to place all libraries
# and executables in a common CMAKE_RUNTIME_OUTPUT_DIRECTORY, so that the .dll are found
# as they are in the same directory where the executable is loaded. For tests that are
# launched via Ruby, this does not work, so we need to manually add CMAKE_RUNTIME_OUTPUT_DIRECTORY
# to the PATH. This is done via the ENVIRONMENT_MODIFICATION that is only available
# since CMake 3.22. However, if an older CMake is used another trick to install the libraries
# beforehand
if (WIN32 AND CMAKE_VERSION STRGREATER "3.22")
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()
endforeach()
add_subdirectory(cmd)