forked from harfang3d/harfang3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
418 lines (361 loc) · 15.5 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
function(install_cppsdk_external_target TARGET)
if(NOT HG_BUILD_CPP_SDK)
return()
endif()
if (DEFINED ARGV1)
set(TargetHeaderPath ${ARGV1})
else()
set(TargetHeaderPath ${TARGET})
endif()
get_target_property(TargetType ${TARGET} TYPE)
if ((TargetType STREQUAL "STATIC_LIBRARY") OR MSVC)
set(LibraryDestination ${CppSdkLibraryDestination})
else()
set(LibraryDestination ${CppSdkRuntimeDestination})
endif()
install(
TARGETS ${TARGET}
EXPORT cppsdkTargets
COMPONENT cppsdk
PUBLIC_HEADER DESTINATION ${CppSdkHeadersDestination}/extern/${TargetHeaderPath}
ARCHIVE DESTINATION ${CppSdkLibraryDestination}
LIBRARY DESTINATION ${LibraryDestination}
RUNTIME DESTINATION ${CppSdkRuntimeDestination}
INCLUDES DESTINATION ${CppSdkHeadersDestination}/extern
)
endfunction(install_cppsdk_external_target)
# glfw
if(HG_USE_GLFW)
# determine glfw backend (as we do not have access to glfw_config.h).
if(GLFW_USE_WAYLAND)
set(HG_GLFW_BACKEND "WAYLAND")
elseif (WIN32)
set(HG_GLFW_BACKEND "WIN32")
elseif (APPLE)
set(HG_GLFW_BACKEND "COCOA")
elseif (UNIX)
set(HG_GLFW_BACKEND "X11")
else ()
message(ERROR "GLFW: unknown or unsupported backed")
endif()
set(HG_GLFW_BACKEND ${HG_GLFW_BACKEND} PARENT_SCOPE)
if(NOT DEFINED HG_REBUILD_GLFW)
set(HG_REBUILD_GLFW ON)
endif()
if(NOT HG_REBUILD_GLFW)
# use system package
find_package(glfw3 3.2)
if(glfw3_FOUND)
# check that we are using the shared library version
get_target_property(glfw_target_type glfw TYPE)
if(glfw_target_type STREQUAL "SHARED_LIBRARY")
set_target_properties(glfw PROPERTIES IMPORTED_GLOBAL TRUE)
# we set the corresponding compile definition. This define will be exported in the CMake configuration files.
target_compile_definitions(glfw INTERFACE GLFW_${HG_GLFW_BACKEND}=1)
else()
message(WARNING "Only the dynamic library version of GLFW is allowed")
set(HG_REBUILD_GLFW ON)
endif()
else()
message(WARNING "GLFW was not found")
set(HG_REBUILD_GLFW ON)
endif()
endif()
if(HG_REBUILD_GLFW)
# build it from sources
if(HG_BUILD_HARFANG_STATIC)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
else()
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE)
endif()
set(GLFW_INSTALL OFF CACHE BOOL "")
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "")
add_subdirectory(glfw EXCLUDE_FROM_ALL)
# here we completly hijack glfw shared library output name.
# on *nix we don't want all the so names with versions (libgflw.so.3 libglfw.so.3.x etc...)
set_property(TARGET glfw PROPERTY VERSION)
set_property(TARGET glfw PROPERTY SOVERSION)
set_property(TARGET glfw PROPERTY OUTPUT_NAME glfw3)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
install_cppsdk_external_target(glfw)
set_target_properties(glfw PROPERTIES FOLDER "harfang/3rdparty")
set_target_properties(glfw PROPERTIES
INCLUDE_DIRECTORIES
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/glfw/include>;${CMAKE_CURRENT_SOURCE_DIR}/glfw/src;${CMAKE_CURRENT_BINARY_DIR}/glfw/src"
INTERFACE_INCLUDE_DIRECTORIES
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/glfw/include>"
)
# we set the corresponding compile definition. This define will be exported in the CMake configuration files.
target_compile_definitions(glfw PUBLIC GLFW_${HG_GLFW_BACKEND}=1)
endif()
set(HG_REBUILD_GLFW ${HG_REBUILD_GLFW} PARENT_SCOPE)
else()
set(HG_GLFW_BACKEND "NONE" PARENT_SCOPE)
endif()
# miniz
add_library(miniz STATIC miniz/miniz.c miniz/miniz.h)
set_target_properties(miniz PROPERTIES FOLDER "harfang/3rdparty")
target_include_directories(miniz PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/miniz> )
install_cppsdk_external_target(miniz)
# bgfx
add_subdirectory(bgfx EXCLUDE_FROM_ALL)
install_cppsdk_external_target(bx)
install_cppsdk_external_target(bimg)
install_cppsdk_external_target(bgfx)
install_cppsdk_external_target(astc-codec)
install_cppsdk_external_target(astc)
install_cppsdk_external_target(edtaa3)
install_cppsdk_external_target(etc1)
install_cppsdk_external_target(etc2)
install_cppsdk_external_target(iqa)
install_cppsdk_external_target(squish)
install_cppsdk_external_target(nvtt)
install_cppsdk_external_target(pvrtc)
# Lua
if(UNIX AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
# lua links against libreadline but does not check for its availability.
find_package(readline REQUIRED)
endif()
add_subdirectory(lua EXCLUDE_FROM_ALL)
set_property(TARGET lua luac liblua libluadll PROPERTY FOLDER "harfang/3rdparty/lua")
if(HG_BUILD_CPP_SDK)
set_target_properties(libluadll PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/lua/src/lua.h;${CMAKE_CURRENT_SOURCE_DIR}/lua/src/luaconf.h;${CMAKE_CURRENT_SOURCE_DIR}/lua/src/lualib.h;${CMAKE_CURRENT_SOURCE_DIR}/lua/src/lauxlib.h;${CMAKE_CURRENT_SOURCE_DIR}/lua/src/lua.hpp")
endif()
target_include_directories(libluadll PUBLIC $<INSTALL_INTERFACE:${CppSdkHeadersDestination}/extern/lua>)
install_cppsdk_external_target(libluadll lua)
# STB vorbis (customized to handle raw VORBIS stream)
add_library(stb_vorbis STATIC stb_vorbis/stb_vorbis.c)
set_target_properties(stb_vorbis PROPERTIES FOLDER "harfang/3rdparty")
target_compile_definitions(stb_vorbis PUBLIC STB_VORBIS_NO_STDIO=1)
target_include_directories(stb_vorbis PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/stb_vorbis>)
install_cppsdk_external_target(stb_vorbis)
# STB truetype
add_library(stb_truetype STATIC stb_truetype/stb_truetype.c stb_truetype/stb_truetype.h)
target_include_directories(stb_truetype PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/stb_truetype>)
set_target_properties(stb_truetype PROPERTIES FOLDER "harfang/3rdparty")
install_cppsdk_external_target(stb_truetype)
# STB image write
add_library(stb_image_write STATIC stb_image/stb_image_write.c stb_image/stb_image_write.h)
target_include_directories(stb_image_write PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/stb_image>)
set_target_properties(stb_image_write PROPERTIES FOLDER "harfang/3rdparty")
install_cppsdk_external_target(stb_image_write)
# Bullet 3
if(HG_ENABLE_BULLET3_SCENE_PHYSICS)
add_subdirectory(bullet3 EXCLUDE_FROM_ALL)
set_target_properties(BulletDynamics PROPERTIES FOLDER "harfang/3rdparty/bullet3")
set_target_properties(BulletCollision PROPERTIES FOLDER "harfang/3rdparty/bullet3")
set_target_properties(BulletCommon PROPERTIES FOLDER "harfang/3rdparty/bullet3")
set_target_properties(LinearMath PROPERTIES FOLDER "harfang/3rdparty/bullet3")
set_target_properties(BulletWorldImporter PROPERTIES FOLDER "harfang/3rdparty/bullet3")
set_target_properties(BulletFileLoader PROPERTIES FOLDER "harfang/3rdparty/bullet3")
install_cppsdk_external_target(BulletDynamics)
install_cppsdk_external_target(BulletCollision)
install_cppsdk_external_target(BulletCommon)
install_cppsdk_external_target(LinearMath)
install_cppsdk_external_target(BulletWorldImporter)
install_cppsdk_external_target(BulletFileLoader)
endif()
# imgui
add_library(imgui STATIC
imgui/misc/cpp/imgui_stdlib.cpp
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_tables.cpp
imgui/imgui_widgets.cpp
imgui/imgui.h
imgui/imgui_internal.h
imgui/imconfig.h)
target_include_directories(imgui
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/imgui>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../harfang>
$<INSTALL_INTERFACE:${CppSdkHeadersDestination}/extern/imgui>
)
set_target_properties(imgui PROPERTIES FOLDER "harfang/3rdparty")
install_cppsdk_external_target(imgui)
if(HG_BUILD_CPP_SDK)
install(DIRECTORY imgui DESTINATION cppsdk/include/extern FILES_MATCHING PATTERN "*.h" PATTERN "fonts" EXCLUDE)
endif()
# OpenAL soft
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
message("Configuring OpenAL soft")
set(ALSOFT_UTILS OFF CACHE BOOL "OpenAL soft: Build and install utility programs")
set(ALSOFT_EXAMPLES OFF CACHE BOOL "OpenAL soft: Build and install example programs")
set(ALSOFT_TESTS OFF CACHE BOOL "OpenAL soft: Build and install test programs")
set(ALSOFT_CONFIG OFF CACHE BOOL "OpenAL soft: Install alsoft.conf sample configuration file")
set(ALSOFT_INSTALL OFF CACHE BOOL "OpenAL soft: Install headers and libraries")
set(LIBTYPE STATIC) # build as static library
add_subdirectory(openal-soft EXCLUDE_FROM_ALL)
target_include_directories(OpenAL PRIVATE openal-soft-hrtf)
target_include_directories(OpenAL PUBLIC $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>)
target_compile_definitions(OpenAL PUBLIC AL_LIBTYPE_STATIC=1) # make sure to correctly propagate this flag to consuming librairies
set_target_properties(OpenAL PROPERTIES FOLDER "harfang/3rdparty")
# ... try to fix include directories
get_target_property(OpenAL_include_dirs OpenAL INTERFACE_INCLUDE_DIRECTORIES)
list(REMOVE_ITEM OpenAL_include_dirs "$<INSTALL_INTERFACE:include>")
set_property(TARGET OpenAL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OpenAL_include_dirs})
install_cppsdk_external_target(OpenAL)
endif()
# json.hpp
add_library(jsonhpp INTERFACE)
target_include_directories(jsonhpp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/json>
$<INSTALL_INTERFACE:${CppSdkHeadersDestination}/extern/json>
)
set_target_properties(jsonhpp PROPERTIES PUBLIC_HEADER "json/json.hpp;json/json_fwd.hpp")
install_cppsdk_external_target(jsonhpp json)
# tiny-process-library
add_subdirectory(tiny-process-library EXCLUDE_FROM_ALL)
target_include_directories(tiny-process-library INTERFACE tiny-process-library)
target_compile_definitions(tiny-process-library PUBLIC UNICODE=1)
set_target_properties(tiny-process-library PROPERTIES FOLDER "harfang/3rdparty")
# OpenVR
if(HG_ENABLE_OPENVR_API)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_OPENVR_BIT 64)
else()
set(_OPENVR_BIT 32)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(_OPENVR_ARCH "linux${_OPENVR_BIT}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(_OPENVR_ARCH "win${_OPENVR_BIT}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") # OpenVR only supports 32 bits osx...
set(_OPENVR_ARCH "osx32")
else(HG_ENABLE_OPENVR_API)
message(WARNING "OpenVR: unsupported platform ${CMAKE_SYSTEM_NAME}")
set(HG_ENABLE_OPENVR_API OFF)
endif()
if(HG_ENABLE_OPENVR_API)
set(OPENVR_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/openvr/headers)
find_library(OPENVR_LIBRARY name openvr_api PATHS ${CMAKE_CURRENT_SOURCE_DIR}/openvr/lib/${_OPENVR_ARCH} NO_DEFAULT_PATH)
add_library(OpenVR SHARED IMPORTED GLOBAL)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(OPENVR_DLL ${CMAKE_CURRENT_SOURCE_DIR}/openvr/bin/${_OPENVR_ARCH}/openvr_api.dll)
set(OPENVR_DLL ${OPENVR_DLL} PARENT_SCOPE)
set_target_properties(OpenVR PROPERTIES
IMPORTED_IMPLIB ${OPENVR_LIBRARY}
IMPORTED_LOCATION ${OPENVR_DLL}
INTERFACE_INCLUDE_DIRECTORIES ${OPENVR_INCLUDE_PATH}
)
if(HG_BUILD_CPP_SDK)
install(FILES ${OPENVR_DLL} DESTINATION ${CppSdkRuntimeDestination} COMPONENT cppsdk)
endif()
else()
set_target_properties(OpenVR PROPERTIES
IMPORTED_LOCATION ${OPENVR_LIBRARY}
IMPORTED_NO_SONAME TRUE
INTERFACE_INCLUDE_DIRECTORIES ${OPENVR_INCLUDE_PATH}
)
endif()
if(HG_BUILD_CPP_SDK)
install(FILES ${OPENVR_LIBRARY} DESTINATION ${CppSdkLibraryDestination} COMPONENT cppsdk)
endif()
endif(HG_ENABLE_OPENVR_API)
unset(_OPENVR_BIT)
unset(_OPENVR_ARCH)
endif()
# OpenXR
if(HG_ENABLE_OPENXR_API)
set(BUILD_WITH_SYSTEM_JSONCPP OFF CACHE BOOL "Build json openxr with system" FORCE)
add_subdirectory(OpenXR EXCLUDE_FROM_ALL)
set_target_properties(openxr_loader PROPERTIES FOLDER "harfang/3rdparty")
add_library(openxr INTERFACE)
# Several files use these compile-time platform switches
if(WIN32)
target_compile_definitions(openxr INTERFACE XR_USE_PLATFORM_WIN32 XR_USE_GRAPHICS_API_D3D11)# XR_USE_GRAPHICS_API_D3D12)
elseif(ANDROID)
target_compile_definitions(openxr INTERFACE XR_USE_PLATFORM_ANDROID)
elseif(PRESENTATION_BACKEND MATCHES "xlib")
target_compile_definitions(openxr INTERFACE XR_USE_PLATFORM_XLIB)
elseif(PRESENTATION_BACKEND MATCHES "wayland")
target_compile_definitions(openxr INTERFACE XR_USE_PLATFORM_WAYLAND)
endif()
target_compile_definitions(openxr INTERFACE XR_USE_GRAPHICS_API_OPENGL)
# find_package(Vulkan)
# if(Vulkan_FOUND)
# target_include_directories(openxr INTERFACE "bgfx/bgfx/3rdparty/khronos")
# target_compile_definitions(openxr INTERFACE XR_USE_GRAPHICS_API_VULKAN)
# endif()
target_link_libraries(openxr INTERFACE openxr_loader)
get_target_property(openxr_loader_INCLUDES openxr_loader INCLUDE_DIRECTORIES)
install_cppsdk_external_target(openxr)
endif()
# SRanipal
if(HG_ENABLE_SRANIPAL_API)
# [todo] linux
find_library(SRANIPAL_LIBRARY name SRanipal PATHS ${CMAKE_CURRENT_SOURCE_DIR}/sranipal/lib NO_DEFAULT_PATH)
set(SRANIPAL_DLL
${CMAKE_CURRENT_SOURCE_DIR}/sranipal/bin/libHTC_License.dll
${CMAKE_CURRENT_SOURCE_DIR}/sranipal/bin/nanomsg.dll
${CMAKE_CURRENT_SOURCE_DIR}/sranipal/bin/SRanipal.dll
${CMAKE_CURRENT_SOURCE_DIR}/sranipal/bin/SRWorks_Log.dll
${CMAKE_CURRENT_SOURCE_DIR}/sranipal/bin/ViveSR_Client.dll)
set(SRANIPAL_DLL ${SRANIPAL_DLL} PARENT_SCOPE)
add_library(SRanipal SHARED IMPORTED GLOBAL)
set_target_properties(SRanipal PROPERTIES
IMPORTED_IMPLIB ${CMAKE_CURRENT_SOURCE_DIR}/sranipal/lib/SRanipal.lib
IMPORTED_LOCATION "${SRANIPAL_DLL}"
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/sranipal/include
)
if(HG_BUILD_CPP_SDK)
install(FILES ${SRANIPAL_DLL} DESTINATION ${CppSdkRuntimeDestination} COMPONENT cppsdk)
install(FILES ${SRANIPAL_LIBRARY} DESTINATION ${CppSdkLibraryDestination} COMPONENT cppsdk)
endif()
endif()
# RecastDetour
if(HG_ENABLE_RECAST_DETOUR_API)
set(RECASTNAVIGATION_DEMO OFF CACHE BOOL "Build demo")
set(RECASTNAVIGATION_TESTS OFF CACHE BOOL "Build tests")
set(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "Build examples")
add_subdirectory(recastnavigation EXCLUDE_FROM_ALL)
set_property(TARGET Recast Detour DetourCrowd PROPERTY FOLDER "harfang/3rdparty/Detour")
install_cppsdk_external_target(Recast)
install_cppsdk_external_target(Detour)
install_cppsdk_external_target(DetourCrowd)
endif()
# CMFT
if(NOT MINGW)
add_executable(cmft
cmft/src/cmft/common/stb_image.cpp
cmft/src/cmft/common/print.cpp
cmft/src/cmft/allocator.cpp
cmft/src/cmft/clcontext.cpp
cmft/src/cmft/cubemapfilter.cpp
cmft/src/cmft/image.cpp
cmft/src/main.cpp)
target_include_directories(cmft PRIVATE cmft/include cmft/dependency cmft/src/cmft)
target_compile_definitions(cmft PRIVATE CMFT_ENABLE_INFO_MESSAGES=1)
set_target_properties(cmft PROPERTIES FOLDER "harfang/tools")
if(APPLE)
target_link_libraries(cmft pthread dl)
elseif(UNIX)
target_compile_definitions(cmft PRIVATE linux)
target_link_libraries(cmft pthread dl)
endif()
endif()
# meshoptimizer
set(CMAKE_INSTALL_INCLUDEDIR ${CppSdkHeadersDestination}/extern)
add_subdirectory(meshoptimizer EXCLUDE_FROM_ALL)
set_target_properties(meshoptimizer PROPERTIES FOLDER "harfang/3rdparty")
install_cppsdk_external_target(meshoptimizer)
if(HG_ENABLE_OPENXR_API)
install_cppsdk_external_target(openxr_loader)
endif()
# meshoptimizer: in emscripten remove some compile options flag
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
get_target_property(_target_cxx_flags meshoptimizer COMPILE_OPTIONS)
if(_target_cxx_flags)
list(REMOVE_ITEM _target_cxx_flags -Wall -Wextra -Wshadow -Werror)
set_target_properties(meshoptimizer PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
endif()
endif()
# mikktspace
add_library(mikktspace STATIC mikktspace/mikktspace.c mikktspace/mikktspace.h)
target_include_directories(mikktspace PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/mikktspace>)
set_target_properties(mikktspace PROPERTIES FOLDER "harfang/3rdparty")
install_cppsdk_external_target(mikktspace)