-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
244 lines (208 loc) · 6.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
cmake_minimum_required(VERSION 3.10)
project(yuki-engine)
# ----- Configurations variables
set(CMAKE_CXX_STANDARD 17)
# set(CMAKE_C_STANDARD 20)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# ----- Global variables
set(VERBOSE_CONFIGURATION ON)
set(YUKI_BUILD_LIBRARY ON)
set(YUKI_BUILD_SANDBOX ON)
set(YUKI_BUILD_PLAYGROUND OFF)
set(CPP_FILE_EXTENSIONS "cpp" "hpp" "cx" "cxx" "hxx" "h")
set(GLSL_FILE_EXTENSIONS "glsl" "vert" "geom" "frag")
# ----- Shader files
set(SHADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/YukiShader")
# ----- Core library
set(YUKICORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/YukiCore")
set(YUKICORE_INCLUDE_DIR "${YUKICORE_DIR}/Include")
set(YUKICORE_SOURCES_DIR "${YUKICORE_DIR}/Srcs")
####
####
foreach(_CPP_FILE_EXTENSION IN LISTS CPP_FILE_EXTENSIONS)
file(GLOB _SOURCE_FILE_FOUND "${YUKICORE_SOURCES_DIR}/*.${_CPP_FILE_EXTENSION}")
list(LENGTH _SOURCE_FILE_FOUND _SOURCE_FILE_FOUND_LENGTH)
if(NOT (_SOURCE_FILE_FOUND_LENGTH EQUAL 0))
list(APPEND YUKICORE_SOURCE_FILES "${_SOURCE_FILE_FOUND}")
endif()
endforeach()
list(REMOVE_DUPLICATES YUKICORE_SOURCE_FILES)
if(VERBOSE_CONFIGURATION)
message("[YUKICORE] Source file(s) found:")
foreach(_SOURCE_FILE_FOUND IN LISTS YUKICORE_SOURCE_FILES)
message("File: ${_SOURCE_FILE_FOUND}")
endforeach()
endif()
# ----- Sandbox program
set(SANDBOX_DIR "${CMAKE_CURRENT_SOURCE_DIR}/YukiSandbox")
set(SANDBOX_INCLUDE_DIR "${SANDBOX_DIR}/Include")
set(SANDBOX_SOURCES_DIR "${SANDBOX_DIR}/Srcs")
foreach(_CPP_FILE_EXTENSION IN LISTS CPP_FILE_EXTENSIONS)
file(GLOB _SOURCE_FILE_FOUND "${SANDBOX_SOURCES_DIR}/*.${_CPP_FILE_EXTENSION}")
list(LENGTH _SOURCE_FILE_FOUND _SOURCE_FILE_FOUND_LENGTH)
if(NOT (_SOURCE_FILE_FOUND_LENGTH EQUAL 0))
list(APPEND SANDBOX_SOURCE_FILES "${_SOURCE_FILE_FOUND}")
endif()
endforeach()
list(REMOVE_DUPLICATES SANDBOX_SOURCE_FILES)
if(VERBOSE_CONFIGURATION)
message("[SANDBOX] Source file(s) found:")
foreach(_SOURCE_FILE_FOUND IN LISTS SANDBOX_SOURCE_FILES)
message("File: ${_SOURCE_FILE_FOUND}")
endforeach()
endif()
# ----- Dependencies
if(WIN32)
file(GLOB YUKIDEPS_DLL_FILES "${YUKIDEPS_BINARIES_DIR}/*.dll" "${YUKIDEPS_BINARIES_DIR}/*.pdb")
if(VERBOSE_CONFIGURATION)
message("Dll file(s) found:")
foreach(_DLL_FILE_FOUND IN LISTS YUKIDEPS_DLL_FILES)
message("File: ${_DLL_FILE_FOUND}")
endforeach()
endif()
foreach(_DLL_FILE IN LISTS YUKIDEPS_DLL_FILES)
file(COPY "${_DLL_FILE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
endforeach()
endif()
# ----- Build targets
add_library(yuki-core SHARED "${YUKICORE_SOURCE_FILES}")
target_include_directories(
yuki-core
PUBLIC "${YUKICORE_INCLUDE_DIR}"
PUBLIC "${YUKIDEPS_INCLUDE_DIR}"
)
target_compile_definitions(
yuki-core
PRIVATE "YUKICORE_EXPORTS"
)
target_link_directories(
yuki-core
PUBLIC "${YUKIDEPS_STATICLIB_DIR}"
)
target_precompile_headers(
yuki-core
PUBLIC "${YUKICORE_INCLUDE_DIR}/YukiCore/Headers.hpp"
)
find_package(assimp CONFIG REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_package(glad CONFIG REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(yuki-core
PUBLIC assimp::assimp
PUBLIC freetype
PUBLIC glad::glad
PUBLIC glfw
PUBLIC fmt::fmt)
if (WIN32)
target_link_libraries(yuki-core
PUBLIC pdh)
endif()
find_path(STB_INCLUDE_DIRS "stb_image.h")
target_include_directories(yuki-core PUBLIC ${STB_INCLUDE_DIRS})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_definitions(
yuki-core
PRIVATE "_DEBUG"
PRIVATE "DEBUG"
)
endif()
add_executable(yuki-sandbox "${SANDBOX_SOURCE_FILES}")
target_link_libraries(yuki-sandbox yuki-core)
target_include_directories(yuki-sandbox PRIVATE "${SANDBOX_INCLUDE_DIR}")
# ----- Resources files / External files / Other stuffs
set(STUFFS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Stuffs")
file(GLOB STUFFS_FILES "${STUFFS_DIR}/*.*")
foreach(_STUFF_FILE IN LISTS STUFFS_FILES)
get_filename_component(_STUFF_FILENAME "${_STUFF_FILE}" NAME)
list(APPEND _STUFF_FILE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_STUFF_FILENAME}")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_STUFF_FILENAME}"
DEPENDS "${_STUFF_FILE}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${_STUFF_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${_STUFF_FILENAME}"
)
endforeach()
add_custom_target(sandbox-stuffs DEPENDS "${_STUFF_FILE_OUTPUT}")
add_dependencies(yuki-sandbox sandbox-stuffs)
# ----- Shader files
foreach(_GLSL_FILE_EXTENSION IN LISTS GLSL_FILE_EXTENSIONS)
file(GLOB _SHADER_FILE_FOUND "${SHADERS_DIR}/*.${_GLSL_FILE_EXTENSION}")
list(LENGTH _SHADER_FILE_FOUND _SHADER_FILE_FOUND_LENGTH)
if(NOT (_SHADER_FILE_FOUND_LENGTH EQUAL 0))
list(APPEND SHADER_FILES_FOUND "${_SHADER_FILE_FOUND}")
endif()
endforeach()
list(REMOVE_DUPLICATES _SHADER_FILE_FOUND)
if(VERBOSE_CONFIGURATION)
message("Shader file(s) found:")
foreach(_SHADER_FILE_FOUND IN LISTS SHADER_FILES_FOUND)
message("File: ${_SHADER_FILE_FOUND}")
endforeach()
endif()
foreach(_SHADER_FILE_FOUND IN LISTS SHADER_FILES_FOUND)
get_filename_component(_SHADER_FILENAME "${_SHADER_FILE_FOUND}" NAME)
list(APPEND _SHADER_FILE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_SHADER_FILENAME}")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_SHADER_FILENAME}"
DEPENDS "${_SHADER_FILE_FOUND}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
"${_SHADER_FILE_FOUND}"
"${CMAKE_CURRENT_BINARY_DIR}/${_SHADER_FILENAME}"
)
endforeach()
add_custom_target(shaders DEPENDS "${_SHADER_FILE_OUTPUT}")
add_dependencies(yuki-core shaders)
# # ----- For windows build
# if(WIN32)
# if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
# target_link_libraries(
# yuki-core
# GLU32
# OpenGL32
# assimp-vc143-mtd
# freetyped
# glad
# glfw3dll
# fmtd
# pdh
# )
# else()
# target_link_libraries(
# yuki-core
# GLU32
# OpenGL32
# assimp-vc143-mt
# freetype
# glad
# glfw3dll
# fmt
# pdh
# )
# endif()
# endif()
# if(UNIX AND NOT APPLE)
# if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
# target_link_libraries(
# yuki-core
# GL GLU X11 assimpd minizip jpeg turbojpeg
# freetype glad glfw3 fmtd z poly2tri Irrlicht
# png Xxf86vm bz2d
# )
# else()
# target_link_libraries(
# yuki-core
# GL GLU X11 assimp minizip jpeg turbojpeg
# freetype glad glfw3 fmt z poly2tri Irrlicht
# png Xxf86vm bz2
# )
# endif()
# endif()
# ----- Playground projects
if(YUKI_BUILD_PLAYGROUND)
add_executable(OpenGLMultithreadTest "Playground/OpenGLMultithreadTest.cpp")
target_link_libraries(OpenGLMultithreadTest yuki-core)
add_executable(PdhQueryTest "Playground/PdhQueryTest.cpp")
target_link_libraries(PdhQueryTest pdh)
endif()