forked from KhronosGroup/Vulkan-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
206 lines (180 loc) · 6.51 KB
/
CMakeLists.txt
File metadata and controls
206 lines (180 loc) · 6.51 KB
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
cmake_minimum_required(VERSION 3.29)
# Enable C++ module dependency scanning
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
project(SimpleEngine VERSION 1.0.0 LANGUAGES CXX C)
# Add CMake module path for custom find modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../CMake")
if(ANDROID)
include(FetchContent)
FetchContent_Declare(
VulkanHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
GIT_TAG v1.3.275 # Or a specific tag/commit This needs to correspond to the NDK version of Vulkan.
)
FetchContent_MakeAvailable(VulkanHeaders)
endif ()
# Find required packages
find_package (glm REQUIRED)
find_package (Vulkan REQUIRED)
find_package (tinygltf REQUIRED)
find_package (KTX REQUIRED)
# Platform-specific settings
if(ANDROID)
# Android-specific settings
add_definitions(-DPLATFORM_ANDROID)
else()
# Desktop-specific settings
add_definitions(-DPLATFORM_DESKTOP)
find_package (glfw3 REQUIRED)
find_package (OpenAL REQUIRED)
endif()
# Shader compilation
# Find Slang shaders
file(GLOB SLANG_SHADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.slang)
# Find slangc executable (optional)
find_program(SLANGC_EXECUTABLE slangc HINTS $ENV{VULKAN_SDK}/bin)
if(SLANGC_EXECUTABLE)
# Ensure the output directory for compiled shaders exists
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders)
# Compile Slang shaders using slangc
foreach(SHADER ${SLANG_SHADER_SOURCES})
get_filename_component(SHADER_NAME ${SHADER} NAME)
get_filename_component(SHADER_NAME_WE ${SHADER_NAME} NAME_WE)
string(REGEX REPLACE "\.slang$" "" OUTPUT_NAME ${SHADER_NAME})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv
COMMAND ${SLANGC_EXECUTABLE} ${SHADER} -target spirv -profile spirv_1_4 -emit-spirv-directly -o ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv
DEPENDS ${SHADER}
COMMENT "Compiling Slang shader ${SHADER_NAME} with slangc"
)
list(APPEND SHADER_SPVS ${CMAKE_CURRENT_BINARY_DIR}/shaders/${OUTPUT_NAME}.spv)
endforeach()
add_custom_target(shaders DEPENDS ${SHADER_SPVS})
else()
message(STATUS "slangc not found. Skipping shader compilation step.")
add_custom_target(shaders)
endif()
# Source files
set(SOURCES
main.cpp
engine.cpp
scene_loading.cpp
platform.cpp
renderer_core.cpp
renderer_rendering.cpp
renderer_pipelines.cpp
renderer_compute.cpp
renderer_utils.cpp
renderer_resources.cpp
memory_pool.cpp
resource_manager.cpp
entity.cpp
component.cpp
transform_component.cpp
mesh_component.cpp
camera_component.cpp
model_loader.cpp
audio_system.cpp
physics_system.cpp
imgui_system.cpp
imgui/imgui.cpp
imgui/imgui_draw.cpp
vulkan_device.cpp
pipeline.cpp
descriptor_manager.cpp
renderdoc_debug_system.cpp
mikktspace.c
)
# Create executable or library based on the platform
if(ANDROID)
add_library(SimpleEngine STATIC ${SOURCES})
else()
add_executable(SimpleEngine ${SOURCES})
endif()
add_dependencies(SimpleEngine shaders)
set_target_properties (SimpleEngine PROPERTIES CXX_STANDARD 20)
# Link libraries
target_link_libraries(SimpleEngine PUBLIC
Vulkan::Vulkan
Vulkan::Headers
glm::glm
tinygltf::tinygltf
KTX::ktx
)
if(ANDROID)
target_link_libraries(SimpleEngine PUBLIC
android
log
EGL
GLESv2
game-activity::game-activity
OpenSLES
)
target_include_directories(SimpleEngine PUBLIC
${VulkanHeaders_SOURCE_DIR}/include
${ANDROID_NDK}/sources/android/native_app_glue
)
target_compile_definitions(SimpleEngine PRIVATE VULKAN_HPP_NO_STRUCT_CONSTRUCTORS)
else()
target_link_libraries(SimpleEngine PRIVATE glfw OpenAL::OpenAL)
target_compile_definitions(SimpleEngine PRIVATE VULKAN_HPP_NO_STRUCT_CONSTRUCTORS VULKAN_HPP_DISPATCH_LOADER_DYNAMIC)
endif()
# Copy model and texture files if they exist
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/models)
add_custom_command(TARGET SimpleEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/models ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/models
COMMENT "Copying models to output directory"
)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/textures)
add_custom_command(TARGET SimpleEngine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/textures ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/textures
COMMENT "Copying textures to output directory"
)
endif()
# Add packaging configuration
include(CPack)
# Set package properties
set(CPACK_PACKAGE_NAME "SimpleEngine")
set(CPACK_PACKAGE_VENDOR "SimpleEngine Team")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A simple game engine built with Vulkan")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "SimpleEngine")
# Set platform-specific package generators
if(WIN32)
set(CPACK_GENERATOR "ZIP;NSIS")
set(CPACK_NSIS_PACKAGE_NAME "SimpleEngine")
set(CPACK_NSIS_DISPLAY_NAME "SimpleEngine")
set(CPACK_NSIS_HELP_LINK "https://github.com/yourusername/SimpleEngine")
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/yourusername/SimpleEngine")
set(CPACK_NSIS_CONTACT "your.email@example.com")
set(CPACK_NSIS_MODIFY_PATH ON)
elseif(APPLE)
set(CPACK_GENERATOR "ZIP;DragNDrop")
set(CPACK_DMG_VOLUME_NAME "SimpleEngine")
set(CPACK_DMG_FORMAT "UDBZ")
else()
set(CPACK_GENERATOR "ZIP;DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Your Name <your.email@example.com>")
set(CPACK_DEBIAN_PACKAGE_SECTION "games")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libvulkan1, libglfw3, libglm-dev, libktx-dev")
endif()
# Include binary and resource directories in the package
install(TARGETS SimpleEngine DESTINATION bin)
if(SLANGC_EXECUTABLE)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders DESTINATION share/SimpleEngine)
endif()
# Install models and textures if they exist
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/models)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/models DESTINATION share/SimpleEngine)
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/textures)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/textures DESTINATION share/SimpleEngine)
endif()
# Install README if it exists
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION share/SimpleEngine)
endif()