forked from gan74/Yave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
187 lines (139 loc) · 5.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
cmake_minimum_required(VERSION 3.24)
project(yave)
function(build_luajit LUAJIT_TARGET)
set(LUA_DIR ${CMAKE_SOURCE_DIR}/external/LuaJIT)
set(LUA_SOURCE_DIR ${LUA_DIR}/src)
if(WIN32)
set(LUA_SHARED_OBJECT ${LUA_SOURCE_DIR}/lua51.dll)
else()
set(LUA_SHARED_OBJECT ${LUA_SOURCE_DIR}/lua51.so)
endif()
if(MSVC)
set(LUA_LIB_FILE ${LUA_SOURCE_DIR}/lua51.lib)
add_custom_command(OUTPUT ${LUA_LIB_FILE} COMMAND cmd /c ${LUA_SOURCE_DIR}/msvcbuild.bat WORKING_DIRECTORY ${LUA_SOURCE_DIR})
else()
set(LUA_LIB_FILE ${LUA_SHARED_OBJECT})
set(MAKE_CMD make)
if(MINGW)
set(MAKE_CMD mingw32-make)
endif()
add_custom_command(OUTPUT ${LUA_LIB_FILE} COMMAND ${MAKE_CMD} WORKING_DIRECTORY ${LUA_DIR})
endif()
add_custom_target(copy-luajit DEPENDS ${LUA_LIB_FILE})
add_custom_command(TARGET copy-luajit POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${LUA_SHARED_OBJECT} ${CMAKE_CURRENT_BINARY_DIR})
add_library(${LUAJIT_TARGET} STATIC IMPORTED GLOBAL)
add_dependencies(${LUAJIT_TARGET} copy-luajit)
set_target_properties(${LUAJIT_TARGET} PROPERTIES IMPORTED_LOCATION ${LUA_LIB_FILE})
endfunction(build_luajit)
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
message("Using unity build for target ${UB_SUFFIX}")
set(FILES ${${SOURCE_VARIABLE_NAME}})
# Exclude all translation units from compilation
set_source_files_properties(${FILES} PROPERTIES HEADER_FILE_ONLY true)
# Generate a unique filename for the unity build translation unit
set(UNIT_BUILD_FILE ${CMAKE_CURRENT_BINARY_DIR}/blob_${UB_SUFFIX}.cpp)
file(WRITE ${UNIT_BUILD_FILE} "// Unity Build generated by CMake\n")
file(WRITE ${UNIT_BUILD_FILE} "#define YAVE_UNITY_BUILD\n")
# Add include statement for each translation unit
foreach(SOURCE_FILE ${FILES})
get_filename_component(FILE_EXT "${SOURCE_FILE}" EXT)
if(NOT "${FILE_EXT}" MATCHES "\.h(pp)?")
file(APPEND ${UNIT_BUILD_FILE} "#include <${SOURCE_FILE}>\n")
endif()
endforeach(SOURCE_FILE)
# Complement list of translation units with the name of ub
set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${UNIT_BUILD_FILE} PARENT_SCOPE)
endfunction(enable_unity_build)
function(optimize_shaders SHADER_TARGET)
file(GLOB SHADER_BINARIES "${CMAKE_CURRENT_BINARY_DIR}/*.spv")
foreach(SHADER ${SHADER_BINARIES})
add_custom_command(TARGET ${SHADER_TARGET} POST_BUILD COMMAND spirv-opt ${SHADER} -O --preserve-bindings -o ${SHADER})
endforeach()
endfunction(optimize_shaders)
option(YAVE_BUILD_YAVE "Build yave" ON)
option(YAVE_BUILD_EDITOR "Build editor" ON)
option(YAVE_TRACY_PROFILING "Use Tracy profiling" ON)
option(YAVE_UNITY_BUILD "Force unity build" OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
# See note in y
# set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Vulkan REQUIRED)
if(NOT Vulkan_FOUND)
message(FATAL_ERROR "Vulkan SDK not found")
endif()
if(NOT Vulkan_glslc_FOUND)
message(FATAL_ERROR "glslc not found in Vulkan SDK")
endif()
# add y subtree
add_subdirectory(y)
add_subdirectory(external/spirv_cross)
# setup includes
include_directories(${y_SOURCE_DIR})
include_directories(${yave_SOURCE_DIR})
include_directories(${Vulkan_INCLUDE_DIRS})
include_directories(external/sol/include)
include_directories(external/LuaJIT/src)
# Yave's core file
file(GLOB_RECURSE YAVE_FILES
"yave/*.h"
"yave/*.cpp"
)
set(TRACY_FILES
"external/tracy/public/TracyClient.cpp"
)
# Editor files
file(GLOB_RECURSE EDITOR_FILES
"editor/*.cpp"
"editor/*.h"
)
file(GLOB_RECURSE EDITOR_EXTERNAL_FILES
"external/imgui/*.cpp"
"external/imgui/*.h"
"external/imgui_test_engine/*.cpp"
"external/imgui_test_engine/*.h"
"external/tinygltf/*.hpp"
"external/tinygltf/*.h"
)
# Shader files
file(GLOB_RECURSE SHADER_FILES
"shaders/*.frag"
"shaders/*.vert"
"shaders/*.geom"
"shaders/*.comp"
)
# Shader libs, they are here so the IDE can find them
file(GLOB_RECURSE SHADER_LIBS
"shaders/*.glsl"
)
build_luajit(luajit)
if(YAVE_UNITY_BUILD)
enable_unity_build(yave YAVE_FILES)
endif()
if(YAVE_BUILD_YAVE)
add_library(yave STATIC ${YAVE_FILES} ${SHADER_FILES} ${SHADER_LIBS})
if(UNIX)
target_link_libraries(yave xcb)
endif()
if(YAVE_TRACY_PROFILING)
add_library(tracy STATIC ${TRACY_FILES})
if(WIN32)
target_link_libraries(tracy ws2_32 dbghelp advapi32 user32)
endif()
target_compile_options(tracy PUBLIC "-DTRACY_ENABLE")
target_link_libraries(yave tracy)
endif()
target_link_libraries(yave y spirv-cross-core)
if(NOT MSVC)
target_link_libraries(yave stdc++fs)
endif()
target_link_libraries(yave luajit)
add_custom_target(shaders COMMAND ${Vulkan_GLSLC_EXECUTABLE} -c --target-env=vulkan1.2 ${SHADER_FILES})
optimize_shaders(shaders)
add_dependencies(yave shaders)
endif()
if(YAVE_BUILD_EDITOR)
add_executable(editor ${EDITOR_FILES} ${EDITOR_EXTERNAL_FILES})
target_include_directories(editor PRIVATE external/imgui)
target_link_libraries(editor yave)
endif()