-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
138 lines (112 loc) · 3.87 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
cmake_minimum_required(VERSION 3.9)
project(heikousen)
set(CMAKE_CXX_STANDARD 17)
add_definitions(-DGLFW_INCLUDE_VULKAN)
# Static linking with msvc
if (MSVC)
foreach (flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MD")
endforeach (flag_var)
endif ()
file(GLOB SOURCE_FILES
"src/*.[ch]pp"
"src/Rendering/*.cpp"
"src/Rendering/*.h"
"src/Common/*.h")
file(GLOB SHADER_FILES "shader/*.vert" "shader/*.frag")
file(GLOB SCRIPT_FILES "scripts/*.js")
find_program(GLSL_EXECUTABLE glslangValidator)
function(preprocess_glsl out_var)
set(result)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shader)
foreach (in_f ${ARGN})
file(RELATIVE_PATH out_f ${CMAKE_CURRENT_SOURCE_DIR} ${in_f})
set(out_f "${CMAKE_CURRENT_BINARY_DIR}/${out_f}.spv")
add_custom_command(OUTPUT ${out_f}
COMMAND ${GLSL_EXECUTABLE} -V -o ${out_f} ${in_f}
DEPENDS ${in_f}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Compiling shader ${in_f}"
VERBATIM
)
list(APPEND result ${out_f})
endforeach ()
set(${out_var} "${result}" PARENT_SCOPE)
endfunction()
preprocess_glsl(COMPILED_SHADERS ${SHADER_FILES})
find_package(Bullet REQUIRED HINTS "${CMAKE_SOURCE_DIR}/extern/dist/lib/cmake/bullet")
find_package(Vulkan REQUIRED)
find_package(glm REQUIRED HINTS "${CMAKE_SOURCE_DIR}/extern/dist/lib/cmake/glm")
if (UNIX)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
else ()
find_package(glfw3 REQUIRED HINTS "${CMAKE_SOURCE_DIR}/extern/dist/lib/cmake/glfw3")
endif ()
link_directories(
${BULLET_LIBRARY_DIRS}
${CMAKE_SOURCE_DIR}/extern/dist/lib
)
message("Vulkan found? " ${Vulkan_FOUND})
message("Bullet found? " ${BULLET_FOUND})
message("GLFW3 found? " ${GLFW_FOUND})
message("GLM found? " ${GLM_FOUND})
add_executable(heikousen ${SOURCE_FILES} ${SHADER_FILES} ${COMPILED_SHADERS})
set(BINARY heikousen)
if (UNIX)
target_include_directories(
heikousen PRIVATE
"/usr/include/bullet"
)
else ()
target_include_directories(
heikousen PRIVATE
${CMAKE_SOURCE_DIR}/extern/dist/include
)
endif ()
target_include_directories(
heikousen PRIVATE
${Vulkan_INCLUDE_DIRS}
${BULLET_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/extern/VulkanMemoryAllocator/src
)
# case sensitive!
target_link_libraries(
${BINARY}
${BULLET_LIBRARIES}
${Vulkan_LIBRARIES}
glm
glfw
)
configure_file(${CMAKE_SOURCE_DIR}/default.ini ${CMAKE_CURRENT_BINARY_DIR}/config.ini COPYONLY)
# Copy script files on build
add_custom_command(TARGET heikousen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/scripts ${CMAKE_CURRENT_BINARY_DIR}/scripts
)
# Copy script files on build
add_custom_command(TARGET heikousen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/models ${CMAKE_CURRENT_BINARY_DIR}/models
)
# Copy font files on build
add_custom_command(TARGET heikousen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/fonts ${CMAKE_CURRENT_BINARY_DIR}/fonts
)
# Copy texture files on build
add_custom_command(TARGET heikousen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/textures ${CMAKE_CURRENT_BINARY_DIR}/textures
)
# Copy map files on build
add_custom_command(TARGET heikousen PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/maps ${CMAKE_CURRENT_BINARY_DIR}/maps
)