-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
125 lines (110 loc) · 4.24 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
cmake_minimum_required(VERSION 3.21)
# set the project name
project(game)
# specify the list of paths to source files
set(SOURCES
src/event_sdl.c
src/filesystem_physfs.c
src/framework.c
src/graphics_opengl_sdl.c
src/main_sdl.c
src/timer_sdl.c
src/vk_mem_alloc.cpp
src/window_sdl.c
)
# add the executable
if (WIN32)
add_executable(game WIN32 ${SOURCES})
elseif(APPLE)
add_executable(game MACOSX_BUNDLE ${SOURCES})
else()
add_executable(game ${SOURCES})
endif()
# specify the C++ standard
set_property(TARGET game PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET game PROPERTY CXX_STANDARD 11)
set_property(TARGET game PROPERTY CXX_STANDARD_REQUIRED ON)
# specify the C standard
set_property(TARGET game PROPERTY C_EXTENSIONS OFF)
set_property(TARGET game PROPERTY C_STANDARD 99)
set_property(TARGET game PROPERTY C_STANDARD_REQUIRED ON)
# add the PhysicsFS library
set(PHYSFS_BUILD_STATIC FALSE CACHE BOOL "Build static library")
set(PHYSFS_BUILD_TEST FALSE CACHE BOOL "Build stdio test program.")
set(PHYSFS_BUILD_DOCS FALSE CACHE BOOL "Build doxygen based documentation")
add_subdirectory(lib/physfs-release-3.2.0)
# add the SDL2 library
find_package(SDL2 2.28.1 EXACT REQUIRED PATHS lib)
# add the volk library
add_subdirectory(lib/volk)
# https://github.com/KhronosGroup/Vulkan-Samples/blob/3df7dba1b1f428f24cd9a242af78540a518f4b67/third_party/CMakeLists.txt#L53-L86
if(ANDROID)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_ANDROID_KHR)
elseif(WIN32)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_WIN32_KHR)
elseif(APPLE)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_METAL_EXT)
elseif(UNIX)
# Choose WSI based on VKB_WSI_SELECTION
if (VKB_WSI_SELECTION STREQUAL XCB OR VKB_WSI_SELECTION STREQUAL XLIB OR VKB_WSI_SELECTION STREQUAL WAYLAND)
find_package(PkgConfig REQUIRED)
endif()
if (VKB_WSI_SELECTION STREQUAL XCB)
pkg_check_modules(XCB xcb REQUIRED)
if (XCB_FOUND)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_XCB_KHR)
endif()
elseif (VKB_WSI_SELECTION STREQUAL XLIB)
pkg_check_modules(X11 x11 REQUIRED)
if (X11_FOUND)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_XLIB_KHR)
endif()
elseif (VKB_WSI_SELECTION STREQUAL WAYLAND)
pkg_check_modules(WAYLAND wayland-client REQUIRED)
if (WAYLAND_FOUND)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_WAYLAND_KHR)
endif()
elseif (VKB_WSI_SELECTION STREQUAL D2D)
set(DIRECT_TO_DISPLAY TRUE)
set(DIRECT_TO_DISPLAY TRUE PARENT_SCOPE)
target_compile_definitions(game PUBLIC VK_USE_PLATFORM_DISPLAY_KHR)
else()
# UNDONE: No Window System Integration (WSI) on GitHub Actions.
# message(FATAL_ERROR "Unknown WSI")
endif()
endif()
# add the Vulkan Memory Allocator library
set(VMA_STATIC_VULKAN_FUNCTIONS OFF CACHE BOOL "Link statically with Vulkan API")
add_subdirectory(lib/VulkanMemoryAllocator-3.0.1)
if (APPLE)
target_compile_options(VulkanMemoryAllocator PUBLIC -Wno-nullability-completeness)
endif()
# add the GLM library
find_package(glm REQUIRED PATHS lib/glm/cmake)
target_link_libraries(game PUBLIC PhysFS::PhysFS)
target_link_libraries(game PUBLIC SDL2::SDL2)
target_link_libraries(game PUBLIC SDL2::SDL2main)
target_link_libraries(game PUBLIC volk::volk)
target_link_libraries(game PUBLIC VulkanMemoryAllocator)
target_link_libraries(game PUBLIC glm::glm)
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(game PUBLIC
"${PROJECT_BINARY_DIR}"
PhysFS::PhysFS
SDL2::SDL2
SDL2::SDL2main
volk::volk
VulkanMemoryAllocator
glm::glm
)
if(WIN32)
add_custom_command(TARGET game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:game> $<TARGET_FILE_DIR:game>
COMMAND_EXPAND_LISTS
)
add_custom_command(TARGET game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/shaders $<TARGET_FILE_DIR:game>/shaders
COMMAND_EXPAND_LISTS
)
endif()