forked from StereoKit/StereoKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
468 lines (418 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
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
# Copyright 2021, Collabora, Ltd.
# Copyright Moses Turner, 2021.
# Copyright Nick Klingensmith, 2021.
# Many thanks to Ryan Pavlik for showing the way
# SPDX-License-Identifier: MIT
# This build file has the following options
# - SK_LINUX_EGL
# This tells the Linux build to use EGL as the OpenGL loader,
# instead of the default GLX.
# - SK_MULTITHREAD_BUILD_BY_DEFAULT
# MSVC only, on by default. This forces projects here to
# build with multi-threading (/MP)
# - SK_BUILD_TESTS
# Build the StereoKitCTest project in addition to the StereoKitC
# library. This is off by default.
# - SK_BUILD_SHARED_LIBS
# Should StereoKit build as a shared, or static library?
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(StereoKit VERSION "0.3.6" LANGUAGES CXX C)
# Default build configuration to RelWithDebInfo
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
endif()
###########################################
## Options ##
###########################################
set(SK_LINUX_EGL OFF CACHE BOOL "Force using EGL graphics backend on Linux")
set(SK_MULTITHREAD_BUILD_BY_DEFAULT ON CACHE BOOL "MSVC only, on by default. This forces projects here to build with multi-threading (/MP)")
set(SK_BUILD_TESTS ON CACHE BOOL "Build the StereoKitCTest project in addition to the StereoKitC library.")
set(SK_BUILD_SHARED_LIBS ON CACHE BOOL "Should StereoKit build as a shared, or static library?")
set(SK_PHYSICS ON CACHE BOOL "Enable physics.")
set(FORCE_COLORED_OUTPUT OFF CACHE BOOL "Always produce ANSI-colored output (GNU/Clang only).")
###########################################
## Pretty colors ##
###########################################
if(FORCE_COLORED_OUTPUT)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif()
###########################################
## Dependencies ##
###########################################
# See: https://github.com/cpm-cmake/CPM.cmake
include("cmake/CPM.cmake")
if (UNIX)
# Linux users/devs prefer shared system libraries rather than
# static libraries. Linux OpenXR runtimes are responsible for
# providing the shared OpenXR loader there. On Windows and
# Android, static linking is necessary.
set(CPM_USE_LOCAL_PACKAGES ON) # Tell CPM to prefer locally installed packages
endif()
#### ReactPhysics3D - https://www.reactphysics3d.com/ ####
if(SK_PHYSICS)
CPMAddPackage(
NAME reactphysics3d
GITHUB_REPOSITORY DanielChappuis/reactphysics3d
GIT_TAG 4bbbaa7c6e92942734eec696e23a2fad1f1cb8a1 # v0.9.0
EXCLUDE_FROM_ALL YES
)
# Something in reactphysics3d seems to require -fPIC
set_property(TARGET reactphysics3d PROPERTY POSITION_INDEPENDENT_CODE ON)
# Disable warnings for reactphysics3d, it's a little horrifying
target_compile_options(reactphysics3d PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W0>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-w> )
set(PHYSICS_LIB
reactphysics3d)
endif()
#### OpenXR - https://www.khronos.org/openxr/ ####
CPMAddPackage(
NAME OpenXR
VERSION 1.0.22
GITHUB_REPOSITORY KhronosGroup/OpenXR-SDK
GIT_TAG 458984d7f59d1ae6dc1b597d94b02e4f7132eaba # v1.0.22
)
###########################################
## Shader Compiler ##
###########################################
set(SK_SRC_SHADERS_HLSL
StereoKitC/shaders_builtin/shader_builtin_blit.hlsl
StereoKitC/shaders_builtin/shader_builtin_default.hlsl
StereoKitC/shaders_builtin/shader_builtin_equirect.hlsl
StereoKitC/shaders_builtin/shader_builtin_font.hlsl
StereoKitC/shaders_builtin/shader_builtin_lines.hlsl
StereoKitC/shaders_builtin/shader_builtin_pbr.hlsl
StereoKitC/shaders_builtin/shader_builtin_pbr_clip.hlsl
StereoKitC/shaders_builtin/shader_builtin_skybox.hlsl
StereoKitC/shaders_builtin/shader_builtin_ui.hlsl
StereoKitC/shaders_builtin/shader_builtin_ui_box.hlsl
StereoKitC/shaders_builtin/shader_builtin_ui_quadrant.hlsl
StereoKitC/shaders_builtin/shader_builtin_unlit.hlsl
StereoKitC/shaders_builtin/shader_builtin_unlit_clip.hlsl )
set(SK_SRC_SHADERS_H
StereoKitC/shaders_builtin/shader_builtin.h )
set(SK_SHADER_COMPILER "${CMAKE_SOURCE_DIR}/Tools/skshaderc")
foreach(SHADER ${SK_SRC_SHADERS_HLSL})
# Shader compile tool doesn't work on Linux yet, but pre-built
# shaders should still be in the repository.
if (WIN32)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/${SHADER}.h
COMMAND ${SK_SHADER_COMPILER} -h -t xge -i ${CMAKE_SOURCE_DIR}/Tools/include -o ${CMAKE_SOURCE_DIR}/StereoKitC/shaders_builtin/ ${CMAKE_SOURCE_DIR}/${SHADER}
DEPENDS ${SHADER} )
endif()
list(APPEND SK_SRC_SHADERS_H ${SHADER}.h)
endforeach(SHADER)
###########################################
## Platform Specific Library Linking ##
###########################################
if (UNIX)
set(LINUX_LIBS
Threads::Threads
GLX
X11
fontconfig )
# Add pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Add OpenGL, and account for the SK_LINUX_EGL option
if(SK_LINUX_EGL)
add_definitions("-DSKG_LINUX_EGL")
list(APPEND LINUX_LIBS EGL)
else()
add_definitions("-DSKG_LINUX_GLX")
find_package(GLEW REQUIRED)
find_package(X11 REQUIRED)
list(APPEND LINUX_LIBS GL GLEW)
endif()
elseif(WIN32)
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
set(WINDOWS_LIBS
WindowsApp) # Required for ISAC spatial audio code
endif()
if(NOT SK_PHYSICS)
message("-- Building without physics!")
add_definitions("-DSK_PHYSICS_PASSTHROUGH")
else()
message("-- Building with physics!")
endif()
###########################################
## StereoKitC ##
###########################################
set(SK_SRC_CODE
StereoKitC/stereokit.h
StereoKitC/_stereokit.h
StereoKitC/_stereokit_ui.h
StereoKitC/color.cpp
StereoKitC/backend.cpp
StereoKitC/hierarchy.h
StereoKitC/hierarchy.cpp
StereoKitC/intersect.cpp
StereoKitC/log.h
StereoKitC/log.cpp
StereoKitC/rect_atlas.h
StereoKitC/rect_atlas.cpp
StereoKitC/sk_math.h
StereoKitC/sk_math_dx.h
StereoKitC/sk_math.cpp
StereoKitC/sk_memory.h
StereoKitC/sk_memory.cpp
StereoKitC/spherical_harmonics.h
StereoKitC/spherical_harmonics.cpp
StereoKitC/stereokit.cpp )
set(SK_SRC_ASSET_TYPES
StereoKitC/asset_types/assets.h
StereoKitC/asset_types/assets.cpp
StereoKitC/asset_types/animation.h
StereoKitC/asset_types/animation.cpp
StereoKitC/asset_types/font.h
StereoKitC/asset_types/font.cpp
StereoKitC/asset_types/material.h
StereoKitC/asset_types/material.cpp
StereoKitC/asset_types/mesh.h
StereoKitC/asset_types/mesh.cpp
StereoKitC/asset_types/model.h
StereoKitC/asset_types/model.cpp
StereoKitC/asset_types/model_gltf.cpp
StereoKitC/asset_types/model_obj.cpp
StereoKitC/asset_types/model_ply.cpp
StereoKitC/asset_types/model_stl.cpp
StereoKitC/asset_types/shader.h
StereoKitC/asset_types/shader.cpp
StereoKitC/asset_types/sound.h
StereoKitC/asset_types/sound.cpp
StereoKitC/asset_types/sprite.h
StereoKitC/asset_types/sprite.cpp
StereoKitC/asset_types/texture.h
StereoKitC/asset_types/texture.cpp )
set(SK_SRC_LIBRARIES
StereoKitC/libraries/aileron_font_data.h
StereoKitC/libraries/array.h
StereoKitC/libraries/cgltf.h
StereoKitC/libraries/cgltf.cpp
StereoKitC/libraries/ferr_hash.h
StereoKitC/libraries/ferr_hash.cpp
StereoKitC/libraries/isac_spatial_sound.h
StereoKitC/libraries/isac_spatial_sound.cpp
StereoKitC/libraries/micro_ply.h
StereoKitC/libraries/miniaudio.h
StereoKitC/libraries/miniaudio.cpp
StereoKitC/libraries/qoi.h
StereoKitC/libraries/qoi.cpp
StereoKitC/libraries/sk_gpu.h
StereoKitC/libraries/sk_gpu.cpp
StereoKitC/libraries/sokol_time.h
StereoKitC/libraries/sokol_time.cpp
StereoKitC/libraries/stb_image.h
StereoKitC/libraries/stb_image.cpp
StereoKitC/libraries/stb_image_write.h
StereoKitC/libraries/stb_truetype.h
StereoKitC/libraries/stref.h
StereoKitC/libraries/stref.cpp
StereoKitC/libraries/tinycthread.h
StereoKitC/libraries/tinycthread.cpp )
set(SK_SRC_SYSTEMS
StereoKitC/systems/audio.h
StereoKitC/systems/audio.cpp
StereoKitC/systems/defaults.h
StereoKitC/systems/defaults.cpp
StereoKitC/systems/input.h
StereoKitC/systems/input.cpp
StereoKitC/systems/input_keyboard.h
StereoKitC/systems/input_keyboard.cpp
StereoKitC/systems/line_drawer.h
StereoKitC/systems/line_drawer.cpp
StereoKitC/systems/physics.h
StereoKitC/systems/physics.cpp
StereoKitC/systems/render.h
StereoKitC/systems/render.cpp
StereoKitC/systems/sprite_drawer.h
StereoKitC/systems/sprite_drawer.cpp
StereoKitC/systems/system.h
StereoKitC/systems/system.cpp
StereoKitC/systems/text.h
StereoKitC/systems/text.cpp
StereoKitC/systems/world.h
StereoKitC/systems/world.cpp )
set(SK_SRC_HANDS
StereoKitC/systems/hand/hand_mouse.h
StereoKitC/systems/hand/hand_mouse.cpp
StereoKitC/systems/hand/hand_override.h
StereoKitC/systems/hand/hand_override.cpp
StereoKitC/systems/hand/hand_oxr_articulated.h
StereoKitC/systems/hand/hand_oxr_articulated.cpp
StereoKitC/systems/hand/hand_oxr_controller.h
StereoKitC/systems/hand/hand_oxr_controller.cpp
StereoKitC/systems/hand/hand_poses.h
StereoKitC/systems/hand/input_hand.h
StereoKitC/systems/hand/input_hand.cpp )
set(SK_SRC_PLATFORM
StereoKitC/systems/platform/android.cpp
StereoKitC/systems/platform/android.h
StereoKitC/systems/platform/flatscreen_input.h
StereoKitC/systems/platform/flatscreen_input.cpp
StereoKitC/systems/platform/linux.h
StereoKitC/systems/platform/linux.cpp
StereoKitC/systems/platform/openxr.h
StereoKitC/systems/platform/openxr.cpp
StereoKitC/systems/platform/openxr_extensions.h
StereoKitC/systems/platform/openxr_input.h
StereoKitC/systems/platform/openxr_input.cpp
StereoKitC/systems/platform/openxr_view.h
StereoKitC/systems/platform/openxr_view.cpp
StereoKitC/systems/platform/platform.h
StereoKitC/systems/platform/platform.cpp
StereoKitC/systems/platform/platform_utils.h
StereoKitC/systems/platform/platform_utils.cpp
StereoKitC/systems/platform/web.h
StereoKitC/systems/platform/web.cpp
StereoKitC/systems/platform/uwp.h
StereoKitC/systems/platform/uwp.cpp
StereoKitC/systems/platform/win32.h
StereoKitC/systems/platform/win32.cpp )
set(SK_SRC_TOOLS
StereoKitC/tools/virtual_keyboard_layouts.h
StereoKitC/tools/virtual_keyboard.h
StereoKitC/tools/virtual_keyboard.cpp
StereoKitC/tools/file_picker.h
StereoKitC/tools/file_picker.cpp )
set(SK_SRC_UI
StereoKitC/stereokit_ui.h
StereoKitC/ui/stereokit_ui.cpp )
# Switch between a static or shared library based on
# the cmake options provided.
if (SK_BUILD_SHARED_LIBS)
set(LIBRARY_TYPE SHARED)
else()
set(LIBRARY_TYPE STATIC)
endif()
add_library(StereoKitC ${LIBRARY_TYPE}
${SK_SRC_CODE}
${SK_SRC_ASSET_TYPES}
${SK_SRC_LIBRARIES}
${SK_SRC_SYSTEMS}
${SK_SRC_HANDS}
${SK_SRC_PLATFORM}
${SK_SRC_TOOLS}
${SK_SRC_UI}
${SK_SRC_SHADERS_H} )
# Set up Visual Studio folders/filters for a more organized
# workspace there.
source_group("code" FILES ${SK_SRC_CODE})
source_group("asset_types" FILES ${SK_SRC_ASSET_TYPES})
source_group("libraries" FILES ${SK_SRC_LIBRARIES})
source_group("systems" FILES ${SK_SRC_SYSTEMS})
source_group("hands" FILES ${SK_SRC_HANDS})
source_group("platform" FILES ${SK_SRC_PLATFORM})
source_group("tools" FILES ${SK_SRC_TOOLS})
source_group("ui" FILES ${SK_SRC_UI})
if (UNIX)
# DirectXMath on Linux needs a few extra files
set(LINUX_INCLUDES
StereoKitC/lib/include_no_win/)
endif()
target_include_directories(StereoKitC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/StereoKitC>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/StereoKitC/
${LINUX_INCLUDES}
)
target_link_libraries( StereoKitC
PRIVATE
${PHYSICS_LIB}
openxr_loader
${LINUX_LIBS}
${WINDOWS_LIBS}
${CMAKE_DL_LIBS}
)
###########################################
## StereoKitCTest ##
###########################################
if (SK_BUILD_TESTS)
add_executable( StereoKitCTest
Examples/StereoKitCTest/main.cpp
Examples/StereoKitCTest/demo_envmap.h
Examples/StereoKitCTest/demo_envmap.cpp
Examples/StereoKitCTest/demo_draw.h
Examples/StereoKitCTest/demo_draw.cpp
Examples/StereoKitCTest/demo_basics.h
Examples/StereoKitCTest/demo_basics.cpp
Examples/StereoKitCTest/demo_desktop.h
Examples/StereoKitCTest/demo_desktop.cpp
Examples/StereoKitCTest/demo_picker.h
Examples/StereoKitCTest/demo_picker.cpp
Examples/StereoKitCTest/demo_mic.h
Examples/StereoKitCTest/demo_mic.cpp
Examples/StereoKitCTest/demo_sprites.h
Examples/StereoKitCTest/demo_sprites.cpp
Examples/StereoKitCTest/scene.h
Examples/StereoKitCTest/scene.cpp
Examples/StereoKitCTest/demo_ui.h
Examples/StereoKitCTest/demo_ui.cpp
Examples/StereoKitCTest/demo_ui_layout.h
Examples/StereoKitCTest/demo_ui_layout.cpp
Examples/StereoKitCTest/demo_world.h
Examples/StereoKitCTest/demo_world.cpp
Examples/StereoKitCTest/demo_windows.h
Examples/StereoKitCTest/demo_windows.cpp
Examples/StereoKitCTest/demo_lines.h
Examples/StereoKitCTest/demo_lines.cpp
Examples/StereoKitCTest/demo_lighting.h
Examples/StereoKitCTest/demo_lighting.cpp
Examples/StereoKitCTest/skt_lighting.h
Examples/StereoKitCTest/skt_lighting.cpp
Examples/StereoKitCTest/Shaders/skt_default_lighting.hlsl.h
Examples/StereoKitCTest/Shaders/skt_light_only.hlsl.h
)
target_link_libraries( StereoKitCTest
StereoKitC
)
if (MSVC AND SK_MULTITHREAD_BUILD_BY_DEFAULT)
target_compile_options(StereoKitCTest PRIVATE "/MP")
endif()
endif()
###########################################
## Multi-threaded build MSVC ##
###########################################
# Setup Visual Studio to use multi-threaded compilation by
# default, this is mostly for when using Visual Studio as
# the IDE. CLI users can pass in command line arguments.
if (MSVC AND SK_MULTITHREAD_BUILD_BY_DEFAULT)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
if(SK_PHYSICS)
target_compile_options(reactphysics3d PRIVATE "/MP")
endif()
target_compile_options(openxr_loader PRIVATE "/MP")
target_compile_options(StereoKitC PRIVATE "/MP")
endif()
###########################################
## Installation ##
###########################################
# For installing on Linux
# find_package(PkgConfig)
install(
TARGETS StereoKitC
EXPORT StereoKitC-targets
)
install(
FILES "StereoKitC/stereokit.h" "StereoKitC/stereokit_ui.h" "Tools/include/stereokit.hlsli"
DESTINATION include)
install(
FILES "Tools/skshaderc"
DESTINATION bin)
install(
EXPORT StereoKitC-targets
FILE StereoKitCConfig.cmake
NAMESPACE StereoKitC::
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/StereoKitC"
)