-
Notifications
You must be signed in to change notification settings - Fork 52
/
CMakeLists.txt
executable file
·341 lines (309 loc) · 15.1 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
#/****************************************************************************
# Copyright (c) 2013-2014 cocos2d-x.org
# Copyright (c) 2015-2017 Chukong Technologies Inc.
#
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/
cmake_minimum_required(VERSION 3.16)
option(CCLUA_BUILD_SPINE "Build with spine support" ON)
option(CCLUA_BUILD_COCOSSTUDIO "Build with cocos studio support" OFF)
option(CCLUA_BUILD_PBC "Build with pbc support" ON)
option(CCLUA_BUILD_SPROTO "Build with sproto support" ON)
option(CCLUA_BUILD_LPEG "Build with lpeg support" ON) # if CCLUA_BUILD_SPROTO ON then lpeg auto set ON end
option(CCLUA_BUILD_BUGLY "Build with bugly support" ON)
option(CCLUA_BUILD_LUASOCKET "Build with lua_socket support" ON)
option(CCLUA_BUILD_SQLITE3 "Build with sqlite3 support" OFF)
option(CCLUA_BUILD_FAIRYGUI "Build with fairygui support" ON)
option(CCLUA_BUILD_DRAGONBONES "Build with dragonbones support" OFF)
option(CCLUA_BUILD_BOX2D "Build with box2d support" ON)
option(CCLUA_BUILD_SWF "Build with swf support" OFF)
option(CCLUA_BUILD_JPUSH "Build with jpush support" OFF)
option(CCLUA_BUILD_JAUTH "Build with jauth support" OFF)
option(CCLUA_BUILD_JANALYTICS "Build with janalytics support" OFF)
option(CCLUA_BUILD_TALKINGDATA "Build with talkingdata support" OFF)
option(CCLUA_BUILD_WECHAT "Build with wechat support" OFF)
option(CCLUA_BUILD_ALIPAY "Build with alipay support" OFF)
option(CCLUA_BUILD_HUAWEI "Build with huawei support" OFF)
option(CCLUA_BUILD_OPPO "Build with oppo support" OFF)
option(CCLUA_BUILD_VIVO "Build with vivo support" OFF)
option(CCLUA_FEATURE_MSAA "Support MSAA" OFF)
option(CCLUA_FEATURE_TRACKING "Support TRACKING" OFF)
option(CCLUA_FEATURE_INTCOLOR "Support integer color" ON)
include(config.cmake)
project(${APP_PROJECT_NAME})
if(ANDROID)
set(APP_NAME ${APP_ANDROID_NAME})
endif()
add_definitions(-DCC_FILEUTILS_APPLE_ENABLE_OBJC=0)
add_definitions(-DCC_ENABLE_SCRIPT_BINDING=0)
add_definitions(-DCC_CONSTRUCTOR_ACCESS=public)
if(CCLUA_BUILD_SPINE)
set(BUILD_EDITOR_SPINE ON)
add_definitions(-DSPINE_USE_STD_FUNCTION)
else()
set(BUILD_EDITOR_SPINE OFF)
endif()
if(NOT DEFINED BUILD_ENGINE_DONE)
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
include(CocosBuildSet)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
# runtime-src
set(RUNTIME_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/runtime-src)
# record sources, headers, resources...
set(GAME_SOURCE)
set(GAME_HEADER)
set(GAME_RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/assets")
if(APPLE)
file(GLOB folder_files "${GAME_RES_FOLDER}/*")
foreach(file ${folder_files})
if(NOT ${file} MATCHES ".DS_Store$")
list(APPEND common_res_files ${file})
set_source_files_properties(${file} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
source_group("Resources" FILES ${file})
endif()
endforeach()
elseif(WINDOWS)
cocos_mark_multi_resources(common_res_files RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER})
endif()
# add cross-platforms source files and header files
list(APPEND GAME_SOURCE ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp)
list(APPEND GAME_HEADER ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.h)
if(ANDROID)
# change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
list(APPEND GAME_SOURCE ${RUNTIME_SRC_ROOT}/proj.android/app/jni/hellocpp/main.cpp)
elseif(LINUX)
list(APPEND GAME_SOURCE ${RUNTIME_SRC_ROOT}/proj.linux/main.cpp)
elseif(WINDOWS)
list(APPEND GAME_HEADER
${RUNTIME_SRC_ROOT}/proj.win32/main.h
${RUNTIME_SRC_ROOT}/proj.win32/resource.h
)
list(APPEND GAME_SOURCE
${RUNTIME_SRC_ROOT}/proj.win32/main.cpp
${RUNTIME_SRC_ROOT}/proj.win32/game.rc
${common_res_files}
)
elseif(APPLE)
if(IOS)
list(APPEND GAME_HEADER
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/AppController.h
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/RootViewController.h
)
set(APP_UI_RES
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreen.storyboard
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreenBackground.png
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/Images.xcassets
)
list(APPEND GAME_SOURCE
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/main.m
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/AppController.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/RootViewController.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/Prefix.pch
${APP_UI_RES}
)
elseif(MACOSX)
set(APP_UI_RES ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Icon.icns)
list(APPEND GAME_SOURCE
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/main.cpp
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Prefix.pch
${APP_UI_RES}
)
endif()
list(APPEND GAME_SOURCE ${common_res_files})
endif()
# mark app complie info and libs info
set(all_code_files
${GAME_HEADER}
${GAME_SOURCE}
)
if(NOT ANDROID)
add_executable(${APP_NAME} ${all_code_files})
else()
add_library(${APP_NAME} SHARED ${all_code_files})
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android ${ENGINE_BINARY_PATH}/cocos/platform)
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME} GROUPBASE ${RUNTIME_SRC_ROOT})
endif()
target_compile_definitions(${APP_NAME} PUBLIC APP_NAME="${APP_NAME}")
target_compile_definitions(${APP_NAME} PUBLIC APP_PACKAGE_NAME="${APP_PACKAGE_NAME}")
target_link_libraries(${APP_NAME} cocos2d)
target_include_directories(${APP_NAME}
PRIVATE
${RUNTIME_SRC_ROOT}/Classes
${COCOS2DX_ROOT_PATH}/cocos/audio/include/
)
function(add_module path)
set(oneValue LINK_TO FOLDER)
set(multiValue TARGETS ENABLEIF DEFINITIONS)
cmake_parse_arguments("ARG" "" "${oneValue}" "${multiValue}" ${ARGN})
if(NOT DEFINED ARG_ENABLEIF OR (${ARG_ENABLEIF}))
add_subdirectory(${path})
message(STATUS "add module: ${path}")
string(REPLACE ";" " " ARG_DEFINITIONS "${ARG_DEFINITIONS}")
foreach(name ${ARG_TARGETS})
if(DEFINED ARG_DEFINITIONS)
target_compile_definitions(${name} PUBLIC ${ARG_DEFINITIONS})
endif()
if(DEFINED ARG_FOLDER)
set_target_properties(${name} PROPERTIES FOLDER ${ARG_FOLDER})
endif()
target_link_libraries(${ARG_LINK_TO} ${name})
set_target_properties(${name}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
endforeach()
endif()
endfunction()
add_module(frameworks/cclua TARGETS cclua LINK_TO ${APP_NAME})
add_module(frameworks/libswf TARGETS swf LINK_TO ${APP_NAME} ENABLEIF CCLUA_BUILD_SWF DEFINITIONS CCLUA_BUILD_SWF)
add_module(frameworks/3rd/box2d TARGETS box2d LINK_TO cclua FOLDER "3rd" ENABLEIF CCLUA_BUILD_BOX2D DEFINITIONS CCLUA_BUILD_BOX2D)
add_module(frameworks/3rd/bzip2 TARGETS bz2 LINK_TO cclua FOLDER "3rd")
add_module(frameworks/3rd/cjson TARGETS cjson LINK_TO ${APP_NAME} FOLDER "3rd")
add_module(frameworks/3rd/dragonbones TARGETS dragonbones LINK_TO cclua FOLDER "3rd" ENABLEIF CCLUA_BUILD_DRAGONBONES DEFINITIONS CCLUA_BUILD_DRAGONBONES)
add_module(frameworks/3rd/fairygui TARGETS fairygui LINK_TO cclua FOLDER "3rd" ENABLEIF CCLUA_BUILD_FAIRYGUI DEFINITIONS CCLUA_BUILD_FAIRYGUI)
add_module(frameworks/3rd/glsl-optimizer TARGETS glsl_optimizer LINK_TO cocos2d FOLDER "3rd" ENABLEIF APPLE)
add_module(frameworks/3rd/freetype TARGETS freetype LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/glfw TARGETS glfw LINK_TO cocos2d FOLDER "3rd" ENABLEIF WINDOWS OR MACOSX OR LINUX)
add_module(frameworks/3rd/jpeg TARGETS jpeg LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/lfs TARGETS lfs LINK_TO ${APP_NAME} FOLDER "3rd")
add_module(frameworks/3rd/lmd5 TARGETS lmd5 LINK_TO ${APP_NAME} FOLDER "3rd")
add_module(frameworks/3rd/lpeg TARGETS lpeg LINK_TO ${APP_NAME} FOLDER "3rd" ENABLEIF CCLUA_BUILD_LPEG DEFINITIONS CCLUA_BUILD_LPEG)
add_module(frameworks/3rd/lua TARGETS lua LINK_TO cclua FOLDER "3rd")
add_module(frameworks/3rd/luaopenssl TARGETS luaopenssl LINK_TO ${APP_NAME} FOLDER "3rd")
add_module(frameworks/3rd/luasocket TARGETS luasocket LINK_TO ${APP_NAME} FOLDER "3rd" ENABLEIF CCLUA_BUILD_LUASOCKET DEFINITIONS CCLUA_BUILD_LUASOCKET)
add_module(frameworks/3rd/md5 TARGETS md5 LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/pbc TARGETS pbc LINK_TO ${APP_NAME} FOLDER "3rd" ENABLEIF CCLUA_BUILD_PBC DEFINITIONS CCLUA_BUILD_PBC)
add_module(frameworks/3rd/png TARGETS png LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/sproto TARGETS sproto LINK_TO ${APP_NAME} FOLDER "3rd" ENABLEIF CCLUA_BUILD_SPROTO DEFINITIONS CCLUA_BUILD_SPROTO)
add_module(frameworks/3rd/sqlite3 TARGETS sqlite3 LINK_TO ${APP_NAME} FOLDER "3rd" ENABLEIF CCLUA_BUILD_SQLITE3 DEFINITIONS CCLUA_BUILD_SQLITE3)
add_module(frameworks/3rd/openssl TARGETS ssl crypto LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/unzip TARGETS unzip LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/xxtea TARGETS xxtea LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/3rd/zlib TARGETS zlib LINK_TO cocos2d FOLDER "3rd")
add_module(frameworks/plugins/alipay TARGETS plugin_alipay LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_ALIPAY)
add_module(frameworks/plugins/apple TARGETS plugin_apple LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF APPLE)
add_module(frameworks/plugins/huawei TARGETS plugin_huawei LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_HUAWEI)
add_module(frameworks/plugins/janalytics TARGETS plugin_janalytics LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_JANALYTICS)
add_module(frameworks/plugins/jauth TARGETS plugin_jauth LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_JAUTH)
add_module(frameworks/plugins/jpush TARGETS plugin_jpush LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_JPUSH)
add_module(frameworks/plugins/oppo TARGETS plugin_oppo LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_OPPO)
add_module(frameworks/plugins/talkingdata TARGETS plugin_talkingdata LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_TALKINGDATA)
add_module(frameworks/plugins/vivo TARGETS plugin_vivo LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_VIVO)
add_module(frameworks/plugins/wechat TARGETS plugin_wechat LINK_TO ${APP_NAME} FOLDER "Plugins" ENABLEIF CCLUA_BUILD_WECHAT)
# suspend warnings
if(APPLE)
target_compile_options(cocos2d
PRIVATE
-Wno-reorder
-Wno-deprecated-declarations
-Wno-shorten-64-to-32
-Wno-comma
)
if(CCLUA_BUILD_FAIRYGUI)
target_compile_options(fairygui
PRIVATE
-Wno-reorder
-Wno-shorten-64-to-32
)
endif()
if(CCLUA_BUILD_DRAGONBONES)
target_compile_options(dragonbones
PRIVATE
-Wno-shorten-64-to-32
)
endif()
if(CCLUA_BUILD_BOX2D)
target_compile_options(box2d
PRIVATE
-Wno-shorten-64-to-32
)
endif()
endif()
# link other flags
if(IOS)
set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS -ObjC)
endif()
# mark app resources
setup_cocos_app_config(${APP_NAME})
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
if(MACOSX)
set_xcode_property(${APP_NAME} INFOPLIST_FILE "${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Info.plist")
elseif(IOS)
set_xcode_property(${APP_NAME} INFOPLIST_FILE "${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/Info.plist")
set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
set_xcode_property(${APP_NAME} CODE_SIGN_ENTITLEMENTS "${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/app.entitlements")
set(CMAKE_XCODE_ATTRIBUTE_ARCHS "arm64")
endif()
# For code-signing, set the DEVELOPMENT_TEAM:
set_xcode_property(${APP_NAME} CLANG_ENABLE_OBJC_ARC "YES")
set_xcode_property(${APP_NAME} SKIP_INSTALL "NO")
set_xcode_property(${APP_NAME} INSTALL_PATH "$(LOCAL_APPS_DIR)")
set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "${APPLE_DEVELOPMENT_TEAM}")
set_xcode_property(${APP_NAME} PRODUCT_BUNDLE_IDENTIFIER "${APP_PACKAGE_NAME}")
set_xcode_property(${APP_NAME} PRODUCT_NAME "${APP_NAME}")
set_xcode_property(${APP_NAME} CURRENT_PROJECT_VERSION "${APP_BUILD}")
set_xcode_property(${APP_NAME} MARKETING_VERSION "${APP_VERSION}")
set_xcode_property(${APP_NAME} TARGETED_DEVICE_FAMILY "1,2")
# set_xcode_property(${APP_NAME} GCC_GENERATE_DEBUGGING_SYMBOLS "YES")
# set_xcode_property(${APP_NAME} DEBUG_INFORMATION_FORMAT "DWARF")
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET)
SET (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 12.0)
endif()
# warnings
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_BOOL_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_COMMA "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_ENUM_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INFINITE_RECURSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_INT_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_NON_LITERAL_NULL_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_STRICT_PROTOTYPES "YES")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_UNREACHABLE_CODE "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_CLANG_WARN_EMPTY_BODY "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_ABOUT_RETURN_TYPE "YES_ERROR")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_MISSING_PARENTHESES "YES")
set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_UNINITIALIZED_AUTOS "YES")
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME})
endif()
if(LINUX OR WINDOWS)
cocos_get_resource_path(APP_RES_DIR ${APP_NAME})
cocos_copy_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()
# TODO: remove
if(WINDOWS)
get_target_property(rt_output ${APP_NAME} RUNTIME_OUTPUT_DIRECTORY)
add_custom_command(TARGET ${APP_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/frameworks/3rd/openssl/prebuilt/win32/libcrypto-1_1.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/frameworks/3rd/openssl/prebuilt/win32/libssl-1_1.dll"
"${rt_output}/${CMAKE_CFG_INTDIR}"
)
endif()