-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
CMakeLists.txt
347 lines (278 loc) · 9.7 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
cmake_minimum_required(VERSION 3.8.0)
# cmake config
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# cmake library
include(CMake/CMakeVisualStudioSourceGroup.cmake)
include(CMake/CMakeVisualStudioPCH.cmake)
# this line has to appear before 'PROJECT' in order to be able to disable incremental linking
set(MSVC_INCREMENTAL_DEFAULT ON)
# begin project
project(SKYLICHT_ENGINE)
file(STRINGS "Version.txt" SKYLICHT_VERSION)
message(STATUS "- Skylicht Engine version ${SKYLICHT_VERSION}")
# setup folder
set(SKYLICHT_ENGINE_BIN_DIR ${SKYLICHT_ENGINE_SOURCE_DIR}/Bin)
set(SKYLICHT_ENGINE_PROJECT_DIR ${SKYLICHT_ENGINE_SOURCE_DIR}/Projects)
# output
if (CMAKE_SYSTEM_NAME STREQUAL Android)
set(LIBRARY_OUTPUT_PATH ${SKYLICHT_ENGINE_BIN_DIR}/${CMAKE_SYSTEM_NAME}/Libs/${ANDROID_ABI} CACHE PATH "Single output directory for building all libraries.")
elseif (CMAKE_SYSTEM_NAME STREQUAL iOS)
set(LIBRARY_OUTPUT_PATH ${SKYLICHT_ENGINE_BIN_DIR}/${CMAKE_SYSTEM_NAME}/Libs/${PLATFORM} CACHE PATH "Single output directory for building all libraries.")
else()
set(LIBRARY_OUTPUT_PATH ${SKYLICHT_ENGINE_BIN_DIR}/${CMAKE_SYSTEM_NAME}/Libs CACHE PATH "Single output directory for building all libraries.")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL iOS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SKYLICHT_ENGINE_BIN_DIR}/${PLATFORM} CACHE PATH "Single output directory for building executables.")
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SKYLICHT_ENGINE_BIN_DIR} CACHE PATH "Single output directory for building executables.")
endif()
# debug/release
if (NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "- System: ${CMAKE_SYSTEM_NAME} - BuildType: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
endif()
set(CMAKE_CXX_STANDARD 17)
option(BUILD_SHARED_LIBS "Use shared libraries" OFF)
option(INSTALL_LIBS "Install library" OFF)
option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
# build skylicht engine tool on Windows
option(BUILD_EDITOR_TOOL "Build with scene editor" ON)
# skylicht engine option
option(BUILD_DEBUG_VLD "Build with debug visual leak detector" OFF)
option(BUILD_DEBUG_CRASHHANDLER "Build with debug crash handler" OFF)
option(BUILD_SDL "Build with Simple DirectMedia Layer is a cross-platform development library" OFF)
option(USE_OPENMP "Use openmp for multithread optimize" ON)
include(SkylichtConfig.cmake)
include(PlatformConfig.cmake)
if (USE_OPENMP)
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# AppleClang
find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
find_file(OMP_H_PATH NAME omp.h HINTS OpenMP)
get_filename_component(OMP_INCLUDE_DIR ${OMP_H_PATH} DIRECTORY)
include_directories(${OMP_INCLUDE_DIR})
find_library(OMP_LIBRARY NAMES omp)
link_libraries(${OMP_LIBRARY})
message(STATUS "- OpenMP library found: ${OMP_H_PATH}")
message(STATUS "- OpenMP include directory: ${OMP_INCLUDE_DIR}")
message(STATUS "- OpenMP link directory: ${OMP_LIBRARY}")
add_definitions(-DUSE_OPENMP)
else()
message(STATUS "! OpenMP library not found! $>brew install libomp")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# using Visual Studio C++
add_compile_options(/openmp)
add_definitions(-DUSE_OPENMP)
else()
# using GCC & Clang++ (android)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
add_definitions(-DUSE_OPENMP)
endif()
endif()
if (BUILD_DEBUG_CRASHHANDLER AND MSVC)
add_definitions(-DUSE_CRASHHANDLER)
endif()
# network
if (BUILD_SKYLICHT_NETWORK)
add_definitions(-DBUILD_SKYLICHT_NETWORK)
# curl on/off
if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(BUILD_CURL OFF)
else()
set(BUILD_CURL ON)
add_definitions(-DHAVE_CURL)
add_definitions(-DCURL_STATICLIB)
add_definitions(-DHTTP_ONLY)
add_definitions(-DBUILDING_LIBCURL)
# enable openssl for https
if (MSVC)
set(BUILD_OPENSSL ON)
add_definitions(-DUSE_OPENSSL)
endif()
endif()
else()
set(BUILD_CURL OFF)
endif()
# freetype font library
if (BUILD_FREETYPE)
add_definitions(-DFT2_BUILD_LIBRARY)
endif()
# engine static library
if (NOT BUILD_SHARED_LIBS)
add_definitions(-D_IRR_STATIC_LIB_)
add_definitions(-D_SKYLICHT_STATIC_LIB_)
endif()
# skylicht debug leak memory
if (BUILD_DEBUG_VLD AND MSVC)
add_definitions(-DUSE_VISUAL_LEAK_DETECTOR)
endif()
if (BUILD_SDL)
add_definitions(-DSDL)
endif()
# bullet engine
if (BUILD_BULLET_PHYSIC_LIB)
add_definitions(-DUSE_BULLET_PHYSIC_ENGINE)
endif()
# unicode library
add_definitions(-DUNICODE -D_UNICODE)
if (CYGWIN)
add_definitions(-DCYGWIN)
# gcc7 not support std::filesystem so we disable
set(BUILD_EDITOR_TOOL OFF)
set(BUILD_EDITOR_GUI_LIB OFF)
endif()
if (MINGW)
add_definitions(-DMINGW)
# gcc7 not support std::filesystem so we disable
set(BUILD_EDITOR_TOOL OFF)
set(BUILD_EDITOR_GUI_LIB OFF)
endif()
# android
if (BUILD_ANDROID)
add_compile_options(-Wno-narrowing)
add_compile_options(-fvisibility=hidden)
add_compile_options(-O3)
endif()
# visual studio
if (BUILD_WINDOWS_STORE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_options(/ZW)
if (CMAKE_CL_64)
add_definitions(-D_WIN64)
endif()
elseif (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if (NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
#We statically link to reduce dependancies
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if (${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MD")
if (${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif (${flag_var} MATCHES "/MDd")
endforeach()
endif()
if (CMAKE_CL_64)
add_definitions(-D_WIN64)
endif()
option(USE_MSVC_FAST_FLOATINGPOINT "Use MSVC /fp:fast option" ON)
if (USE_MSVC_FAST_FLOATINGPOINT)
add_compile_options(/fp:fast)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif()
# install output
set(CMAKE_INSTALL_PREFIX ${SKYLICHT_ENGINE_SOURCE_DIR}/InstallLibs)
set(SKYLICHT_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
# install library directory
set(SKYLICHT_RUNTIME_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin/${CMAKE_SYSTEM_NAME})
set(SKYLICHT_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_NAME})
set(SKYLICHT_ARCHIVE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_NAME})
set(SKYLICHT_TARGET_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/cmake/${CMAKE_SYSTEM_NAME})
if (CMAKE_SYSTEM_NAME STREQUAL Android)
set(SKYLICHT_RUNTIME_INSTALL_DIR ${SKYLICHT_RUNTIME_INSTALL_DIR}/${ANDROID_ABI})
set(SKYLICHT_LIBRARY_INSTALL_DIR ${SKYLICHT_LIBRARY_INSTALL_DIR}/${ANDROID_ABI})
set(SKYLICHT_ARCHIVE_INSTALL_DIR ${SKYLICHT_ARCHIVE_INSTALL_DIR}/${ANDROID_ABI})
set(SKYLICHT_TARGET_INSTALL_DIR ${SKYLICHT_TARGET_INSTALL_DIR}/${ANDROID_ABI})
elseif (CMAKE_SYSTEM_NAME STREQUAL iOS)
set(SKYLICHT_RUNTIME_INSTALL_DIR ${SKYLICHT_RUNTIME_INSTALL_DIR}/${PLATFORM})
set(SKYLICHT_LIBRARY_INSTALL_DIR ${SKYLICHT_LIBRARY_INSTALL_DIR}/${PLATFORM})
set(SKYLICHT_ARCHIVE_INSTALL_DIR ${SKYLICHT_ARCHIVE_INSTALL_DIR}/${PLATFORM})
set(SKYLICHT_TARGET_INSTALL_DIR ${SKYLICHT_TARGET_INSTALL_DIR}/${PLATFORM})
endif()
if (BUILD_SHARED_LIBS)
message(STATUS "Building dynamic libs")
set(ENGINE_SHARED_OR_STATIC_LIB "SHARED")
else()
message(STATUS "Building static libs")
set(ENGINE_SHARED_OR_STATIC_LIB "STATIC")
endif()
# add project
# core library
subdirs (Projects/ThirdParty)
subdirs (Projects/Irrlicht)
# skylicht engine
subdirs (Projects/Skylicht/System)
subdirs (Projects/Skylicht/Engine)
if (BUILD_IMGUI)
add_definitions(-DBUILD_IMGUI)
subdirs (Projects/Imgui)
endif()
# spine runtimes
if (BUILD_SPINE_RUNTIMES)
subdirs (Projects/SpineCpp)
endif()
# recast & graph
if (BUILD_SKYLICHT_GRAPH)
add_definitions(-DBUILD_SKYLICHT_GRAPH)
subdirs (Projects/Skylicht/Graph)
endif()
# skylicht components
if (BUILD_SKYLICHT_COMPONENTS)
add_definitions(-DBUILD_SKYLICHT_COMPONENTS)
subdirs (Projects/Skylicht/Components)
endif()
# skylicht collision
if (BUILD_SKYLICHT_COLLISION)
add_definitions(-DBUILD_SKYLICHT_COLLISION)
subdirs (Projects/Skylicht/Collision)
endif()
# skylicht lightmapper
if (BUILD_SKYLICHT_LIGHMAPPER)
add_definitions(-DBUILD_SKYLICHT_LIGHMAPPER)
subdirs (Projects/Skylicht/Lightmapper)
endif()
# skylicht physics library
if (BUILD_SKYLICHT_PHYSIC)
add_definitions(-DBUILD_SKYLICHT_PHYSIC)
if (BUILD_BULLET_PHYSIC_LIB)
subdirs (Projects/Bullet3)
endif()
subdirs (Projects/Skylicht/Physics)
endif()
# skylicht audio
if (BUILD_SKYLICHT_AUDIO)
add_definitions(-DBUILD_SKYLICHT_AUDIO)
subdirs (Projects/Skylicht/Audio)
endif()
# skylicht ui
if (BUILD_SKYLICHT_UI)
add_definitions(-DBUILD_SKYLICHT_UI)
subdirs (Projects/Skylicht/UserInterface)
endif()
# skylicht crypto
if (BUILD_SKYLICHT_CRYPTO)
add_definitions(-DBUILD_SKYLICHT_CRYPTO)
subdirs (Projects/Skylicht/Crypto)
endif()
# skylicht network
if (BUILD_SKYLICHT_NETWORK)
subdirs (Projects/Skylicht/Network)
endif()
subdirs (Projects/Skylicht/Client)
if (BUILD_EDITOR_GUI_LIB)
subdirs (Projects/EditorGUI)
endif()
if (NOT INSTALL_LIBS)
if (BUILD_EDITOR_TOOL AND BUILD_EDITOR_GUI_LIB)
subdirs (Projects/Editor)
endif()
include(CMakeProjects.cmake)
# unit test
if (NOT BUILD_ANDROID AND NOT BUILD_IOS AND NOT BUILD_EMSCRIPTEN AND NOT BUILD_WINDOWS_STORE)
enable_testing()
subdirs (UnitTest/TestApp)
endif()
endif()