-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
154 lines (121 loc) · 3.54 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
cmake_minimum_required(VERSION 3.15)
project(rend)
set(CMAKE_CXX_STANDARD 17)
add_compile_definitions(ASSET_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/assets")
find_package(Vulkan REQUIRED)
find_package(assimp REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(SDL2 REQUIRED)
add_subdirectory(vk-bootstrap)
add_subdirectory(VulkanMemoryAllocator)
add_subdirectory(JoltPhysics/Build)
# Shader compilation targets
file(GLOB VERT_SHADER_SOURCES
"assets/shaders/*.vert"
CONFIGUE_DEPENDS
)
file(GLOB FRAG_SHADER_SOURCES
"assets/shaders/*.frag"
CONFIGUE_DEPENDS
)
message(STATUS "Vertex shaders:\n ${VERT_SHADER_SOURCES}")
message(STATUS "Fragment shaders:\n ${FRAG_SHADER_SOURCES}")
set(SHADER_SOURCES ${VERT_SHADER_SOURCES} ${FRAG_SHADER_SOURCES})
set(SHADER_TARGETS)
foreach(SHADER_SOURCE ${SHADER_SOURCES})
message("Shader source: ${SHADER_SOURCE}")
get_filename_component(SHADER_FILENAME ${SHADER_SOURCE} NAME)
get_filename_component(SHADER_NAME_STEM ${SHADER_SOURCE} NAME_WE)
get_filename_component(SHADER_EXT ${SHADER_SOURCE} EXT)
message(STATUS "Shader name: ${SHADER_FILENAME}")
string(REPLACE "." "" EXT_NO_DOT ${SHADER_EXT})
add_custom_target( ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader
COMMAND glslangValidator
${CMAKE_CURRENT_SOURCE_DIR}/assets/shaders/${SHADER_FILENAME}
-V
-o
${SHADER_NAME_STEM}_${EXT_NO_DOT}.spv
-I${CMAKE_CURRENT_SOURCE_DIR}/assets/shaders/bin
COMMENT "Compiling ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader"
)
add_custom_target( ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader_copy
COMMAND cp ${SHADER_NAME_STEM}_${EXT_NO_DOT}.spv ${CMAKE_CURRENT_SOURCE_DIR}/assets/shaders/bin
COMMENT "Copying ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader"
DEPENDS ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader
)
list(APPEND SHADER_TARGETS ${SHADER_NAME_STEM}_${EXT_NO_DOT}_shader_copy)
endforeach()
message(STATUS "Generated targets:\n ${SHADER_TARGETS}")
message(STATUS "Sources:\n ${${CMAKE_PROJECT_NAME}_SOURCES}")
# LIB
set(${CMAKE_PROJECT_NAME}_SOURCES
rend/src/vma_impl.cpp
rend/src/Renderer.cpp
rend/src/InputHandler.cpp
rend/src/Shader.cpp
rend/src/Mesh.cpp
rend/src/Material.cpp
rend/src/Texture.cpp
rend/src/EntityRegistry.cpp
)
add_library(${CMAKE_PROJECT_NAME}
${${CMAKE_PROJECT_NAME}_SOURCES}
)
# Build IMGUI
file(GLOB IMGUI_HEADERS
"imgui/*.h"
)
file(GLOB IMGUI_SOURCES
"imgui/*.cpp"
"imgui/backends/imgui_impl_vulkan.cpp"
"imgui/backends/imgui_impl_sdl2.cpp"
)
add_library(lodepng
"lodepng/lodepng.cpp"
)
target_include_directories(lodepng PUBLIC
lodepng
)
add_library(imgui
${IMGUI_SOURCES}
)
target_include_directories(imgui PUBLIC
imgui/
${SDL2_INCLUDE_DIRS}
)
target_link_libraries(imgui PUBLIC
SDL2
)
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
${Vulkan_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
VulkanMemoryAllocator/include
rend/include/
vk-bootstrap/src
stb/
JoltPhysics/
)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
${Vulkan_LIBRARIES}
/usr/lib/x86_64-linux-gnu/libSDL2.so
vk-bootstrap::vk-bootstrap
VulkanMemoryAllocator
assimp
SDL2
SDL2_mixer
Jolt
pthread
imgui
lodepng
)
add_dependencies(${CMAKE_PROJECT_NAME} ${SHADER_TARGETS})
# Example
add_executable(${CMAKE_PROJECT_NAME}_example
examples/main.cpp
)
target_link_libraries(${CMAKE_PROJECT_NAME}_example
${CMAKE_PROJECT_NAME}
)
enable_testing()
add_subdirectory(test)