forked from facebook/igl
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCMakeLists.txt
296 lines (248 loc) · 10.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
# 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)
include(CMakeDependentOption)
include(FetchContent)
project("LVK" CXX C)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# cmake-format: off
option(LVK_DEPLOY_DEPS "Deploy dependencies via CMake" ON)
option(LVK_WITH_GLFW "Enable GLFW" ON)
option(LVK_WITH_SAMPLES "Enable sample demo apps" ON)
option(LVK_WITH_SAMPLES_ANDROID "Generate Android projects for demo apps" OFF)
option(LVK_WITH_TRACY "Enable Tracy profiler" ON)
option(LVK_WITH_TRACY_GPU "Enable Tracy GPU profiler" OFF)
option(LVK_WITH_WAYLAND "Enable Wayland" OFF)
option(LVK_WITH_IMPLOT "Enable ImPlot" ON)
option(LVK_WITH_OPENXR "Enable OpenXR" OFF)
option(LVK_WITH_ANDROID_VALIDATION "Enable validation layers on Android" ON)
option(LVK_WITH_SLANG "Enable Slang compiler" OFF)
cmake_dependent_option(LVK_WITH_VULKAN_PORTABILITY "Enable portability extension" ON "APPLE" OFF)
set(LVK_ANDROID_ABI "arm64-v8a" CACHE STRING "Enabled ABI on Android")
set(LVK_CUSTOM_MOLTENVK_PATH "" CACHE STRING "Path to custom MoltenVK")
# cmake-format: on
if(LVK_WITH_SAMPLES AND NOT LVK_WITH_GLFW)
message(STATUS "WARNING: Setting LVK_WITH_SAMPLES=ON forces LVK_WITH_GLFW=ON")
set(LVK_WITH_GLFW ON)
endif()
if(ANDROID)
message(STATUS "WARNING: LVK_WITH_GLFW and LVK_WITH_SLANG were set to OFF for Android")
set(LVK_WITH_GLFW OFF)
set(LVK_WITH_SLANG OFF)
endif()
if(LVK_WITH_TRACY_GPU AND NOT LVK_WITH_TRACY)
message(STATUS "WARNING: Setting LVK_WITH_TRACY_GPU=ON forces LVK_WITH_TRACY=ON")
set(LVK_WITH_TRACY ON)
endif()
if(LVK_WITH_WAYLAND AND (ANDROID OR APPLE OR WIN32))
message(FATAL_ERROR "LVK_WITH_WAYLAND=ON can be set only on Linux")
endif()
if(APPLE)
if(EXISTS ${LVK_CUSTOM_MOLTENVK_PATH})
message("Custom MoltenVK found at ${LVK_CUSTOM_MOLTENVK_PATH}")
set(LVK_USE_CUSTOM_MOLTENVK ON)
else()
if(NOT LVK_WITH_VULKAN_PORTABILITY)
message(FATAL_ERROR "LVK_WITH_VULKAN_PORTABILITY=ON must be set on macOS if Vulkan SDK is used")
endif()
set(LVK_USE_CUSTOM_MOLTENVK OFF)
endif()
endif()
include(cmake/CommonMacros.txt)
if(NOT LVK_USE_CUSTOM_MOLTENVK AND 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()
function(lvk_set_folder target folder_name)
set_property(TARGET ${target} PROPERTY FOLDER ${folder_name})
endfunction()
function(lvk_set_cxxstd target cpp_version)
set_property(TARGET ${target} PROPERTY CXX_STANDARD ${cpp_version})
set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED ON)
endfunction()
# cmake-format: off
message(STATUS "LVK_DEPLOY_DEPS = ${LVK_DEPLOY_DEPS}")
message(STATUS "LVK_WITH_GLFW = ${LVK_WITH_GLFW}")
message(STATUS "LVK_WITH_SAMPLES = ${LVK_WITH_SAMPLES}")
message(STATUS "LVK_WITH_SAMPLES_ANDROID = ${LVK_WITH_SAMPLES_ANDROID}")
message(STATUS "LVK_WITH_TRACY = ${LVK_WITH_TRACY}")
message(STATUS "LVK_WITH_TRACY_GPU = ${LVK_WITH_TRACY_GPU}")
message(STATUS "LVK_WITH_VULKAN_PORTABILITY = ${LVK_WITH_VULKAN_PORTABILITY}")
message(STATUS "LVK_WITH_WAYLAND = ${LVK_WITH_WAYLAND}")
message(STATUS "LVK_WITH_IMPLOT = ${LVK_WITH_IMPLOT}")
message(STATUS "LVK_WITH_OPENXR = ${LVK_WITH_OPENXR}")
# cmake-format: on
# cmake-format: off
if(LVK_WITH_SAMPLES_ANDROID)
message(STATUS "LVK_ANDROID_ABI = ${LVK_ANDROID_ABI}")
message(STATUS "LVK_WITH_ANDROID_VALIDATION = ${LVK_WITH_ANDROID_VALIDATION}")
endif()
# cmake-format: on
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
add_compile_options("$<$<CONFIG:DEBUG>:-DDEBUG>")
message(STATUS "Generator : " ${CMAKE_GENERATOR})
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
set(LVK_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LVK_DEPS_CACHE_FILE "${LVK_ROOT_DIR}/third-party/.bootstrap-deps.json")
find_package(Python3 COMPONENTS Interpreter)
message(STATUS "LVK_ROOT_DIR = " ${LVK_ROOT_DIR})
# enable multithreaded builds for Visual Studio
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
if(LVK_DEPLOY_DEPS)
# deploy dependencies during configuration
execute_process(COMMAND ${Python3_EXECUTABLE} deploy_deps.py WORKING_DIRECTORY ${LVK_ROOT_DIR} COMMAND_ERROR_IS_FATAL ANY)
if(NOT EXISTS ${LVK_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 ${LVK_DEPS_CACHE_FILE}
DEPENDS "${LVK_ROOT_DIR}/third-party/bootstrap-deps.json" WORKING_DIRECTORY ${LVK_ROOT_DIR})
add_custom_target(LVKDependencies DEPENDS ${LVK_DEPS_CACHE_FILE})
lvk_set_folder(LVKDependencies "LVK")
if(LVK_WITH_SLANG)
FetchContent_Populate(
slang
GIT_REPOSITORY https://github.com/shader-slang/slang
GIT_TAG v2024.9.2
SOURCE_DIR ${LVK_ROOT_DIR}/third-party/deps/src/slang
)
endif()
endif()
if(LVK_WITH_WAYLAND)
include(${LVK_ROOT_DIR}/third-party/deps/src/cmake-wayland/FindWayland.cmake)
if(NOT WAYLAND_FOUND)
message(FATAL_ERROR "Wayland is not found in this OS")
endif()
endif()
if(LVK_WITH_TRACY)
add_definitions("-DTRACY_ENABLE=1")
add_subdirectory(third-party/deps/src/tracy)
lvk_set_folder(TracyClient "third-party")
endif()
if(LVK_WITH_OPENXR)
if(NOT WIN32)
message(FATAL_ERROR "OpenXR can be enabled only on Windows.")
endif()
add_subdirectory(third-party/deps/src/openxr-sdk)
# cmake-format: off
lvk_set_folder(openxr_loader "third-party/OpenXR")
lvk_set_folder(generate_openxr_header "third-party/OpenXR")
lvk_set_folder(xr_common_generated_files "third-party/OpenXR")
lvk_set_folder(xr_global_generated_files "third-party/OpenXR")
# cmake-format: on
endif()
# temporary
if(NOT LVK_USE_CUSTOM_MOLTENVK AND NOT LVK_WITH_SLANG)
find_package(Vulkan REQUIRED)
endif()
include_directories(.)
include_directories(src)
add_subdirectory(lvk)
target_include_directories(LVKLibrary PUBLIC ${LVK_ROOT_DIR})
target_include_directories(LVKLibrary PUBLIC ${LVK_ROOT_DIR}/src)
if(LVK_WITH_TRACY)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_TRACY=1")
if(LVK_WITH_TRACY_GPU)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_TRACY_GPU=1")
endif()
endif()
if(LVK_WITH_GLFW)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_GLFW=1")
endif()
if(LVK_WITH_IMPLOT)
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_IMPLOT=1")
endif()
if(LVK_DEPLOY_DEPS)
add_dependencies(LVKLibrary LVKDependencies)
endif()
add_library(LVKstb third-party/deps/patches/stb_impl/stb_image.c third-party/deps/patches/stb_impl/stb_image_resize2.c
third-party/deps/patches/stb_impl/stb_image_write.c)
target_include_directories(LVKstb PUBLIC "third-party/deps/src/stb")
if(ANDROID)
target_compile_definitions(LVKstb PUBLIC "STBI_NO_SIMD=1")
target_compile_definitions(LVKstb PUBLIC "STBIR_NO_SIMD=1")
endif()
lvk_set_folder(LVKstb "LVK")
# cmake-format: off
set(MINILOG_BUILD_EXAMPLE OFF CACHE BOOL "")
set(MINILOG_RAW_OUTPUT ON CACHE BOOL "")
# cmake-format: on
add_subdirectory(third-party/deps/src/minilog)
lvk_set_folder(minilog "third-party")
target_link_libraries(LVKLibrary PUBLIC minilog)
target_include_directories(LVKLibrary PUBLIC "third-party/deps/src")
if(LVK_WITH_GLFW)
# 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 "")
if(WAYLAND_FOUND)
set(GLFW_BUILD_WAYLAND ON)
set(GLFW_BUILD_X11 OFF)
else()
set(GLFW_BUILD_WAYLAND OFF)
set(GLFW_BUILD_X11 ON)
endif()
add_subdirectory(third-party/deps/src/glfw)
lvk_set_folder(glfw "third-party/GLFW3")
lvk_set_folder(update_mappings "third-party/GLFW3")
# cmake-format: on
endif()
if(LVK_WITH_SAMPLES)
include_directories("third-party/deps/src")
include_directories("third-party/deps/src/ktx-software")
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(UNIX AND NOT ANDROID)
find_package(OpenGL REQUIRED)
endif()
# cmake-format: off
set(KTX_FEATURE_DOC OFF CACHE BOOL "")
set(KTX_FEATURE_GL_UPLOAD OFF CACHE BOOL "")
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 "")
# cmake-format: on
add_subdirectory(third-party/deps/src/ktx-software)
lvk_set_folder(ktx "third-party/ktx-software")
lvk_set_folder(ktx_read "third-party/ktx-software")
lvk_set_folder(ktx_version "third-party/ktx-software")
lvk_set_folder(obj_basisu_cbind "third-party/ktx-software")
lvk_set_folder(objUtil "third-party/ktx-software")
if(TARGET astcenc-avx2-static)
lvk_set_folder(astcenc-avx2-static "third-party/ktx-software")
endif()
add_subdirectory(third-party/deps/src/meshoptimizer)
add_subdirectory(third-party/deps/src/fast_obj)
add_subdirectory(samples)
# cmake-format: off
lvk_set_folder(meshoptimizer "third-party")
lvk_set_folder(fast_obj_lib "third-party")
# cmake-format: on
endif()
if(LVK_WITH_TRACY)
target_link_libraries(LVKLibrary PUBLIC TracyClient)
endif()
if(LVK_WITH_OPENXR)
target_compile_definitions(LVKVulkan PRIVATE "XR_USE_GRAPHICS_API_VULKAN=1")
target_compile_definitions(LVKLibrary PUBLIC "LVK_WITH_OPENXR=1")
target_link_libraries(LVKLibrary PUBLIC OpenXR::openxr_loader)
target_include_directories(LVKLibrary PUBLIC "${LVK_ROOT_DIR}/third-party/deps/src/openxr-sdk/include")
endif()
# ImGui
target_include_directories(LVKLibrary PUBLIC "${LVK_ROOT_DIR}/third-party/deps/src/imgui")