-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
540 lines (483 loc) · 23.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
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
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
PROJECT(osgVerse)
SET(VERSE_VERSION "0.8.0")
SET(VERSE_GRAPHICS_API "GL")
SET(VERSE_PLATFORM "")
SET(CMAKE_DEBUG_POSTFIX "d")
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")
SET(FIND_LIB_POSTFIX lib)
SET_PROPERTY(GLOBAL PROPERTY VERSE_DEPENDENCIES "")
SET_PROPERTY(GLOBAL PROPERTY VERSE_PLUGIN_LIBRARIES "")
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
INCLUDE(VerseMacros)
######################################### Install Configurations
SET(VERSE_3RDPARTY_PATH "${CMAKE_SOURCE_DIR}/../Dependencies" CACHE STRING "Dependency root path")
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/sdk" CACHE PATH "..." FORCE)
ENDIF()
IF(NOT WIN32)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -frtti -fpermissive")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib")
ENDIF(NOT WIN32)
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275 /wd4996 /nologo /bigobj")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
ELSEIF(MINGW OR CYGWIN)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -Wa,-mbig-obj")
ENDIF()
SET(INSTALL_INCDIR include)
SET(INSTALL_BINDIR bin)
IF(WIN32)
SET(INSTALL_LIBDIR bin)
SET(INSTALL_ARCHIVEDIR lib)
ELSE()
INCLUDE(GNUInstallDirs)
SET(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
SET(INSTALL_ARCHIVEDIR ${CMAKE_INSTALL_LIBDIR})
ENDIF()
######################################### SIMD Finders
INCLUDE(CMakeHostSystemInformationExtra)
INCLUDE(GetCPUSIMDFeatures)
MACRO(APPLY_SIMD_FLAGS CHECK_NAME DEF_FLAG COMPILER_FLAG)
IF(${CHECK_NAME} IN_LIST VERSE_SIMD_FEATURES)
IF(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEF_FLAG}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEF_FLAG}")
ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAG}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAG}")
ADD_DEFINITIONS(${DEF_FLAG})
ENDIF()
ENDIF()
ENDMACRO(APPLY_SIMD_FLAGS)
SET(VERSE_NO_SIMD_FEATURES OFF CACHE BOOL "Enable to ignore all SIMD features (when struggling with compile errors)")
SET(VERSE_SIMD_FEATURES "")
IF(VERSE_NO_SIMD_FEATURES)
# Do nothing...
ELSEIF(USE_WASM_OPTIONS)
# https://emscripten.org/docs/porting/simd.html
SET(VERSE_SIMD_FEATURES sse sse2 sse3 avx)
MESSAGE(STATUS "[osgVerse] WebAssembly Porting. Features: ${VERSE_SIMD_FEATURES}")
ELSE()
CMAKE_HOST_SYSTEM_INFORMATION_EXTRA(RESULT VERSE_CPU_ARCHITECT QUERY PROCESSOR_MICRO_ARCHITECTURE)
IF(VERSE_CPU_ARCHITECT)
GET_CPU_SIMD_FEATURES(VERSE_SIMD_FEATURES "${VERSE_CPU_ARCHITECT}")
MESSAGE(STATUS "[osgVerse] CPU Architecture: ${VERSE_CPU_ARCHITECT}. Features: ${VERSE_SIMD_FEATURES}")
ENDIF(VERSE_CPU_ARCHITECT)
ENDIF()
IF(VERSE_SIMD_FEATURES)
# Find SIMD instruction supporting using the following statement:
# IF("sse3" IN_LIST VERSE_SIMD_FEATURES) ...
IF(USE_WASM_OPTIONS)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msimd128")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msimd128")
ELSE()
APPLY_SIMD_FLAGS("sse" "-D__SSE__" "-msse")
APPLY_SIMD_FLAGS("sse2" "-D__SSE2__" "-msse2")
APPLY_SIMD_FLAGS("sse3" "-D__SSE3__" "-msse3")
APPLY_SIMD_FLAGS("ssse3" "-D__SSSE3__" "-mssse3")
APPLY_SIMD_FLAGS("sse4.1" "-D__SSE4_1__" "-msse4.1")
APPLY_SIMD_FLAGS("sse4.2" "-D__SSE4_2__" "-msse4.2")
APPLY_SIMD_FLAGS("avx" "-D__AVX__" "-mavx")
APPLY_SIMD_FLAGS("avx2" "-D__AVX2__" "-mavx2")
APPLY_SIMD_FLAGS("fma" "-D__FMA__" "-mfma")
ENDIF()
ENDIF()
######################################### Core Dependency Finders
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/x86)
IF(CMAKE_CL_64)
SET(FIND_LIB_POSTFIX lib64)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/x64)
ENDIF(CMAKE_CL_64)
SET(USE_UWP_OPTIONS OFF)
IF(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
SET(USE_UWP_OPTIONS ON)
MESSAGE("[osgVerse] Building Windows Store (UWP) libraries...")
ENDIF()
SET(BUILD_WASM_64 OFF)
IF(USE_WASM_OPTIONS)
IF(USE_WASM_OPTIONS EQUAL 2)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/wasm64)
SET(BUILD_WASM_64 ON)
ELSE()
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/wasm)
ENDIF()
ELSEIF(USE_UWP_OPTIONS)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/uwp)
ELSEIF(ANDROID)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/android)
ELSEIF(IOS)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/ios)
ELSEIF(APPLE)
SET(THIRDPARTY_ROOT ${VERSE_3RDPARTY_PATH}/apple)
ENDIF()
IF(OSG_ROOT)
SET(OSG_INCLUDE_DIR "${OSG_ROOT}/include")
SET(OSG_BUILD_INCLUDE_DIR "${OSG_ROOT}/include")
SET(OSG_LIB_DIR "${OSG_ROOT}/lib")
ELSE(OSG_ROOT)
FIND_PATH(OSG_INCLUDE_DIR osg/Referenced
PATHS ${THIRDPARTY_ROOT}/include
$ENV{OSG_ROOT}/include
$ENV{OSG_DIR}/include
/usr/include
/usr/local/include
)
FIND_PATH(OSG_BUILD_INCLUDE_DIR osg/Config
PATHS ${THIRDPARTY_ROOT}/include
$ENV{OSG_ROOT}/include
$ENV{OSG_DIR}/include
/usr/include
/usr/local/include
)
FIND_PATH(OSG_LIB_DIR
NAMES libosg.a libosg.dll.a libosg.so osg.lib
PATHS ${THIRDPARTY_ROOT}/lib
$ENV{OSG_ROOT}/lib $ENV{OSG_ROOT}/${FIND_LIB_POSTFIX}
$ENV{OSG_DIR}/lib $ENV{OSG_DIR}/${FIND_LIB_POSTFIX}
${OSG_BUILD_INCLUDE_DIR}/../lib
/usr/lib /usr/${FIND_LIB_POSTFIX} /usr/lib/x86_64-linux-gnu
/usr/local/lib /usr/local/${FIND_LIB_POSTFIX}
)
ENDIF(OSG_ROOT)
SET(VERSE_DEBUG_POSTFIX "_Debug" CACHE STRING "Postfix of thirdparty built-libraries")
SET(OSG_DEBUG_POSTFIX "d" CACHE STRING "Postfix of OSG built-libraries")
SET(OSG_VERSION_THREADS "")
SET(OSG_VERSION_CORE "")
MACRO(LINK_OSG_LIBRARY PROJECT_NAME)
FOREACH(OSG_LIB_NAME ${ARGN})
STRING(FIND ${OSG_LIB_NAME} "OpenThreads" FOUND_OT_INDEX)
IF(FOUND_OT_INDEX GREATER "-1")
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
debug ${OSG_VERSION_THREADS}${OSG_LIB_NAME}${OSG_DEBUG_POSTFIX}
optimized ${OSG_VERSION_THREADS}${OSG_LIB_NAME})
ELSE()
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
debug ${OSG_VERSION_CORE}${OSG_LIB_NAME}${OSG_DEBUG_POSTFIX}
optimized ${OSG_VERSION_CORE}${OSG_LIB_NAME})
ENDIF()
ENDFOREACH()
ENDMACRO(LINK_OSG_LIBRARY)
SET(VERSE_FIND_LEGACY_OPENGL OFF CACHE BOOL "Enable to find OpenGL in legacy mode")
IF(VERSE_FIND_LEGACY_OPENGL)
SET(OpenGL_GL_PREFERENCE "LEGACY")
ELSE(VERSE_FIND_LEGACY_OPENGL)
SET(OpenGL_GL_PREFERENCE "GLVND")
ENDIF(VERSE_FIND_LEGACY_OPENGL)
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(OpenMP)
IF(OPENMP_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
IF(USE_WASM_OPTIONS OR ANDROID OR APPLE)
# do nothing
ELSEIF(NOT OPENGL_gl_LIBRARY)
IF(OPENGL_opengl_LIBRARY)
SET(OPENGL_gl_LIBRARY ${OPENGL_opengl_LIBRARY})
ELSE(OPENGL_opengl_LIBRARY)
MESSAGE(FATAL_ERROR "[osgVerse] Dependency OpenGL not found. All following steps may not work...")
ENDIF(OPENGL_opengl_LIBRARY)
ENDIF()
SET(THIRDPARTY_INCLUDE_DIRS "")
SET(THIRDPARTY_LIBRARIES "")
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${OPENGL_gl_LIBRARY})
IF(OPENMP_FOUND)
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} OpenMP::OpenMP_CXX)
ENDIF(OPENMP_FOUND)
######################################### Global Options
SET(VERSE_INSTALL_PDB_FILES ON CACHE BOOL "Enable to install PDB files along with executables and dynamic libraries")
SET(VERSE_BUILD_EXPORTERS OFF CACHE BOOL "Enable build of exporters of other software (e.g., 3dsmax)")
SET(VERSE_BUILD_3RDPARTIES ON CACHE BOOL "Enable build of common libraries like FreeType, Jpeg and PNG")
SET(VERSE_BUILD_WITH_QT OFF CACHE BOOL "Enable build of Qt based applications and tests")
SET(VERSE_BUILD_DEPRECATED_TESTS OFF CACHE BOOL "Enable build of deprecated tests")
SET(VERSE_SUPPORT_CPP17 OFF CACHE BOOL "Enable build of libraries using C++ 17 standard")
SET(VERSE_STATIC_BUILD OFF CACHE BOOL "Enable static build of osgVerse libraries")
SET(VERSE_USE_OSG_STATIC OFF CACHE BOOL "Use static build of OpenSceneGraph (will force osgVerse to be static)")
SET(VERSE_USE_MTT_DRIVER OFF CACHE BOOL "Use MooreThreads MTT drivers")
IF(VERSE_SUPPORT_CPP17)
SET(CMAKE_CXX_STANDARD 17)
ENDIF(VERSE_SUPPORT_CPP17)
IF(MSVC)
SET(VERSE_USE_FORCED_MULTIPLE OFF CACHE BOOL "Use /FORCE:MULTIPLE flag under MSVC")
IF(VERSE_USE_FORCED_MULTIPLE)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /FORCE:MULTIPLE")
ENDIF(VERSE_USE_FORCED_MULTIPLE)
ELSEIF(UNIX)
SET(VERSE_USE_DWARF OFF CACHE BOOL "Enable detailed debug-info and symbols. 'libdw-dev' must be installed")
SET(VERSE_USE_GLIBCXX11_ABI ON CACHE BOOL
"Enable _GLIBCXX_USE_CXX11_ABI for newer GCC compilers. Set to OFF if you are using old ones")
ENDIF()
IF(VERSE_USE_OSG_STATIC)
SET(VERSE_STATIC_BUILD ON CACHE BOOL "Enable static build of osgVerse" FORCE)
ENDIF(VERSE_USE_OSG_STATIC)
IF(USE_WASM_OPTIONS)
SET(VERSE_WASM_USE_PTHREAD ON CACHE BOOL "Enable Pthread for WASM, which requires SharedArrayBuffer (COOP / COEP) on server-side")
SET(VERSE_WASM_OPTIMIZE_SIZE OFF CACHE BOOL "Enable -O3 for WASM, which is very slow but with small generated size")
SET(VERSE_USE_OSG_STATIC ON CACHE BOOL "Enable static build of osgVerse libraries" FORCE)
SET(VERSE_STATIC_BUILD ON CACHE BOOL "Enable static build of osgVerse" FORCE)
IF(BUILD_WASM_64)
ADD_DEFINITIONS("-s MEMORY64=1 -s USE_SDL=2 -pthread")
ELSE(BUILD_WASM_64)
ADD_DEFINITIONS("-s USE_SDL=2 -pthread")
ENDIF(BUILD_WASM_64)
ELSEIF(ANDROID)
SET(VERSE_USE_OSG_STATIC ON CACHE BOOL "Enable static build of osgVerse libraries" FORCE)
SET(VERSE_STATIC_BUILD ON CACHE BOOL "Enable static build of osgVerse" FORCE)
ADD_DEFINITIONS(-DBACKWARD_SYSTEM_UNKNOWN=1)
ENDIF()
######################################### Checking OSG version and definition
SET(VERSE_USE_EXTERNAL_GLCORE OFF)
SET(VERSE_USE_EXTERNAL_GLES2 OFF)
SET(VERSE_USE_EXTERNAL_GLES3 OFF)
IF(OSG_BUILD_INCLUDE_DIR)
FILE(READ "${OSG_BUILD_INCLUDE_DIR}/osg/GL" OSG_GL_FILE_CONTENTS)
STRING(FIND "${OSG_GL_FILE_CONTENTS}" "#define OSG_GL3_AVAILABLE" OSG_GLCORE_INDEX)
STRING(FIND "${OSG_GL_FILE_CONTENTS}" "#define OSG_GLES2_AVAILABLE" OSG_GLES2_INDEX)
STRING(FIND "${OSG_GL_FILE_CONTENTS}" "#define OSG_GLES3_AVAILABLE" OSG_GLES3_INDEX)
IF(OSG_GLCORE_INDEX GREATER -1)
MESSAGE(STATUS "[osgVerse] OSG is built with GL3/4 support.")
SET(VERSE_USE_EXTERNAL_GLCORE ON)
SET(VERSE_GRAPHICS_API "GLCORE")
ENDIF()
IF(OSG_GLES3_INDEX GREATER -1)
MESSAGE(STATUS "[osgVerse] OSG is built with GLES3 support. Make sure to configure osgVerse to use GLES3, too.")
FIND_PATH(OSG_GLES_INCLUDE_DIR GLES3/gl3.h PATHS /usr/include /usr/local/include)
FIND_LIBRARY(OSG_GLES_LIBRARY NAMES libGLESv2.so libGLESv2.lib
HINTS /usr/lib /usr/${FIND_LIB_POSTFIX} /usr/local/lib /usr/local/${FIND_LIB_POSTFIX})
FIND_LIBRARY(OSG_EGL_LIBRARY NAMES libEGL.so libEGL.lib
HINTS /usr/lib /usr/${FIND_LIB_POSTFIX} /usr/local/lib /usr/local/${FIND_LIB_POSTFIX})
SET(VERSE_USE_EXTERNAL_GLES3 ON)
SET(VERSE_GRAPHICS_API "GLES3")
ELSEIF(OSG_GLES2_INDEX GREATER -1)
MESSAGE(STATUS "[osgVerse] OSG is built with GLES2 support. Make sure to configure osgVerse to use GLES2, too.")
FIND_PATH(OSG_GLES_INCLUDE_DIR GLES2/gl2.h PATHS /usr/include /usr/local/include)
FIND_LIBRARY(OSG_GLES_LIBRARY NAMES libGLESv2.so libGLESv2.lib
HINTS /usr/lib /usr/${FIND_LIB_POSTFIX} /usr/local/lib /usr/local/${FIND_LIB_POSTFIX})
FIND_LIBRARY(OSG_EGL_LIBRARY NAMES libEGL.so libEGL.lib
HINTS /usr/lib /usr/${FIND_LIB_POSTFIX} /usr/local/lib /usr/local/${FIND_LIB_POSTFIX})
SET(VERSE_USE_EXTERNAL_GLES2 ON)
SET(VERSE_GRAPHICS_API "GLES2")
ENDIF()
IF(VERSE_USE_EXTERNAL_GLES2 OR VERSE_USE_EXTERNAL_GLES3)
IF(OSG_GLES_INCLUDE_DIR AND OSG_GLES_LIBRARY)
SET(OPENGL_INCLUDE_DIR "${OSG_GLES_INCLUDE_DIR}" CACHE STRING "Set OpenGL include folder to use the GLES alternative" FORCE)
SET(OPENGL_gl_LIBRARY "${OSG_GLES_LIBRARY}" CACHE STRING "Set OpenGL library to use the GLES alternative" FORCE)
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${OSG_EGL_LIBRARY})
ELSEIF(NOT USE_WASM_OPTIONS)
MESSAGE("[osgVerse] Dependency GLES not found. The solution may be uncompilable...")
ENDIF()
ENDIF(VERSE_USE_EXTERNAL_GLES2 OR VERSE_USE_EXTERNAL_GLES3)
ENDIF(OSG_BUILD_INCLUDE_DIR)
SET(VERSE_USE_EXTERNAL_GLES OFF)
IF(VERSE_USE_EXTERNAL_GLES2 OR VERSE_USE_EXTERNAL_GLES3)
SET(VERSE_USE_EXTERNAL_GLES ON)
ENDIF()
IF(ANDROID OR IOS OR USE_UWP_OPTIONS OR USE_WASM_OPTIONS)
IF(NOT VERSE_USE_EXTERNAL_GLES)
MESSAGE(FATAL_ERROR "[osgVerse] Dependency GLES not found, which is the only solution under current platform...")
ENDIF()
ENDIF()
SET(OSG_MAJOR_VERSION 3)
SET(OSG_MINOR_VERSION 1)
SET(OSG_PATCH_VERSION 1)
IF(OSG_BUILD_INCLUDE_DIR)
FILE(READ "${OSG_BUILD_INCLUDE_DIR}/OpenThreads/Version" OT_FILE_CONTENTS)
FILE(READ "${OSG_BUILD_INCLUDE_DIR}/osg/Version" OSG_FILE_CONTENTS)
STRING(FIND "${OT_FILE_CONTENTS}" "OPENTHREADS_SOVERSION" OT_VERSION_INDEX)
STRING(FIND "${OSG_FILE_CONTENTS}" "OPENSCENEGRAPH_SOVERSION" OSG_VERSION_INDEX)
STRING(FIND "${OSG_FILE_CONTENTS}" "OPENSCENEGRAPH_MAJOR_VERSION" OSGPLUGIN_INDEX0)
STRING(FIND "${OSG_FILE_CONTENTS}" "OPENSCENEGRAPH_MINOR_VERSION" OSGPLUGIN_INDEX1)
STRING(FIND "${OSG_FILE_CONTENTS}" "OPENSCENEGRAPH_PATCH_VERSION" OSGPLUGIN_INDEX2)
MATH(EXPR OT_VERSION_INDEX "${OT_VERSION_INDEX} + 22")
MATH(EXPR OSG_VERSION_INDEX "${OSG_VERSION_INDEX} + 25")
MATH(EXPR OSGPLUGIN_INDEX0 "${OSGPLUGIN_INDEX0} + 29")
MATH(EXPR OSGPLUGIN_INDEX1 "${OSGPLUGIN_INDEX1} + 29")
MATH(EXPR OSGPLUGIN_INDEX2 "${OSGPLUGIN_INDEX2} + 29")
STRING(SUBSTRING "${OT_FILE_CONTENTS}" "${OT_VERSION_INDEX}" "4" OT_VERSION)
STRING(SUBSTRING "${OSG_FILE_CONTENTS}" "${OSG_VERSION_INDEX}" "12" OSG_VERSION)
STRING(SUBSTRING "${OSG_FILE_CONTENTS}" "${OSGPLUGIN_INDEX0}" "5" OSG_MAJOR_VERSION)
STRING(SUBSTRING "${OSG_FILE_CONTENTS}" "${OSGPLUGIN_INDEX1}" "5" OSG_MINOR_VERSION)
STRING(SUBSTRING "${OSG_FILE_CONTENTS}" "${OSGPLUGIN_INDEX2}" "5" OSG_PATCH_VERSION)
STRING(STRIP ${OT_VERSION} OT_VERSION)
STRING(STRIP ${OSG_VERSION} OSG_VERSION)
STRING(STRIP ${OSG_MAJOR_VERSION} OSG_MAJOR_VERSION)
STRING(STRIP ${OSG_MINOR_VERSION} OSG_MINOR_VERSION)
STRING(STRIP ${OSG_PATCH_VERSION} OSG_PATCH_VERSION)
IF(VERSE_USE_OSG_STATIC)
IF(MSVC)
SET(OSG_VERSION_THREADS "ot${OT_VERSION}-")
SET(OSG_VERSION_CORE "osg${OSG_VERSION}-")
ENDIF(MSVC)
SET(OSG_LIB_DIR ${OSG_LIB_DIR}
"${OSG_LIB_DIR}/osgPlugins-${OSG_MAJOR_VERSION}.${OSG_MINOR_VERSION}.${OSG_PATCH_VERSION}")
ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
ENDIF(VERSE_USE_OSG_STATIC)
ENDIF(OSG_BUILD_INCLUDE_DIR)
######################################### Optional Dependencies
MESSAGE("[osgVerse] Automatically Search for Dependencies in ${THIRDPARTY_ROOT}...")
FIND_DEPENDENCE(BULLET "btBulletDynamicsCommon.h" "libBulletDynamics.so;libBulletDynamics.a;BulletDynamics.lib" "bullet")
FIND_DEPENDENCE(DRACO "draco/draco_features.h" "libdraco.so;libdraco.a;draco.lib" "")
FIND_DEPENDENCE(EFFEKSEER "Effekseer.h" "libEffekseer.so;libEffekseer.a;Effekseer.lib" "")
FIND_DEPENDENCE(LIBCEF "cef_browser.h" "libcef.so;libcef.a;libcef.lib" "libcef")
FIND_DEPENDENCE(LIBIGL "igl/igl_inline.h" "" "")
FIND_DEPENDENCE(MIMALLOC "mimalloc.h" "libmimalloc.so;mimalloc.lib" "mimalloc")
IF(NOT USE_WASM_OPTIONS)
FIND_DEPENDENCE(SDL2 "SDL.h" "libSDL2.so;libSDL2.a;SDL2.lib" "SDL")
IF(VERSE_USE_EXTERNAL_GLES)
FIND_DEPENDENCE(VULKAN "vulkan/vulkan.h" "" "")
ENDIF(VERSE_USE_EXTERNAL_GLES)
ENDIF(NOT USE_WASM_OPTIONS)
IF(MIMALLOC_FOUND)
SET(VERSE_USE_MIMALLOC ON CACHE BOOL "Enable use of mi-malloc to improve memory allocating" FORCE)
ENDIF(MIMALLOC_FOUND)
######################################### Platform Definintions
ADD_DEFINITIONS(-DPREPENDED_HEADER="pipeline/Allocator.h")
IF(VERSE_USE_MIMALLOC)
# TODO: static building support?
SET(EXTERNAL_LIBRARIES mimalloc ${EXTERNAL_LIBRARIES})
INCLUDE_DIRECTORIES(${MIMALLOC_INCLUDE_DIR}/mimalloc)
ADD_DEFINITIONS(-DVERSE_USE_MIMALLOC)
ENDIF(VERSE_USE_MIMALLOC)
IF(ANDROID)
ADD_DEFINITIONS(-DVERSE_ANDROID)
SET(VERSE_PLATFORM "Android")
ELSEIF(IOS)
ADD_DEFINITIONS(-DVERSE_IOS)
SET(VERSE_PLATFORM "IOS")
ELSEIF(WIN32 OR MINGW OR CYGWIN)
IF(USE_UWP_OPTIONS)
ADD_DEFINITIONS(-DVERSE_UWP -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS)
ELSEIF(MSVC)
ADD_DEFINITIONS(-DVERSE_MSVC -DNOMINMAX)
IF(MSVC_VERSION LESS 1910)
ADD_DEFINITIONS(-DVERSE_MSVC14)
ENDIF()
ELSEIF(MINGW OR CYGWIN)
ADD_DEFINITIONS(-DVERSE_MINGW -DWIN32_HAS_PTHREADS)
ENDIF()
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} Ws2_32 Winmm imm32 Ole32 OleAut32 Dbghelp)
ADD_DEFINITIONS(-DVERSE_WINDOWS)
SET(VERSE_PLATFORM "Windows")
ELSEIF(APPLE)
ADD_DEFINITIONS(-DVERSE_APPLE)
SET(VERSE_PLATFORM "MacOSX")
# TODO
ELSE()
IF(NOT USE_WASM_OPTIONS)
FIND_PACKAGE(X11)
IF(VERSE_USE_DWARF)
ADD_DEFINITIONS(-DBACKWARD_HAS_DW=1)
FIND_PATH(DW_INCLUDE_DIR dwarf.h PATHS /usr/include /usr/local/include)
FIND_LIBRARY(DW_LIBRARY NAMES dw HINTS /usr/${FIND_LIB_POSTFIX} /usr/local/${FIND_LIB_POSTFIX})
SET(EXTERNAL_INCLUDES ${EXTERNAL_INCLUDES} ${DW_INCLUDE_DIR})
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${DW_LIBRARY})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
ENDIF(VERSE_USE_DWARF)
IF(VERSE_USE_GLIBCXX11_ABI)
ADD_DEFINITIONS(-D_GLIBCXX_USE_CXX11_ABI=1)
ELSE(VERSE_USE_GLIBCXX11_ABI)
ADD_DEFINITIONS(-D_GLIBCXX_USE_CXX11_ABI=0)
ENDIF(VERSE_USE_GLIBCXX11_ABI)
IF(X11_FOUND)
SET(EXTERNAL_LIBRARIES ${EXTERNAL_LIBRARIES} ${X11_LIBRARIES})
ADD_DEFINITIONS(-DVERSE_X11)
ENDIF(X11_FOUND)
SET(VERSE_PLATFORM "Linux")
ELSE()
SET(VERSE_PLATFORM "Emscripten")
ENDIF()
ADD_DEFINITIONS(-DVERSE_UNIX)
ENDIF()
STRING(FIND "${CMAKE_C_COMPILER}" "icx" INTEL_COMPILER_INDEX)
IF(INTEL_COMPILER_INDEX GREATER -1)
ADD_DEFINITIONS(-DINTEL_COMPILER -DRAPIDJSON_HAS_CXX11_RVALUE_REFS=1 -DRAPIDJSON_HAS_CXX11_NOEXCEPT=1)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++14")
ELSEIF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ELSEIF(USE_WASM_OPTIONS)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-template-arg-list-after-template-kw")
ENDIF()
IF(VERSE_STATIC_BUILD)
ADD_DEFINITIONS(-DVERSE_STATIC_BUILD)
ENDIF(VERSE_STATIC_BUILD)
IF(USE_WASM_OPTIONS)
ADD_DEFINITIONS(-DVERSE_WASM)
IF(VERSE_USE_EXTERNAL_GLES3)
ADD_DEFINITIONS(-DVERSE_WEBGL2)
ELSE()
ADD_DEFINITIONS(-DVERSE_WEBGL1)
ENDIF()
ENDIF(USE_WASM_OPTIONS)
######################################### Subdirectories
IF(OSG_INCLUDE_DIR AND OSG_LIB_DIR)
IF(OSG_BUILD_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${OSG_BUILD_INCLUDE_DIR})
ENDIF(OSG_BUILD_INCLUDE_DIR)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${OSG_INCLUDE_DIR} . 3rdparty
"${CMAKE_BINARY_DIR}/3rdparty")
LINK_DIRECTORIES(${OSG_LIB_DIR} .)
ADD_DEFINITIONS(-DINSTALL_PATH_PREFIX="${CMAKE_INSTALL_PREFIX}")
IF(VERSE_BUILD_3RDPARTIES)
MESSAGE(STATUS "[osgVerse] Build third-party libraries under helpers/toolchain_builder.")
ADD_SUBDIRECTORY(helpers/toolchain_builder)
SET(THIRDPARTY_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/helpers/toolchain_builder/freetype/include
${CMAKE_SOURCE_DIR}/helpers/toolchain_builder/jpeg ${CMAKE_SOURCE_DIR}/helpers/toolchain_builder/png
${CMAKE_SOURCE_DIR}/helpers/toolchain_builder/zlib)
SET(THIRDPARTY_LIBRARIES freetype jpeg png zlib)
SET_PROPERTY(GLOBAL APPEND PROPERTY VERSE_PLUGIN_LIBRARIES "${THIRDPARTY_LIBRARIES}")
ELSE(VERSE_BUILD_3RDPARTIES)
IF(JPEG_INCLUDE_DIR AND PNG_PNG_INCLUDE_DIR AND ZLIB_INCLUDE_DIR)
SET(THIRDPARTY_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_freetype2} ${FREETYPE_INCLUDE_DIR_ft2build}
${JPEG_INCLUDE_DIR} ${PNG_PNG_INCLUDE_DIR}${ZLIB_INCLUDE_DIR})
SET(THIRDPARTY_LIBRARIES ${FREETYPE_LIBRARY_RELEASE} ${JPEG_LIBRARY_RELEASE} ${PNG_LIBRARY_RELEASE} ${ZLIB_LIBRARY_RELEASE})
SET_PROPERTY(GLOBAL APPEND PROPERTY VERSE_PLUGIN_LIBRARIES "${THIRDPARTY_LIBRARIES}")
ELSE()
MESSAGE("[osgVerse] Common third-party libraries not found. Some modules and functionalities will be ignored.")
ENDIF()
ENDIF(VERSE_BUILD_3RDPARTIES)
ADD_SUBDIRECTORY(3rdparty)
ADD_SUBDIRECTORY(readerwriter)
ADD_SUBDIRECTORY(pipeline)
ADD_SUBDIRECTORY(animation)
ADD_SUBDIRECTORY(modeling)
ADD_SUBDIRECTORY(ai)
ADD_SUBDIRECTORY(script)
ADD_SUBDIRECTORY(ui)
ADD_SUBDIRECTORY(wrappers)
ADD_SUBDIRECTORY(plugins)
IF(VERSE_BUILD_EXPORTERS)
ADD_SUBDIRECTORY(helpers/3dsmax_exporter)
ENDIF(VERSE_BUILD_EXPORTERS)
IF(USE_WASM_OPTIONS)
MESSAGE(STATUS "[osgVerse] Emscripten / WebAssembly toolchain is used. (WebGL2 = ${VERSE_USE_EXTERNAL_GLES3})")
IF(BUILD_WASM_64)
MESSAGE(STATUS "[osgVerse] Experimental WASM 64bit is enabled. "
"Remember to open chrome://flags and enable 'WebAssembly Memory64'")
ENDIF()
ADD_SUBDIRECTORY(wasm)
ELSEIF(ANDROID)
MESSAGE(STATUS "[osgVerse] Android toolchain is used. (API = ${VERSE_GRAPHICS_API})")
# Nothing else to do... Start 'Android Studio' to continue compiling examples
ELSEIF(IOS)
MESSAGE(STATUS "[osgVerse] IOS toolchain is used. (API = ${VERSE_GRAPHICS_API})")
# Add demo project here?
ELSE()
MESSAGE(STATUS "[osgVerse] Desktop toolchain is used. (API = ${VERSE_GRAPHICS_API})")
ADD_SUBDIRECTORY(applications)
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(assets)
ENDIF()
GET_PROPERTY(VERSE_DEPENDENCIES_TO_SHOW GLOBAL PROPERTY VERSE_DEPENDENCIES)
MESSAGE(STATUS "[osgVerse] OpenSceneGraph version: ${OSG_MAJOR_VERSION}.${OSG_MINOR_VERSION}.${OSG_PATCH_VERSION}"
"; osgVerse version: ${VERSE_VERSION} (${VERSE_PLATFORM})")
MESSAGE(STATUS "[osgVerse] Dependency libraries: ${VERSE_DEPENDENCIES_TO_SHOW}")
CONFIGURE_FILE(cmake/osgVerseConfig.cmake.in "${CMAKE_INSTALL_PREFIX}/lib/osgVerse/osgVerseConfig.cmake" @ONLY)
INSTALL(FILES VerseCommon.h DESTINATION ${INSTALL_INCDIR}/osgVerse COMPONENT libosgverse-dev)
ELSE(OSG_INCLUDE_DIR AND OSG_LIB_DIR)
MESSAGE(FATAL_ERROR "[osgVerse] Dependency OpenSceneGraph not found. NOTHING will be created...")
ENDIF(OSG_INCLUDE_DIR AND OSG_LIB_DIR)