-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmakelists.txt
298 lines (248 loc) · 9.12 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
cmake_minimum_required(VERSION 3.28)
project(lavender VERSION 0.0.0.1)
include(CMakeRC.cmake)
include(FetchContent)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
FetchContent_Declare(glfw
GIT_REPOSITORY https://github.com/glfw/glfw
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_MakeAvailable(glfw)
FetchContent_Declare(concurrentqueue
GIT_REPOSITORY https://github.com/cameron314/concurrentqueue
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_MakeAvailable(concurrentqueue)
FetchContent_Declare(vma
GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_MakeAvailable(vma)
FetchContent_Declare(offsetAllocator
GIT_REPOSITORY https://github.com/sebbbi/offsetAllocator/
GIT_TAG main
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_Populate(offsetAllocator)
FetchContent_Declare(ctti
GIT_REPOSITORY https://github.com/Manu343726/ctti.git
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_Populate(ctti)
FetchContent_Declare(FastNoise2
GIT_REPOSITORY https://github.com/Auburn/FastNoise2/
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_Populate(FastNoise2)
set(FASTNOISE2_NOISETOOL OFF CACHE BOOL "Build Noise Tool" FORCE) #example if don't need the graph tool
add_subdirectory(${fastnoise2_SOURCE_DIR})
FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm
GIT_TAG master
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_MakeAvailable(glm)
target_compile_definitions(glm INTERFACE GLM_FORCE_DEPTH_ZERO_TO_ONE=1)
target_compile_definitions(glm INTERFACE GLM_SWIZZLE=1)
target_compile_definitions(glm INTERFACE GLM_FORCE_RADIANS=1)
target_compile_definitions(glm INTERFACE GLM_FORCE_SIZE_T_LENGTH=1)
target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL=1)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_ENABLE_CMAKE ON)
set(BOOST_INCLUDE_LIBRARIES container unordered dynamic_bitset core type_traits)
message("Downloading boost, this will take some time!")
FetchContent_Declare(
Boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.86.0
GIT_SHALLOW TRUE
SYSTEM
)
FetchContent_MakeAvailable(Boost)
find_package(Vulkan REQUIRED)
add_executable(lavender
src/main.cpp
src/game/ec/entity_component_manager.cpp
src/game/ec/entity_storage.cpp
src/game/camera.cpp
src/game/frame_generator.cpp
src/game/game.cpp
src/game/transform.cpp
src/gfx/vulkan/allocator.cpp
src/gfx/vulkan/buffer_stager.cpp
src/gfx/vulkan/device.cpp
src/gfx/vulkan/frame_manager.cpp
src/gfx/vulkan/image.cpp
src/gfx/vulkan/instance.cpp
src/gfx/vulkan/swapchain.cpp
src/gfx/renderer.cpp
src/gfx/window.cpp
src/shaders/shaders.cpp
src/util/index_allocator.cpp
src/util/log.cpp
src/util/misc.cpp
src/util/range_allocator.cpp
src/verdigris/verdigris.cpp
src/voxel/brick_pointer_allocator.cpp
src/voxel/chunk_manager.cpp
src/voxel/material_manager.cpp
src/voxel/world.cpp
${fastnoise2_SOURCE_DIR}/src/FastNoise/FastNoise_C.cpp
${fastnoise2_SOURCE_DIR}/src/FastNoise/Metadata.cpp
${fastnoise2_SOURCE_DIR}/src/FastNoise/SmartNode.cpp
)
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()
target_include_directories(lavender PUBLIC src)
target_include_directories(lavender SYSTEM PUBLIC ${Vulkan_INCLUDE_DIRS})
target_include_directories(lavender SYSTEM PUBLIC ${vma_SOURCE_DIR}/include)
target_include_directories(lavender SYSTEM PUBLIC ${offsetAllocator_SOURCE_DIR})
target_include_directories(lavender SYSTEM PUBLIC ${ctti_SOURCE_DIR}/include)
target_compile_definitions(lavender PUBLIC LAVENDER_VERSION_MAJOR=${PROJECT_VERSION_MAJOR})
target_compile_definitions(lavender PUBLIC LAVENDER_VERSION_MINOR=${PROJECT_VERSION_MINOR})
target_compile_definitions(lavender PUBLIC LAVENDER_VERSION_PATCH=${PROJECT_VERSION_PATCH})
target_compile_definitions(lavender PUBLIC LAVENDER_VERSION_TWEAK=${PROJECT_VERSION_TWEAK})
target_compile_definitions(lavender INTERFACE FASTSIMD_INCLUDE_HEADER_ONLY=1)
target_compile_definitions(lavender PUBLIC VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1)
target_compile_definitions(lavender PUBLIC VULKAN_HPP_NO_CONSTRUCTORS=1)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
target_compile_definitions(lavender PUBLIC LAVENDER_DEBUG_BUILD=1)
else()
target_compile_definitions(lavender PUBLIC LAVENDER_DEBUG_BUILD=0)
endif()
target_link_libraries(
lavender
PRIVATE
glfw
concurrentqueue
glm
Boost::container
Boost::unordered
Boost::dynamic_bitset
Boost::core
Boost::type_traits
FastNoise
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(lavender PUBLIC
-Weverything
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
-Wno-c++20-compat
-Wno-pre-c++20-compat-pedantic
-Wno-covered-switch-default
-Wno-ctad-maybe-unsupported
-Wno-pre-c++17-compat
-Wno-braced-scalar-init
-Wno-unsafe-buffer-usage
-Wno-gnu-zero-line-directive
-Wno-missing-prototypes
-Wno-switch-enum
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
# Add debug symbols that lldb can actually read
target_compile_options(lavender PUBLIC -glldb)
target_compile_options(lavender PUBLIC -gdwarf-4)
target_compile_options(lavender PUBLIC -g3)
# target_compile_options(lavender PUBLIC -fsanitize=thread)
# target_link_options(lavender PUBLIC -fsanitize=thread)
# target_compile_options(lavender PUBLIC -fsanitize=undefined)
# target_link_options(lavender PUBLIC -fsanitize=undefined)
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(lavender PUBLIC
-Wno-braced-scalar-init
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
# Add debug symbols that lldb can actually read
target_compile_options(lavender PUBLIC -glldb)
target_compile_options(lavender PUBLIC -gdwarf-4)
target_compile_options(lavender PUBLIC -g3)
# target_compile_options(lavender PUBLIC -fsanitize=thread)
# target_link_options(lavender PUBLIC -fsanitize=thread)
target_compile_options(lavender PUBLIC -fsanitize=address)
target_link_options(lavender PUBLIC -fsanitize=address)
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# using Intel C++
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++
endif()
# find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
# set(CLANG_TIDY_COMMAND ${CLANG_TIDY_EXE} "--config-file=../.clang-tidy")
# set_target_properties(lavender PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
find_package(Vulkan COMPONENTS glslc)
find_program(glslc_executable NAMES glslc HINTS Vulkan::glslc)
if (APPLE)
target_link_libraries(lavender PRIVATE "-framework Cocoa -framework IOKit")
endif ()
function(compile_shader target)
cmake_parse_arguments(PARSE_ARGV 1 arg "" "ENV;FORMAT;INCLUDE_DIRS" "SOURCES")
foreach (source ${arg_SOURCES})
add_custom_command(
OUTPUT ${source}.${arg_FORMAT}
DEPENDS ${source}
DEPFILE ${source}.d
COMMAND
${glslc_executable}
$<$<BOOL:${arg_ENV}>:--target-env=${arg_ENV}>
$<$<BOOL:${arg_SPV}>:--target-spv=${arg_SPV}>
$<$<BOOL:${arg_FORMAT}>:-mfmt=${arg_FORMAT}>
$<$<BOOL:${arg_INCLUDE_DIRS}>:-I${CMAKE_SOURCE_DIR}/src/shaders/include>
-O
-g # enable opts & debug symbols
-MD -MF ${source}.d
-o ${source}.${arg_FORMAT}
${CMAKE_CURRENT_SOURCE_DIR}/${source}
)
target_sources(${target} PRIVATE ${source}.${arg_FORMAT})
endforeach ()
endfunction()
compile_shader(lavender
ENV vulkan1.2
SPV spv1.6
FORMAT bin
INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/src/shaders/include"
SOURCES
src/shaders/triangle.vert
src/shaders/triangle.frag
src/shaders/voxel_color_calculation.comp
src/shaders/voxel_color_transfer.vert
src/shaders/voxel_color_transfer.frag
src/shaders/voxel_render.vert
src/shaders/voxel_render.frag
src/shaders/voxel_visibility_detection.comp
)
cmrc_add_resource_library(
lavender_resources
ALIAS lav2
NAMESPACE lav
build/src/shaders/triangle.frag.bin
build/src/shaders/triangle.vert.bin
build/src/shaders/voxel_color_calculation.comp.bin
build/src/shaders/voxel_color_transfer.vert.bin
build/src/shaders/voxel_color_transfer.frag.bin
build/src/shaders/voxel_render.vert.bin
build/src/shaders/voxel_render.frag.bin
build/src/shaders/voxel_visibility_detection.comp.bin
)
target_link_libraries(lavender PRIVATE lav2)