forked from effekseer/Effekseer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
386 lines (327 loc) · 14.9 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
cmake_minimum_required(VERSION 3.15)
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)
endif()
include(ExternalProject)
# Solution name
project(Effekseer)
# For MSVC
if (MSVC)
option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" OFF)
endif()
option(BUILD_GL "Build OpenGL" ON)
option(BUILD_VIEWER "Build viewer" OFF)
option(BUILD_EDITOR "Build editor" OFF)
option(BUILD_TEST "Build test" OFF)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_UNITYPLUGIN "is built as unity plugin" OFF)
option(BUILD_UNITYPLUGIN_FOR_IOS "is built as unity plugin for ios" OFF)
option(FROM_CI "from ci" OFF)
option(SANITIZE_ENABLED "is sanitizer enabled" OFF)
option(USE_LIBPNG_LOADER "use libpng in an internal loader (if it builds viewer except windows, it becomes on)" OFF)
option(BUILD_VULKAN "Build vulkan modules" OFF)
if (WIN32)
option(BUILD_DX9 "Build DirectX9 modules" ON)
option(BUILD_DX11 "Build DirectX11 modules" ON)
option(BUILD_DX12 "Build DirectX12 modules" ON)
else()
option(BUILD_DX12 "Build DirectX12 modules" OFF)
endif()
if (APPLE)
option(BUILD_METAL "Build metal modules" ON)
else()
option(BUILD_METAL "Build metal modules" OFF)
endif()
include(cmake/ClangFormat.cmake)
if (BUILD_VIEWER)
set(USE_LIBPNG_LOADER ON)
endif()
if(USE_LIBPNG_LOADER)
add_definitions(-D__EFFEKSEER_USE_LIBPNG__)
endif()
if(SANITIZE_ENABLED)
set(CMAKE_CXX_FLAGS " -fsanitize=undefined,address" ${CMAKE_CXX_FLAGS})
endif()
# find_package(Vulkan)
# if (Vulkan_FOUND)
# set(BUILD_VULKAN ON)
# else()
# set(BUILD_VULKAN OFF)
# endif()
if(BUILD_VULKAN)
set(BUILD_VULKAN ON CACHE BOOL "For LLGI" FORCE)
set(BUILD_VULKAN_COMPILER ON CACHE BOOL "For LLGI" FORCE)
add_definitions(-D__EFFEKSEER_BUILD_VULKAN__)
else()
set(BUILD_VULKAN OFF CACHE BOOL "For LLGI" FORCE)
set(BUILD_VULKAN_COMPILER OFF CACHE BOOL "For LLGI" FORCE)
endif()
if (BUILD_DX12)
add_definitions(-D__EFFEKSEER_BUILD_DX12__)
endif()
option(BUILD_WITH_EASY_PROFILER "Build with easy_profiler to profile" OFF)
if (BUILD_DX12)
add_definitions(-D__EFFEKSEER_BUILD_DX12__)
endif()
# for linux
if(UNIX AND NOT APPLE)
set(OpenGL_GL_PREFERENCE GLVND)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# detect IDE
if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
message("Build with postfix")
set(BUILD_WITH_POSTFIX ON)
else()
set(BUILD_WITH_POSTFIX OFF)
endif()
if(MSVC)
add_definitions(/MP)
endif()
if(SANITIZER_ENABLED AND MSVC)
STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
endif()
if(BUILD_WITH_EASY_PROFILER)
ExternalProject_Add(
ExternalProject_easy_profiler
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Dev/Cpp/3rdParty/easy_profiler
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/easy_profiler
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/easy_profiler
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/easy_profiler
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
if(BUILD_WITH_POSTFIX)
set(EASY_PROFILER_LIB_DEBUG "easy_profilerd")
set(EASY_PROFILER_LIB_RELEASE "easy_profiler")
else()
set(EASY_PROFILER_LIB_DEBUG "easy_profiler")
set(EASY_PROFILER_LIB_RELEASE "easy_profiler")
endif()
list(APPEND EFK_PROFILER_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/easy_profiler/include)
list(APPEND EFK_PROFILER_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/easy_profiler/lib)
endif()
if(BUILD_VULKAN)
# TODO : Improve it
option(USE_EXTERNAL_GLSLANG "Whether do it compile with external glslang" OFF)
if(USE_EXTERNAL_GLSLANG)
option(GLSLANG_INCLUDE_DIR "A directory which contains glslang includes" "")
else()
# Hack for GLSLANG
if (MSVC)
# CMAKE_MSVC_RUNTIME_LIBRARY can be only used if minimum required is larger than 3.17
if(USE_MSVC_RUNTIME_LIBRARY_DLL)
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
set(ENABLE_HLSL OFF CACHE BOOL "For glslang" FORCE)
set(ENABLE_CTEST OFF CACHE BOOL "For glslang" FORCE)
set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "For glslang" FORCE)
set(GLSLANG_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Dev/Cpp/3rdParty/glslang/" "${CMAKE_CURRENT_SOURCE_DIR}/Dev/Cpp/3rdParty/")
add_subdirectory(Dev/Cpp/3rdParty/glslang/)
endif()
endif()
if(BUILD_VIEWER)
# zlib
if(BUILD_WITH_POSTFIX)
set(ZLIB_INSTALL "")
else()
set(ZLIB_INSTALL ${CMAKE_COMMAND} --install . --prefix <INSTALL_DIR>)
endif()
ExternalProject_Add(
ExternalProject_zlib
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/zlib
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/zlib
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib
INSTALL_COMMAND ${ZLIB_INSTALL}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DASM686=off
-DAMD64=off
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib/include)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib/lib)
if(MSVC)
set(ZLIB_LIB_DEBUG "zlibstaticd")
set(ZLIB_LIB_RELEASE "zlibstatic")
elseif(BUILD_WITH_POSTFIX)
set(ZLIB_LIB_DEBUG "z")
set(ZLIB_LIB_RELEASE "z")
else()
set(ZLIB_LIB_DEBUG "z")
set(ZLIB_LIB_RELEASE "z")
endif()
# libpng
if(BUILD_WITH_POSTFIX)
set(LIBPNG_INSTALL "")
else()
set(LIBPNG_INSTALL ${CMAKE_COMMAND} --install . --prefix <INSTALL_DIR>)
endif()
ExternalProject_Add(
ExternalProject_libpng
DEPENDS ExternalProject_zlib
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Dev/Cpp/3rdParty/libpng
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/libpng
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libpng
INSTALL_COMMAND ${LIBPNG_INSTALL}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libpng
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DZLIB_INCLUDE_DIRS=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib/include
-DZLIB_INCLUDE_DIR=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib/include
-DPNG_BUILD_ZLIB=ON
-DPNG_SHARED=OFF
-DPNG_EXECUTABLES=OFF
-DPNG_TESTS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libpng/include)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libpng/lib)
if(MSVC)
set(LIBPNG_LIB_DEBUG "libpng16_staticd")
set(LIBPNG_LIB_RELEASE "libpng16_static")
elseif(BUILD_WITH_POSTFIX)
set(LIBPNG_LIB_DEBUG "png16d")
set(LIBPNG_LIB_RELEASE "png16")
else()
set(LIBPNG_LIB_DEBUG "png16")
set(LIBPNG_LIB_RELEASE "png16")
endif()
# libgd
ExternalProject_Add(
ExternalProject_libgd
DEPENDS ExternalProject_zlib
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/libgd
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/libgd
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libgd
PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Dev/3rdPartyPatch/libgd-getopt.c <SOURCE_DIR>/src/getopt.c
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libgd
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DZLIB_ROOT=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/zlib
-DBUILD_STATIC_LIBS=ON
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
if(MSVC)
set(GD_LIB_DEBUG "libgd_staticd")
set(GD_LIB_RELEASE "libgd_static")
elseif(BUILD_WITH_POSTFIX)
set(GD_LIB_DEBUG "gdd")
set(GD_LIB_RELEASE "gd")
else()
set(GD_LIB_DEBUG "gd")
set(GD_LIB_RELEASE "gd")
endif()
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libgd/include)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/libgd/lib)
# glew
if(WIN32)
ExternalProject_Add(
ExternalProject_glew
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/glew
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/glew
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glew
PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Dev/3rdPartyPatch/glew-CMakeLists.txt <SOURCE_DIR>/CMakeLists.txt
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glew
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DBUILD_SHARED_LIBS=OFF
-DGLEW_BUILD_INFO=OFF
-DBUILD_UTILS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glew/include)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glew/lib)
endif()
# OpenSoundMixer
ExternalProject_Add(
ExternalProject_OpenSoundMixer
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/OpenSoundMixer
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/OpenSoundMixer
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/OpenSoundMixer
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/OpenSoundMixer
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/OpenSoundMixer/src)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/OpenSoundMixer/lib)
if(BUILD_WITH_POSTFIX)
set(OSM_LIB_DEBUG "OpenSoundMixerd")
set(OSM_LIB_RELEASE "OpenSoundMixer")
else()
set(OSM_LIB_DEBUG "OpenSoundMixer")
set(OSM_LIB_RELEASE "OpenSoundMixer")
endif()
endif()
if(BUILD_VIEWER OR BUILD_EXAMPLES OR BUILD_TEST)
# glfw
ExternalProject_Add(
ExternalProject_glfw
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Downloads/glfw
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Build/glfw
INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glfw
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glfw
-DCMAKE_DEBUG_POSTFIX=d
-DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_CURRENT_SOURCE_DIR}/Dev/CFlagOverrides.cmake
-DEFK_USE_MSVC_RUNTIME_LIBRARY_DLL=${USE_MSVC_RUNTIME_LIBRARY_DLL}
-DGLFW_BUILD_EXAMPLES=OFF
-DGLFW_BUILD_TESTS=OFF
-DGLFW_BUILD_DOCS=OFF
-DGLFW_INSTALL=ON
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true
)
if(BUILD_WITH_POSTFIX)
set(GLFW3_LIB_DEBUG "glfw3d")
set(GLFW3_LIB_RELEASE "glfw3")
else()
set(GLFW3_LIB_DEBUG "glfw3")
set(GLFW3_LIB_RELEASE "glfw3")
endif()
list(APPEND EFK_THIRDPARTY_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glfw/include)
list(APPEND EFK_THIRDPARTY_LIBRARY_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/ThirdParty/Install/glfw/lib)
endif()
# resource
if (BUILD_VIEWER)
find_package(PythonInterp 3)
add_custom_target(ResourceData
SOURCES ResourceData.dummy
)
add_custom_command(
OUTPUT ResourceData.dummy
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Script/setup.py
)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(FilterFolder)
add_subdirectory(Dev)
if(BUILD_EXAMPLES)
# To use glfw in OpenGL projects
add_dependencies(EffekseerRendererGL ExternalProject_glfw)
set(EFK_RUNTIME_ROOT ${CMAKE_CURRENT_LIST_DIR}/Dev/Cpp)
add_subdirectory(Examples)
endif()
# specify filters
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (BUILD_VIEWER)
set_target_properties (ExternalProject_zlib PROPERTIES FOLDER thirdparty)
set_target_properties (ExternalProject_libpng PROPERTIES FOLDER thirdparty)
set_target_properties (ExternalProject_libgd PROPERTIES FOLDER thirdparty)
set_target_properties (ExternalProject_glfw PROPERTIES FOLDER thirdparty)
set_target_properties (ExternalProject_OpenSoundMixer PROPERTIES FOLDER thirdparty)
endif()