-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
84 lines (69 loc) · 2.73 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
cmake_minimum_required (VERSION 3.28)
project (ice)
set(CMAKE_CXX_STANDARD 20)
include(./.env.cmake OPTIONAL RESULT_VARIABLE LOCAL_ENV)
message(STATUS "Local .env.cmake: ${LOCAL_ENV}")
# windowing
find_package(glfw3 CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
# Vulkan and Utils
find_package(Vulkan REQUIRED)
find_package(glm REQUIRED)
find_path(STB_INCLUDE_DIRS "stb_image.h")
find_path(TINYGLTF_INCLUDE_DIRS "tiny_gltf.h")
message(STATUS "Stb directory: ${TINYGLTF_INCLUDE_DIRS}" )
message(STATUS "tinygltf directory: ${STB_INCLUDE_DIRS}" )
message(STATUS "Directory: ${Vulkan_INCLUDE_DIRS}")
message(STATUS "Directory: ${Vulkan_LIBRARIES}")
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/src/*
${PROJECT_SOURCE_DIR}/third_party_patches/*
)
add_executable (first_app ${SOURCES})
foreach( target IN ITEMS first_app)
message(STATUS "Configuring target: ${target}")
target_include_directories(${target} PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(${target} PRIVATE glfw)
target_link_libraries(${target} PRIVATE imgui::imgui)
target_include_directories(${target} PRIVATE ${STB_INCLUDE_DIRS}
${TINYGLTF_INCLUDE_DIRS} ${Vulkan_INCLUDE_DIRS}
)
target_link_libraries(${target} PRIVATE ${Vulkan_LIBRARIES})
target_link_libraries(${target} PRIVATE glm::glm)
endforeach()
set( source "${CMAKE_SOURCE_DIR}/resources")
set( destination "${CMAKE_CURRENT_BINARY_DIR}/resources") # or CMAKE_BINARY_DIR
set( vulkan_apps first_app )
if(MSVC)
# startup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT first_app)
# Needed in Visual Studio to enable file access to non-local paths
# TargetDir is a VS macro containing path to executable directory
set_target_properties(
${vulkan_apps} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:${vulkan_apps}>/"
)
# Copy compiled shaders to executable directory
# Add post-build commands
add_custom_command(TARGET ${vulkan_apps} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/resources
"$(TargetDir)resources" COMMENT
"copied resource folder from ${source} => $(TargetDir)resources"
)
elseif(UNIX)
# For non-MSVC (Linux, macOS, etc.)
add_custom_command(TARGET ${vulkan_apps}
COMMAND ${CMAKE_COMMAND} -E create_symlink
${source} ${destination} DEPENDS ${
destination} COMMENT
"symbolic link resource folder from ${source} => ${destination}"
)
else()
# windows might not use MSVC
add_custom_command(TARGET ${vulkan_apps} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${source}
${destination} COMMENT
"copied resource folder from ${source} => ${destination}"
)
endif()