-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
77 lines (59 loc) · 2.31 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
cmake_minimum_required(VERSION 3.12)
set(EngineName "TanookiEngine")
project(${EngineName})
# Collect all .cpp and .hpp files from the src directory
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.hpp" "src/**/*.cpp" "src/**/*.hpp")
# Set the include directories
include_directories(lib/glm)
include_directories(lib/tiny_obj_loader)
include_directories(lib/stb)
# Set the Vulkan SDK path
set(VULKAN_SDK_PATH "C:/VulkanSDK/1.3.268.0") # Replace with the actual version number
# Find Vulkan
find_package(Vulkan REQUIRED)
# Add the shaders directory to the source files (for IDEs that support it)
file(GLOB SHADERS shaders/*.spv)
# Remove existing shader assets in build directory for CLEAN
file(GLOB EXISTING_SHADERS ${CMAKE_BINARY_DIR}/shaders/*.spv)
if(EXISTING_SHADERS)
message(STATUS "Removing existing shaders in the build directory...")
file(REMOVE ${EXISTING_SHADERS})
endif()
# Set the executable
add_executable(${EngineName} ${SOURCES} ${SHADERS})
# Add a custom target to compile shaders
add_custom_target(CompileShaders
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_SOURCE_DIR} cmd /c compile.bat
COMMENT "Compiling shaders"
VERBATIM
)
# Add CompileShaders as a dependency for VulkanProject
add_dependencies(${EngineName} CompileShaders)
# Copy assets to build directory
file(COPY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${CMAKE_BINARY_DIR})
# Copy only .spv files to build directory after compilation
file(GLOB_RECURSE SPV_FILES ${CMAKE_SOURCE_DIR}/shaders/*.spv)
add_custom_command(TARGET CompileShaders POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/shaders
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SPV_FILES} ${CMAKE_BINARY_DIR}/shaders
COMMENT "Copying .spv files to build directory"
)
# Add the GLFW subdirectory
add_subdirectory(lib/glfw3)
# Link libraries
target_link_libraries(${EngineName}
Vulkan::Vulkan
glfw
)
# Set compiler options
if (MSVC)
target_compile_options(${EngineName} PRIVATE /W4)
else()
target_compile_options(${EngineName} PRIVATE -Wall -Wextra -pedantic)
endif()
# Set output directories for binaries
set_target_properties(${EngineName} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)