-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
305 lines (247 loc) · 9.28 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
##
# Copyright (c) 2022 WaterSurfaceRendering authors Distributed under MIT License
# (http://opensource.org/licenses/MIT)
##
cmake_minimum_required(VERSION 3.16)
project(water VERSION 1.1 LANGUAGES CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(VKP_ENABLE_PROFILING "Enable recording of profiling data" ON)
option(VKP_ENABLE_LOGGING "Enable debug logging" ON)
option(VKP_ENABLE_ASSERTS "Enable assertions" ON)
# ------------------------------------------------------------------------------
# Setup directories
set(BUILD_DIR "${CMAKE_BINARY_DIR}")
set(LIBS_DIR "${CMAKE_SOURCE_DIR}/libs")
set(SRC_DIR "${CMAKE_SOURCE_DIR}/src")
set(SHADERS_DIR "${SRC_DIR}/shaders")
set(TEXTURES_DIR "${CMAKE_SOURCE_DIR}/textures")
set(MODELS_DIR "${CMAKE_SOURCE_DIR}/models")
# ==============================================================================
# Libraries
# OS Dependencies
find_package(Vulkan REQUIRED)
if(UNIX)
find_package(X11 REQUIRED)
find_package(Threads REQUIRED)
endif()
# ----------------------------------------------------------
# spdlog
# https://github.com/gabime/spdlog
set(SPDLOG_DIR "${LIBS_DIR}/spdlog")
set(SPDLOG_INCLUDE_DIR "${SPDLOG_DIR}/include")
set(SPDLOG_BINARY_DIR "${BUILD_DIR}/spdlog")
add_subdirectory(${SPDLOG_DIR} ${SPDLOG_BINARY_DIR})
# ----------------------------------------------------------
# GLFW
# https://www.glfw.org/
set(GLFW_DIR "${LIBS_DIR}/glfw")
set(GLFW_INCLUDE_DIR "${GLFW_DIR}/include")
set(GLFW_BINARY_DIR "${BUILD_DIR}/glfw")
set(GLFW_LIBRARY_TYPE "STATIC" CACHE INTERNAL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "" FORCE)
set(GLFW_INSTALL OFF CACHE INTERNAL "" FORCE)
set(GLFW_DOCUMENT_INTERNALS OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${GLFW_DIR} ${GLFW_BINARY_DIR} EXCLUDE_FROM_ALL)
set(GLFW_LIBRARIES glfw)
if(UNIX)
set(GLFW_LIBRARIES ${GLFW_LIBRARIES} ${VULKAN_LIBRARIES} ${X11_LIBRARIES}
${X11_Xrandr_LIB} ${X11_Xcursor_LIB} ${X11_Xinerama_LIB}
${X11_Xxf86vm_LIB}
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}
)
else()
# TODO Windows and others
endif()
# ----------------------------------------------------------
# Dear ImGui
# https://github.com/ocornut/imgui
set(IMGUI_DIR "${LIBS_DIR}/imgui")
set(IMGUI_INCLUDE_DIR "${LIBS_DIR}")
set(IMGUI_BINARY_DIR "${BUILD_DIR}/imgui")
set(IMGUI_SOURCES
"${IMGUI_DIR}/imgui.cpp"
"${IMGUI_DIR}/imgui_draw.cpp"
"${IMGUI_DIR}/imgui_demo.cpp"
"${IMGUI_DIR}/imgui_tables.cpp"
"${IMGUI_DIR}/imgui_widgets.cpp"
"${IMGUI_DIR}/backends/imgui_impl_glfw.cpp"
"${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp"
)
add_library(imgui ${IMGUI_SOURCES})
add_dependencies(imgui glfw)
target_link_libraries(imgui ${GLFW_LIBRARIES})
target_include_directories(imgui
PRIVATE ${GLFW_INCLUDE_DIR}
PUBLIC ${IMGUI_DIR}
)
#target_compile_options(imgui PRIVATE "-DVK_NO_PROTOTYPES")
# ----------------------------------------------------------
# libshaderc
# https://github.com/google/shaderc
# linking info: https://github.com/google/shaderc/blob/main/libshaderc/README.md
set(SHADERC_DIR "${LIBS_DIR}/shaderc")
set(SHADERC_INCLUDE_DIR "${SHADERC_DIR}/libshaderc/include")
set(SHADERC_BINARY_DIR "${BUILD_DIR}/shaderc")
set(SHADERC_SKIP_INSTALL ON CACHE INTERNAL "" FORCE)
set(SHADERC_SKIP_TESTS ON CACHE INTERNAL "" FORCE)
set(SHADERC_SKIP_EXAMPLES ON CACHE INTERNAL "" FORCE)
set(SHADERC_SKIP_COPYRIGHT_CHECK ON CACHE INTERNAL "" FORCE)
set(SPRIV_TOOLS_DIR "${SHADERC_DIR}/third_party/spirv-tools")
# Run ./utils/git-sync-deps to pull SPIRV-Tools into third_party/
# https://github.com/google/shaderc/issues/1162
if(NOT EXISTS ${SPRIV_TOOLS_DIR})
message(STATUS "Missing spriv-tools. Synchronizing dependencies.")
execute_process(
COMMAND ./utils/git-sync-deps
WORKING_DIRECTORY ${SHADERC_DIR}
OUTPUT_FILE CMD_OUTPUT
)
endif()
set(SKIP_SPIRV_TOOLS_INSTALL ON CACHE INTERNAL "" FORCE)
set(SPIRV_TOOLS_BUILD_STATIC ON CACHE INTERNAL "" FORCE)
set(SPIRV_SKIP_EXECUTABLES ON CACHE INTERNAL "" FORCE)
set(SPIRV_SKIP_TESTS ON CACHE INTERNAL "" FORCE)
set(SPIRV_CHECK_CONTEXT OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${SHADERC_DIR} ${SHADERC_BINARY_DIR} EXCLUDE_FROM_ALL)
# ----------------------------------------------------------
# OpenMP
find_package(OpenMP REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# ----------------------------------------------------------
# FFTW
# http://www.fftw.org/
set(FFTW_DIR "${LIBS_DIR}/fftw")
set(FFTW_INCLUDE_DIR "${FFTW_DIR}/api")
set(FFTW_BINARY_DIR "${BUILD_DIR}/fftw")
include(FetchContent)
FetchContent_Populate(fftw
TMP_DIR "${BUILD_DIR}/temp"
DOWNLOAD_DIR "${BUILD_DIR}/download"
SOURCE_DIR "${FFTW_DIR}"
URL "http://fftw.org/fftw-3.3.10.tar.gz"
URL_MD5 "8ccbf6a5ea78a16dbc3e1306e234cc5c"
)
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
set(BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
set(ENABLE_OPENMP OFF CACHE INTERNAL "" FORCE)
set(ENABLE_THREADS OFF CACHE INTERNAL "" FORCE)
set(ENABLE_FLOAT ON CACHE INTERNAL "" FORCE)
set(ENABLE_SSE OFF CACHE INTERNAL "" FORCE)
set(ENABLE_SSE2 OFF CACHE INTERNAL "" FORCE)
set(ENABLE_AVX ON CACHE INTERNAL "" FORCE)
set(ENABLE_AVX2 OFF CACHE INTERNAL "" FORCE)
add_subdirectory(${FFTW_DIR} ${FFTW_BINARY_DIR})
# ==============================================================================
# Header-only
# Should be able to access them relative to variable LIBS_DIR
# LIBS_DIR variable should already be included in include path
# ----------------------------------------------------------
# GLM
# https://github.com/g-truc/glm
set(GLM_DIR "${LIBS_DIR}/glm")
set(GLM_INCLUDE_DIR "${GLM_DIR}")
# ----------------------------------------------------------
# STB: stb_image
# https://github.com/nothings/stb
set(STB_DIR "${LIBS_DIR}/stb")
set(STB_INCLUDE_DIR "${LIBS_DIR}")
# ==============================================================================
# ==============================================================================
# ==============================================================================
set(MAIN_DIR "${SRC_DIR}")
set(MAIN_INCLUDE_DIR "${SRC_DIR}")
set(MAIN_CORE_DIR "${MAIN_DIR}/core")
set(MAIN_VULKAN_DIR "${MAIN_DIR}/vulkan")
set(MAIN_SCENE_DIR "${MAIN_DIR}/scene")
# TODO file(GLOB sources *.cpp)
set(MAIN_SOURCES
"${MAIN_CORE_DIR}/Log.cpp"
"${MAIN_CORE_DIR}/Profile.cpp"
"${MAIN_VULKAN_DIR}/utils.cpp"
"${MAIN_VULKAN_DIR}/Instance.cpp"
"${MAIN_VULKAN_DIR}/PhysicalDevice.cpp"
"${MAIN_VULKAN_DIR}/Device.cpp"
"${MAIN_VULKAN_DIR}/Surface.cpp"
"${MAIN_VULKAN_DIR}/Image.cpp"
"${MAIN_VULKAN_DIR}/ImageView.cpp"
"${MAIN_VULKAN_DIR}/SwapChain.cpp"
"${MAIN_VULKAN_DIR}/Buffer.cpp"
"${MAIN_VULKAN_DIR}/CommandBuffer.cpp"
"${MAIN_VULKAN_DIR}/CommandPool.cpp"
"${MAIN_VULKAN_DIR}/ShaderModule.cpp"
"${MAIN_VULKAN_DIR}/RenderPass.cpp"
"${MAIN_VULKAN_DIR}/Pipeline.cpp"
"${MAIN_VULKAN_DIR}/Sampler.cpp"
"${MAIN_VULKAN_DIR}/Texture2D.cpp"
"${MAIN_VULKAN_DIR}/Descriptors.cpp"
"${MAIN_VULKAN_DIR}/Texture3D.cpp"
"${MAIN_VULKAN_DIR}/QueueTypes.cpp"
"${MAIN_CORE_DIR}/Window.cpp"
"${MAIN_DIR}/Gui.cpp"
"${MAIN_CORE_DIR}/Application.cpp"
"${MAIN_SCENE_DIR}/Camera.cpp"
"${MAIN_SCENE_DIR}/SkyPreetham.cpp"
"${MAIN_SCENE_DIR}/SkyModel.cpp"
"${MAIN_SCENE_DIR}/WSTessendorf.cpp"
"${MAIN_SCENE_DIR}/WaterSurfaceMesh.cpp"
"${MAIN_DIR}/WaterSurface.cpp"
"${MAIN_DIR}/main.cpp"
)
add_executable(${PROJECT_NAME}
${MAIN_SOURCES}
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${MAIN_INCLUDE_DIR}
${SPDLOG_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
${GLM_INCLUDE_DIR}
${STB_INCLUDE_DIR}
${IMGUI_INCLUDE_DIR}
${SHADERC_INCLUDE_DIR}
${FFTW_INCLUDE_DIR}
)
add_dependencies(${PROJECT_NAME}
Vulkan::Vulkan
glfw
spdlog::spdlog
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${GLFW_LIBRARIES}
PRIVATE Vulkan::Vulkan
PRIVATE spdlog::spdlog
PRIVATE imgui
PRIVATE shaderc
PRIVATE fftw3f
PRIVATE OpenMP::OpenMP_CXX
)
target_precompile_headers(${PROJECT_NAME}
PRIVATE "${SRC_DIR}/pch.h"
)
set(VKP_DEFINITIONS)
if(VKP_ENABLE_LOGGING)
set(VKP_DEFINITIONS "${VKP_DEFINITIONS} -DVKP_DEBUG")
endif()
if(VKP_ENABLE_PROFILING)
set(VKP_DEFINITIONS "${VKP_DEFINITIONS} -DVKP_PROFILE")
endif()
if(VKP_ENABLE_ASSERTS)
set(VKP_DEFINITIONS "${VKP_DEFINITIONS} -DVKP_ENABLE_ASSERTS")
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES
COMPILE_FLAGS "${VKP_DEFINITIONS}"
)
#--------------------------------------------------------------------------------
# Copy assets to build folder
#--------------------------------------------------------------------------------
set(SHADERS_BIN_DIR "${PROJECT_BINARY_DIR}/shaders")
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${SHADERS_DIR}
${SHADERS_BIN_DIR}
COMMENT "Copying shaders to build tree")