-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
211 lines (185 loc) · 8.16 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
#/****************************************************************************
# 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.
# ****************************************************************************/
# NOTE cocos console parses this CMakeLists.txt and looks for a variable named APP_NAME
# so it's recommended not to rename it to anything else.
set(APP_NAME Cocos2dxTemplate)
project(${APP_NAME})
# 3.6 is the minimum for Cocos2d-x 3.17.1.
# Would like to use 3.7+, but currently getting weird invalid char error with it
# in Android Studio.
cmake_minimum_required(VERSION 3.6)
option(SUPPRESS_ENGINE_BUILD_WARNINGS "Suppress engine code's build warnings (there are plenty of them)." ON)
if (NOT DEFINED COCOS2DX_ROOT_PATH)
message(FATAL_ERROR "COCOS2DX_ROOT_PATH not defined, aborting.")
endif()
message(STATUS "COCOS2DX_ROOT_PATH=${COCOS2DX_ROOT_PATH}")
file(TO_CMAKE_PATH ${COCOS2DX_ROOT_PATH} COCOS2DX_ROOT_PATH)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# The next line will fail if COCOS2DX_ROOT_PATH does not point to a valid Cocos2d-x directory structure
include(CocosBuildSet)
include(cmake/Utils.cmake)
include(cmake/PrecompiledHeader.cmake)
# Detect if using code newer than the 3.17.1 release. E.g. WinRT and Tizen support has been dropped after
# the 3.17.1 release: https://github.com/cocos2d/cocos2d-x/commit/0e996a9e0076dced404f699e96b5a319e1042efa
if (NOT EXISTS "${COCOS2DX_ROOT_PATH}/cocos/platform/winrt/CCApplication.h")
set(LATEST_COCOS2DX ON)
message(STATUS "Cocos2d-x newer than 3.17.1 release detected.")
endif()
# Were only interested in the engine, not in the editor. Extensions seem to contain some usable stuff, so keep them on.
set(BUILD_EDITOR_COCOSBUILDER OFF CACHE BOOL "Build editor support for cocosbuilder" FORCE)
set(BUILD_EDITOR_COCOSTUDIO OFF CACHE BOOL "Build editor support for cocostudio" FORCE)
set(BUILD_EDITOR_SPINE OFF CACHE BOOL "Build editor support for spine" FORCE)
#set(BUILD_EXTENSIONS OFF CACHE BOOL "Build extension library" FORCE)
# Suppress Policy CMP0003 spam coming from COCOS2DX_ROOT_PATH/cocos/CMakeLists.txt
if (COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif()
add_subdirectory("${COCOS2DX_ROOT_PATH}/cocos" "${ENGINE_BINARY_PATH}/cocos/core")
if (SUPPRESS_ENGINE_BUILD_WARNINGS)
SuppressCocosEngineBuildWarnings()
endif()
# Shared source files
list(APPEND GAME_HEADER
src/AppMacros.h
src/IncludeCocos2dBegin.h
src/IncludeCocos2dEnd.h
src/HelloWorldScene.h
src/AppDelegate.h
)
list(APPEND GAME_SOURCE
src/AppDelegate.cpp
src/HelloWorldScene.cpp
)
# Platform-specific source and resource files
set(GAME_RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/Resources")
if (APPLE OR VS)
cocos_mark_multi_resources(cc_common_res RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER})
endif()
if (ANDROID)
list(APPEND GAME_SOURCE android/app/jni/main.cpp)
elseif(WINDOWS)
list(APPEND GAME_HEADER win32/resource.h)
list(APPEND GAME_SOURCE src/main.cpp win32/${APP_NAME}.rc ${common_res_files})
elseif(LINUX)
list(APPEND GAME_SOURCE src/main.cpp)
elseif(APPLE)
if(IOS)
list(APPEND GAME_HEADER
ios/AppController.h
ios/RootViewController.h
)
set(APP_UI_RES
ios/LaunchScreen.storyboard
ios/LaunchScreenBackground.png
ios/Images.xcassets
)
list(APPEND GAME_SOURCE
ios/main.m
ios/AppController.mm
ios/RootViewController.mm
${APP_UI_RES}
)
elseif(MACOSX)
set(APP_UI_RES
macos/Icon.icns
macos/Info.plist
macos/en.lproj/MainMenu.xib
macos/en.lproj/InfoPlist.strings
)
list(APPEND GAME_SOURCE src/main.cpp ${APP_UI_RES})
endif()
list(APPEND GAME_SOURCE ${cc_common_res})
endif()
if (ANDROID)
# The native code is included to Android application as a shared library so alter
# the name to reflect this. The name must match to the name in android/app/AndroidManifest.xml.
set(APP_NAME "${APP_NAME}Lib")
add_library(${APP_NAME} SHARED ${GAME_HEADER} ${GAME_SOURCE})
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)
else()
add_executable(${APP_NAME} ${GAME_HEADER} ${GAME_SOURCE})
endif()
# TODO Preferably 17
set_property(TARGET ${APP_NAME} PROPERTY CXX_STANDARD 14)
# With CMake >= 3.8 use target_compile_features() is recommended:
#target_compile_features(${APP_NAME} PRIVATE cxx_std_17)
target_link_libraries(${APP_NAME} cocos2d)
target_include_directories(${APP_NAME} PRIVATE src)
# TODO Support for "cocos deploy"
# if (WIN32)
# set_target_properties(
# ${APP_NAME} PROPERTIES
# RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/Debug.win32/${APP_NAME}"
# RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/Release.win32/${APP_NAME}"
# )
# endif()
if (MSVC)
target_compile_options(${APP_NAME} PRIVATE /W4 /utf-8 /permissive-)
# Enforce Unicode for Win32 and CRT APIs.
target_compile_definitions(${APP_NAME} PRIVATE -DUNICODE -D_UNICODE)
else()
target_compile_options(${APP_NAME} PRIVATE -Wall -Wextra -Wshadow)
# Don't want to use -Wpedantic for GCC < 8.1 as it would cause warning spam
# (extraneous semicolons) that cannot be suppressed.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
target_compile_options(${APP_NAME} PRIVATE -Wpedantic)
endif()
endif()
# PCH
target_sources(${APP_NAME} PRIVATE "src/pch.h")
if (MSVC)
target_sources(${APP_NAME} PRIVATE "src/pch.cpp")
endif()
add_precompiled_header(${APP_NAME} "src/pch.h" FORCEINCLUDE SOURCE_CXX "src/pch.cpp")
# TODO Don't probably want to use this. At least personally I prefer e.g.
# "Header Files" and "Source Files" instead of single "Source Files".
# This function also defines APP_BIN_DIR and APP_RES_DIR
setup_cocos_app_config(${APP_NAME})
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
if(MACOSX)
set_target_properties(
${APP_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/macos/Info.plist"
)
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "")
set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
endif()
elseif(WINDOWS)
if (LATEST_COCOS2DX)
cocos_copy_target_dll(${APP_NAME})
else()
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_RES_DIR}/..)
endif()
endif()
if (LINUX OR WINDOWS)
if (LATEST_COCOS2DX)
set(APP_RES_DIR "$<TARGET_FILE_DIR:${APP_NAME}>/Resources")
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
else()
cocos_copy_res(COPY_TO ${APP_RES_DIR} FOLDERS ${GAME_RES_FOLDER})
endif()
endif()