-
Notifications
You must be signed in to change notification settings - Fork 172
/
CMakeLists.txt
317 lines (267 loc) · 10.7 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
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.19)
project("IGL" CXX C)
# cmake-format: off
option(IGL_WITH_SAMPLES "Enable sample demo apps" ON)
option(IGL_WITH_OPENGL "Enable IGL/OpenGL" ON)
option(IGL_WITH_OPENGLES "Enable IGL/OpenGL ES" OFF)
option(IGL_WITH_VULKAN "Enable IGL/Vulkan" ON)
option(IGL_WITH_METAL "Enable IGL/Metal" ON)
option(IGL_WITH_WEBGL "Enable IGL/WebGL" OFF)
option(IGL_WITH_IGLU "Enable IGLU utils" ON)
option(IGL_WITH_SHELL "Enable Shell utils" ON)
option(IGL_WITH_TESTS "Enable IGL tests (gtest)" OFF)
option(IGL_WITH_TRACY "Enable Tracy profiler" OFF)
option(IGL_WITH_TRACY_GPU "Enable Tracy profiler for the GPU" OFF)
option(IGL_WITH_OPENXR "Enable OpenXR" OFF)
option(IGL_ENFORCE_LOGS "Enable logs in Release builds" ON)
option(IGL_DEPLOY_DEPS "Deploy dependencies via CMake" ON)
# cmake-format: on
if(DEFINED ENV{VULKAN_SDK})
message(STATUS "VULKAN_SDK=$ENV{VULKAN_SDK}")
if(NOT EXISTS $ENV{VULKAN_SDK})
message(FATAL_ERROR "$ENV{VULKAN_SDK} does not exist.")
endif()
endif()
if(IOS)
if(IGL_WITH_OPENGL)
set(IGL_WITH_OPENGLES ON)
endif()
set(IGL_WITH_OPENGL OFF)
set(IGL_WITH_VULKAN OFF)
set(IGL_WITH_WEBGL OFF)
endif()
if(NOT APPLE)
set(IGL_WITH_METAL OFF)
endif()
if(ANDROID)
if(IGL_WITH_OPENGL)
set(IGL_WITH_OPENGLES ON)
endif()
set(IGL_WITH_OPENGL OFF)
set(IGL_WITH_VULKAN ON)
set(IGL_WITH_WEBGL OFF)
# disable for all targets due to warnings in third-party code
add_definitions(-Wno-nullability-completeness)
add_definitions(-Wno-deprecated-volatile)
elseif(UNIX)
# disable for all targets due to warnings in third-party code
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>)
add_definitions(-Wno-attributes)
endif()
if(EMSCRIPTEN)
if(IGL_WITH_OPENXR)
message(FATAL_ERROR "OpenXR is not supported on Emscripten.")
endif()
set(IGL_WITH_IGLU ON)
set(IGL_WITH_OPENGL OFF)
set(IGL_WITH_OPENGLES OFF)
set(IGL_WITH_VULKAN OFF)
set(IGL_WITH_WEBGL ON)
set(IGL_WITH_SHELL OFF) # shell doesn't supported yet
endif()
include(cmake/helpers.cmake)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# cmake-format: off
message(STATUS "IGL_WITH_SAMPLES = ${IGL_WITH_SAMPLES}")
message(STATUS "IGL_WITH_OPENGL = ${IGL_WITH_OPENGL}")
message(STATUS "IGL_WITH_OPENGLES = ${IGL_WITH_OPENGLES}")
message(STATUS "IGL_WITH_VULKAN = ${IGL_WITH_VULKAN}")
message(STATUS "IGL_WITH_METAL = ${IGL_WITH_METAL}")
message(STATUS "IGL_WITH_WEBGL = ${IGL_WITH_WEBGL}")
message(STATUS "IGL_WITH_IGLU = ${IGL_WITH_IGLU}")
message(STATUS "IGL_WITH_SHELL = ${IGL_WITH_SHELL}")
message(STATUS "IGL_WITH_TESTS = ${IGL_WITH_TESTS}")
message(STATUS "IGL_WITH_TRACY = ${IGL_WITH_TRACY}")
message(STATUS "IGL_WITH_TRACY_GPU = ${IGL_WITH_TRACY_GPU}")
message(STATUS "IGL_WITH_OPENXR = ${IGL_WITH_OPENXR}")
message(STATUS "IGL_ENFORCE_LOGS = ${IGL_ENFORCE_LOGS}")
message(STATUS "IGL_DEPLOY_DEPS = ${IGL_DEPLOY_DEPS}")
# cmake-format: on
if(APPLE)
if(IGL_WITH_OPENXR)
message(FATAL_ERROR "OpenXR is not supported on Apple (yet).")
endif()
if(NOT (IGL_WITH_OPENGL OR IGL_WITH_VULKAN OR IGL_WITH_OPENGLES OR IGL_WITH_METAL OR IGL_WITH_WEBGL))
message(FATAL_ERROR "At least one rendering backend should be defined (OpenGL, Vulkan or Metal).")
endif()
else()
if(NOT (IGL_WITH_OPENGL OR IGL_WITH_VULKAN OR IGL_WITH_OPENGLES OR IGL_WITH_WEBGL))
message(FATAL_ERROR "At least one rendering backend should be defined (OpenGL or Vulkan).")
endif()
endif()
if(IGL_WITH_SHELL AND (NOT IGL_WITH_IGLU))
message(FATAL_ERROR "IGL_WITH_SHELL requires enabling IGL_WITH_IGLU.")
endif()
if(APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
endif()
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
message(STATUS "IGL generator : " ${CMAKE_GENERATOR})
message(STATUS "IGL build type: " ${CMAKE_BUILD_TYPE})
set(IGL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(IGL_DEPS_CACHE_FILE "${IGL_ROOT_DIR}/third-party/.bootstrap-deps.json")
find_package(Python3 COMPONENTS Interpreter)
message(STATUS "IGL_ROOT_DIR = " ${IGL_ROOT_DIR})
# Enables multithreaded compilation and a conformant preprocessor on visual studio
if(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
if(IGL_DEPLOY_DEPS)
# deploy dependencies during configuration
execute_process(COMMAND ${Python3_EXECUTABLE} deploy_deps.py WORKING_DIRECTORY ${IGL_ROOT_DIR} COMMAND_ERROR_IS_FATAL ANY)
if(NOT EXISTS ${IGL_DEPS_CACHE_FILE})
message(FATAL_ERROR "Cannot deploy dependencies.")
endif()
# regenerate dependencies when .bootstrap-deps.json is older than bootstrap-deps.json
add_custom_command(COMMAND ${Python3_EXECUTABLE} deploy_deps.py OUTPUT ${IGL_DEPS_CACHE_FILE}
DEPENDS "${IGL_ROOT_DIR}/third-party/bootstrap-deps.json" WORKING_DIRECTORY ${IGL_ROOT_DIR})
add_custom_target(IGLDependencies DEPENDS ${IGL_DEPS_CACHE_FILE})
igl_set_folder(IGLDependencies "IGL")
endif()
if (NOT IGL_WITH_TRACY AND IGL_WITH_TRACY_GPU)
message(FATAL_ERROR "IGL_WITH_TRACY must be enabled to use Tracy's GPU profiling")
endif()
if(IGL_WITH_TRACY)
add_definitions("-DTRACY_ENABLE=1")
add_subdirectory(third-party/deps/src/tracy)
igl_set_folder(TracyClient "third-party")
endif()
if(IGL_WITH_OPENXR)
add_subdirectory(third-party/deps/src/openxr-sdk)
igl_set_folder(openxr_loader "third-party/OpenXR")
endif()
add_subdirectory(src/igl)
if(IGL_WITH_TRACY)
target_compile_definitions(IGLLibrary PUBLIC "IGL_WITH_TRACY=1")
if(IGL_WITH_TRACY_GPU)
target_compile_definitions(IGLLibrary PUBLIC "IGL_WITH_TRACY_GPU=1")
endif()
endif()
if(IGL_DEPLOY_DEPS)
add_dependencies(IGLLibrary IGLDependencies)
endif()
if(IGL_ENFORCE_LOGS)
target_compile_definitions(IGLLibrary PUBLIC "IGL_FORCE_ENABLE_LOGS=1")
endif()
if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT EMSCRIPTEN)
if(IGL_WITH_SAMPLES OR IGL_WITH_SHELL)
target_compile_definitions(IGLLibrary PUBLIC "IGL_PLATFORM_LINUX_USE_EGL=0")
else()
target_compile_definitions(IGLLibrary PUBLIC "IGL_PLATFORM_LINUX_USE_EGL=1")
endif()
endif()
# in the client code, use IGL_BACKEND_* macros instead of IGL_BACKEND_ENABLE_*
if(IGL_WITH_OPENGL)
target_compile_definitions(IGLLibrary PUBLIC "IGL_BACKEND_ENABLE_OPENGL=1")
endif()
if(IGL_WITH_OPENGLES OR IGL_WITH_WEBGL)
target_compile_definitions(IGLLibrary PUBLIC "IGL_BACKEND_ENABLE_OPENGL=1")
endif()
if(IGL_WITH_VULKAN)
target_compile_definitions(IGLLibrary PUBLIC "IGL_BACKEND_ENABLE_VULKAN=1")
endif()
if(IGL_WITH_IGLU)
target_compile_definitions(IGLLibrary PUBLIC "IGL_WITH_IGLU=1")
endif()
if(APPLE AND IGL_WITH_METAL)
target_compile_definitions(IGLLibrary PUBLIC "IGL_BACKEND_ENABLE_METAL=1")
endif()
target_compile_definitions(IGLLibrary PUBLIC "IGL_CMAKE_BUILD=1")
include_directories(.)
if(IGL_WITH_IGLU OR IGL_WITH_SAMPLES)
add_library(IGLstb third-party/deps/patches/stb_impl/stb_image.c third-party/deps/patches/stb_impl/stb_image_resize.c
third-party/deps/patches/stb_impl/stb_image_write.c)
target_include_directories(IGLstb PUBLIC "third-party/deps/src/stb")
target_include_directories(IGLstb PUBLIC "third-party/deps/src")
igl_set_folder(IGLstb "IGL")
endif()
if (IGL_WITH_IGLU)
include_directories("third-party/deps/src/imgui")
add_subdirectory(IGLU)
if(IGL_WITH_SHELL)
include_directories("third-party/deps/src/stb")
add_subdirectory(shell)
endif()
endif()
if(IGL_WITH_SAMPLES)
if (EMSCRIPTEN)
add_subdirectory(samples/wasm)
else()
include_directories("third-party/deps/src")
include_directories("third-party/deps/src/bc7enc")
include_directories("third-party/deps/src/gli")
include_directories("third-party/deps/src/glm")
include_directories("third-party/deps/src/stb")
include_directories("third-party/deps/src/taskflow")
include_directories("third-party/deps/src/3D-Graphics-Rendering-Cookbook")
if(WIN32 OR (UNIX AND NOT APPLE AND NOT ANDROID))
# cmake-format: off
set(GLFW_BUILD_DOCS OFF CACHE BOOL "")
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "")
set(GLFW_BUILD_TESTS OFF CACHE BOOL "")
set(GLFW_INSTALL OFF CACHE BOOL "")
set(GLFW_VULKAN_STATIC OFF CACHE BOOL "")
# cmake-format: on
add_subdirectory(third-party/deps/src/glfw)
igl_set_folder(update_mappings "third-party/GLFW3")
endif()
if(UNIX AND NOT APPLE AND NOT ANDROID)
find_package(OpenGL REQUIRED)
endif()
add_subdirectory(third-party/deps/src/bc7enc)
igl_set_cxxstd(bc7enc 17)
add_subdirectory(third-party/deps/src/meshoptimizer)
add_subdirectory(third-party/deps/src/tinyobjloader)
igl_set_folder(bc7enc "third-party")
igl_set_folder(meshoptimizer "third-party")
igl_set_folder(tinyobjloader "third-party/tinyobjloader")
igl_set_folder(uninstall "third-party/tinyobjloader")
if(NOT APPLE AND NOT ANDROID)
add_subdirectory(samples/desktop)
igl_set_folder(glfw "third-party/GLFW3")
endif()
endif()
endif()
if (IGL_WITH_VULKAN OR IGL_WITH_IGLU OR IGL_WITH_SAMPLES)
add_subdirectory(third-party/deps/src/fmt "fmt")
igl_set_folder(fmt "third-party")
endif()
if (IGL_WITH_IGLU OR IGL_WITH_SAMPLES)
set(KTX_FEATURE_DOC OFF CACHE BOOL "")
if (NOT EMSCRIPTEN)
set(KTX_FEATURE_GL_UPLOAD OFF CACHE BOOL "")
endif()
set(KTX_FEATURE_JNI OFF CACHE BOOL "")
set(KTX_FEATURE_KTX1 ON CACHE BOOL "")
set(KTX_FEATURE_KTX2 ON CACHE BOOL "")
set(KTX_FEATURE_LOADTEST_APPS OFF CACHE BOOL "")
set(KTX_FEATURE_STATIC_LIBRARY ON CACHE BOOL "")
set(KTX_FEATURE_TESTS OFF CACHE BOOL "")
set(KTX_FEATURE_TOOLS OFF CACHE BOOL "")
set(KTX_FEATURE_VK_UPLOAD OFF CACHE BOOL "")
add_subdirectory(third-party/deps/src/ktx-software)
if(TARGET astcenc-avx2-static)
igl_set_folder(astcenc-avx2-static "third-party/ktx-software")
endif()
igl_set_folder(ktx "third-party/ktx-software")
igl_set_folder(ktx_read "third-party/ktx-software")
igl_set_folder(ktx_version "third-party/ktx-software")
igl_set_folder(obj_basisu_cbind "third-party/ktx-software")
igl_set_folder(objUtil "third-party/ktx-software")
endif()
if(IGL_WITH_TRACY)
target_link_libraries(IGLLibrary PUBLIC TracyClient)
endif()
if(IGL_WITH_OPENXR)
target_compile_definitions(IGLLibrary PUBLIC "IGL_WITH_OPENXR=1")
target_link_libraries(IGLLibrary PUBLIC OpenXR::openxr_loader)
target_include_directories(IGLLibrary PUBLIC "${IGL_ROOT_DIR}/third-party/deps/src/openxr-sdk/include")
endif()