-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
429 lines (395 loc) · 15.1 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
#
# Copyright (c) 2019 Arnaud Loonstra.
#
# License MPLv2
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
cmake_minimum_required(VERSION 3.13)
project(gazebosc)
if(NOT ARCH)
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(ARCH 64)
else()
set(ARCH 32)
endif()
endif()
message(STATUS "Compilation set for ${ARCH}bits architectures.")
set(CMAKE_CXX_STANDARD 17)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/dist/cmake")
## Test availability of git and fetch submodules if needed
find_package(Git QUIET)
#if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# # Update submodules as needed
# option(GIT_SUBMODULE "Check submodules during build" ON)
# if(GIT_SUBMODULE)
# message(STATUS "Submodule update")
# execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE GIT_SUBMOD_RESULT)
# if(NOT GIT_SUBMOD_RESULT EQUAL "0")
# message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
# endif()
# endif()
#endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/ext/czmq/CMakeLists.txt")
message(FATAL_ERROR "The submodules in the ext directory are not available! GIT_SUBMODULE was turned off or failed. Please update submodules using \"git submodule update --init --recursive\" and try again.")
endif()
## End getting the submodules
### SET OPTIONS
option (WITH_DEV "Enable running from an IDE" ON)
option (WITH_UNWIND "Enable libunwind support" ON)
option (WITH_IMGUI_DEMO "Enable ImGUI demo console" ON)
option (WITH_EMBED_PYTHON "Embed the python interpreter, otherwise use system installed" OFF)
option (WITH_OPENVR "Enable OpenVR support" ON)
option (WITH_DMX "Enable DMX support" ON)
option (RPI "Build for the Raspberry PI" OFF)
### END SET OPTIONS
### EXTERNAL LIBS
# Definitions for draft API's of submodules
set(ENABLE_DRAFTS ON CACHE BOOL "enable zmq projects draft apis" FORCE)
add_definitions(-DZMQ_BUILD_DRAFT_API=1)
add_definitions(-DCZMQ_BUILD_DRAFT_API=1)
# External libraries in ext/
add_subdirectory("ext/czmq" EXCLUDE_FROM_ALL)
# overrides to prevent the Findczmq.cmake script to fail
set(czmq_LIBRARIES czmq-static)
set(czmq_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/ext/czmq/include/)
add_subdirectory("ext/libsphactor" EXCLUDE_FROM_ALL)
add_subdirectory("ext/SDL" EXCLUDE_FROM_ALL)
add_subdirectory("ext/glm" EXCLUDE_FROM_ALL)
set( RTMIDI_TARGETNAME_UNINSTALL "rtmidi_uninstall" CACHE STRING "Name of 'uninstall' build target")
set( RTMIDI_BUILD_SHARED_LIBS "")
set( RTMIDI_BUILD_STATIC_LIBS "#" )
add_subdirectory("ext/rtmidi" EXCLUDE_FROM_ALL)
# Test for RPI
# We can check if the bcm_host.h exists
# include(CheckIncludeFile)
# CHECK_INCLUDE_FILE(/opt/vc/include/bcm_host.h RPI) # doesn't work :S
# Just check if the file is there
if (RPI)
message(STATUS "Enabling building for the Raspberry Pi")
add_definitions(-DIMGUI_IMPL_OPENGL_ES2)
set(WITH_OPENVR "OFF")
endif(RPI)
# External system libraries through find_package
find_package(libzmq REQUIRED)
if (NOT libzmq_FOUND)
message (FATAL_ERROR "Cannot find libzmq, make sure it is available on the system")
endif()
if(WIN32 AND WITH_EMBED_PYTHON)
set(Python3_ROOT_DIR "${PROJECT_SOURCE_DIR}/build/python")
endif(WIN32 AND WITH_EMBED_PYTHON)
if(Python3_ROOT_DIR) # Usually specified on command line to find python explicitly
set(CMAKE_FIND_USE_CMAKE_PATH FALSE)
set(Python3_FIND_STRATEGY "LOCATION")
set(Python3_FIND_REGISTRY NEVER)
set(Python3_USE_STATIC_LIBS TRUE)
set(Python3_FIND_FRAMEWORK NEVER)
endif(Python3_ROOT_DIR)
if(APPLE AND Python3_ROOT_DIR)
find_package (Python3 3.9 EXACT COMPONENTS Interpreter Development REQUIRED)
else(APPLE AND Python3_ROOT_DIR)
find_package (Python3 COMPONENTS Development REQUIRED)
endif(APPLE AND Python3_ROOT_DIR)
if(Python3_FOUND)
message ("python3 found libs: ${Python3_LIBRARIES} incl: ${Python3_INCLUDE_DIRS}")
add_definitions(-DPYTHON3_FOUND)
else()
message (FATAL_ERROR "Cannot find Python3, make sure the development packages of Python are available on the system. ROOT_DIR=${Python3_ROOT_DIR}")
endif()
if (WITH_UNWIND)
find_package (Unwind)
endif (WITH_UNWIND)
if (Unwind_FOUND)
add_definitions(-DHAVE_LIBUNWIND)
set (HAVE_LIBUNWIND 1)
set (HAVE_UNWIND_H 1)
endif (Unwind_FOUND)
if (WITH_IMGUI_DEMO)
add_definitions(-DHAVE_IMGUI_DEMO)
endif (WITH_IMGUI_DEMO)
if (WITH_OPENVR)
if (WIN32)
set(WINDOWS_PATH_SUFFIXES win${ARCH} Win${ARCH} x${ARCH})
endif(WIN32)
## OpenVR API path
find_library(OPENVR_LIBRARIES
NAMES
openvr_api
PATHS
${CMAKE_SOURCE_DIR}/ext/openvr/bin
${CMAKE_SOURCE_DIR}/ext/openvr/lib
PATH_SUFFIXES
osx32
linux64
${WINDOWS_PATH_SUFFIXES}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
set(OPENVR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ext/openvr/headers)
add_definitions(-DHAVE_OPENVR)
message("Found OpenVR at ${OPENVR_LIBRARIES}")
endif(WITH_OPENVR)
if(WITH_DMX)
add_definitions(-DHAVE_DMX)
endif(WITH_DMX)
### PROJECT SOURCES
file (GLOB ACTOR_SOURCES CONFIGURE_DEPENDS actors/*.h actors/*.c actors/*.cpp actors/*.hpp)
# get git version
include(GitVersion)
message(STATUS "GIT_REPO_VERSION=${GIT_REPO_VERSION} VERSION_MAJOR=${VERSION_MAJOR} VERSION_MINOR=${VERSION_MINOR} VERSION_PATCH=${VERSION_PATCH} GIT_HASH=${GIT_HASH}")
# create config.h
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) # this is not run every build
add_custom_command(
OUTPUT config.h
COMMAND ${CMAKE_COMMAND}
-D GIT_REPO_VERSION=${GIT_REPO_VERSION}
-D GIT_HASH=${GIT_HASH}
-D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/config.h.in
-D OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/config.h
-P ${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/Configure.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/config.h.in
VERBATIM
)
list(APPEND GZB_SOURCES
main.cpp
ImNodes.cpp
ImNodesEz.cpp
helpers.h
helpers.c
app/App.hpp
app/Window.hpp
app/TextEditorWindow.hpp
app/TextEditorWindow.cpp
app/StageWindow.hpp
app/StageWindow.cpp
app/AboutWindow.hpp
app/AboutWindow.cpp
app/LogWindow.hpp
app/PyWindow.hpp
app/DemoWindow.hpp
app/ActorContainer.hpp
app/ActorContainer.cpp
ext/imgui/backends/imgui_impl_opengl3.cpp
ext/imgui/backends/imgui_impl_sdl2.cpp
ext/imgui/imconfig.h
ext/imgui/imgui.h
ext/imgui/imgui.cpp
ext/imgui/imgui_draw.cpp
ext/imgui/imgui_widgets.cpp
ext/imgui/imgui_tables.cpp
ext/imgui/imgui_demo.cpp
ext/ImFileDialog/ImFileDialog.h
ext/ImFileDialog/ImFileDialog.cpp
ext/ImGuiColorTextEdit/LanguageDefinitions.cpp
ext/ImGuiColorTextEdit/TextEditor.cpp
${ACTOR_SOURCES}
)
list(APPEND GZB_INCLUDEDIRS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${Unwind_INCLUDE_DIRS}
${OPENVR_INCLUDE_DIR}
${libzmq_INCLUDE_DIRS}
${Python3_INCLUDE_DIRS}
ext/
ext/ImGuiColorTextEdit
ext/imgui
ext/imgui/backends
)
if(WIN32)
list(APPEND GZB_SOURCES
ext/StackWalker/Main/StackWalker/StackWalker.h
ext/StackWalker/Main/StackWalker/StackWalker.cpp
)
list(APPEND GZB_INCLUDEDIRS
ext/StackWalker/Main/StackWalker/
ext/ImGui-Addons/FileBrowser/
)
endif(WIN32)
if (UNIX)
link_directories(
/usr/local/lib/
)
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${GZB_SOURCES})
add_executable(gazebosc
config.h
${GZB_SOURCES}
)
target_include_directories(gazebosc PUBLIC
${GZB_INCLUDEDIRS}
)
### BUILD OPTIONS
if (Unwind_FOUND)
target_link_libraries (gazebosc PUBLIC unwind::unwind)
endif (Unwind_FOUND)
target_link_options(gazebosc PUBLIC ${Python3_LINK_OPTIONS})
target_compile_options(gazebosc PUBLIC ${SDL2_CFLAGS_OTHER} )
target_compile_definitions(gazebosc PUBLIC -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=0)
set(RESOURCE_DEST "./")
set(RUNTIME_DEST "bin")
set(APPS "bin/gazebosc")
set(LIBS )
set(DIRS "${CMAKE_BINARY_DIR}")
### PLATFORM SPECIFICS
if (APPLE)
set(APPS "gazebosc.app")
set(RESOURCE_DEST "gazebosc.app/Contents/Resources")
set(APPLE_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/dist/osx/Entitlements.plist)
list(APPEND DIRS "${CMAKE_CURRENT_SOURCE_DIR}/ext/openvr/bin/osx32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-check")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-check")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/dist/osx/Info.plist.in" "${CMAKE_CURRENT_BINARY_DIR}/Info.plist" @ONLY)
set_target_properties(gazebosc PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME gazebosc
MACOSX_BUNDLE_COPYRIGHT "Gazebosc is licensed under the MPLv2 License"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.sphactor.Gazebosc"
MACOSX_BUNDLE_ICON_FILE "AppIcon.icns"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist"
RESOURCE_DEST "${RESOURCE_DEST}"
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${APPLE_ENTITLEMENTS}"
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Manual"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-"
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED TRUE
XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "--timestamp=http://timestamp.apple.com/ts01 --options=runtime,library"
XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS "NO"
)
add_definitions(-D__MACOSX_CORE__)
target_link_libraries(gazebosc PUBLIC
SDL2-static
sphactor-static
rtmidi
${OPENVR_LIBRARIES}
${Python3_LIBRARIES}
-ldl "-framework OpenGL" "-framework CoreFoundation" "-framework CoreMidi" "-framework CoreAudio")
# This is handled by fixup_bundle as well but it doesn't copy all required files
if (WITH_EMBED_PYTHON)
# copy embedded python to the bundle but exclude exe_with_* files as it kills fixup_bundle
install(DIRECTORY ${Python3_ROOT_DIR}/ DESTINATION ${RESOURCE_DEST}/python/
USE_SOURCE_PERMISSIONS
COMPONENT Runtime
PATTERN exe_with_* EXCLUDE
)
endif(WITH_EMBED_PYTHON)
elseif (WIN32)
set(RUNTIME_DEST "./")
set(APPS "gazebosc.exe")
if (MSVC)
string(REGEX REPLACE "/" "\\\\" VS_DEBUGGER_BACKSLASH "${CMAKE_BINARY_DIR}/bin/Debug/")
set_property(TARGET gazebosc PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${VS_DEBUGGER_BACKSLASH}")
endif()
list(APPEND DIRS "${CMAKE_CURRENT_SOURCE_DIR}/ext/openvr/bin/win64")
target_link_libraries(gazebosc PUBLIC
SDL2-static
czmq-static
sphactor-static
rtmidi
${OPENVR_LIBRARIES}
${libzmq_LIBRARIES}
${Python3_LIBRARIES}
opengl32.lib DbgHelp.lib)
if (WITH_EMBED_PYTHON)
# copy embedded python, we force binary_dir/python just because :S
install(DIRECTORY ${CMAKE_BINARY_DIR}/python DESTINATION ${RESOURCE_DEST}
USE_SOURCE_PERMISSIONS
COMPONENT Runtime
PATTERN exe_with_* EXCLUDE
)
endif(WITH_EMBED_PYTHON)
elseif (RPI)
target_link_libraries(gazebosc PUBLIC
SDL2-static
sphactor-static
rtmidi
${Python3_LIBRARIES}
-lasound -ldl -lGLESv2)
target_compile_options(gazebosc PUBLIC -D__LINUX_ALSA__ )
else()
list(APPEND DIRS "${CMAKE_CURRENT_SOURCE_DIR}/ext/openvr/bin/linux64")
target_link_libraries(gazebosc PUBLIC
SDL2-static
sphactor-static
rtmidi
${OPENVR_LIBRARIES}
${Python3_LIBRARIES}
-lasound -ldl -lGL -lGLEW)
target_compile_options(gazebosc PUBLIC -D__LINUX_ALSA__ )
endif()
# This is just for running the binary from an ide
if (WITH_DEV)
if (APPLE)
add_custom_command(
TARGET gazebosc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/misc
$<TARGET_FILE_DIR:${PROJECT_NAME}>/../Resources/misc)
else()
add_custom_command(
TARGET gazebosc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/misc
$<TARGET_FILE_DIR:${PROJECT_NAME}>/misc)
endif()
endif(WITH_DEV)
install(TARGETS gazebosc
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION ${RUNTIME_DEST} COMPONENT Runtime
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/misc
DESTINATION ${RESOURCE_DEST}
COMPONENT Runtime)
### POST BUILD/INSTALL
# Path used for searching by FIND_XXX(), with appropriate suffixes added
if(CMAKE_PREFIX_PATH)
foreach(dir ${CMAKE_PREFIX_PATH})
list(APPEND DIRS "${dir}" "${dir}/bin" "${dir}/lib")
endforeach()
endif()
install(CODE "
include(InstallRequiredSystemLibraries)
include(BundleUtilities)
include(${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/CodeSign.cmake)
set(BU_CHMOD_BUNDLE_ITEMS TRUE) # https://gitlab.kitware.com/cmake/cmake/-/issues/19663
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${APPS}\" \"${LIBS}\" \"${DIRS}\" IGNORE_ITEM \"exe_with_z64;exe_with_zip\")
bundlesign(\"\${CMAKE_INSTALL_PREFIX}/${APPS}\" ${APPLE_ENTITLEMENTS})"
COMPONENT Runtime
)
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} CMAKE_HOST_SYSTEM_NAME)
set(CPACK_GENERATOR "ZIP")
set(PLATFORMID "${CMAKE_HOST_SYSTEM_NAME}")
if(APPLE)
set(CPACK_GENERATOR "DragNDrop")
if (CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "")
set(PLATFORMID "OSX")
else()
set(PLATFORMID "OSX_${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
set(CPACK_BUNDLE_NAME "gazebosc")
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
set(CPACK_BUNDLE_ICON "AppIcon.icns")
# The name of your Apple supplied code signing certificate for the application. The name usually takes the form Developer ID Application: [Name] or 3rd Party Mac Developer Application: [Name]. If this variable is not set the application will not be signed.
set(CPACK_BUNDLE_APPLE_CERT_APP "-")
set(CPACK_BUNDLE_APPLE_ENTITLEMENTS ${APPLE_ENTITLEMENTS})
#set(CPACK_POST_BUILD_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/dist/cmake/DmgSign.cmake")
endif()
message(WARN "Platform id: ${PLATFORMID}")
set(CPACK_VERBATIM_VARIABLES true)
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_NAME "Gazebosc")
set(CPACK_PACKAGE_VENDOR "HKU")
set(CPACK_PACKAGE_FILE_NAME "gazebosc_${PLATFORMID}_${GIT_REPO_VERSION}")
#set(CPACK_PACKAGE_ICON "${ICON_TARGET}")
include(CPack)