Skip to content

Commit ab6ff38

Browse files
committed
Merge branch 'minggo/metal-support' into feature/updateProgramState
* minggo/metal-support: sync v3 build related codes into metal-support (cocos2d#173) sync v3 cmake improvements into metal-support (cocos2d#172)
2 parents 5ce9cd0 + cff2ef8 commit ab6ff38

File tree

78 files changed

+508
-6479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+508
-6479
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ matrix:
22
include:
33
# linux
44
- os: linux
5+
dist: xenial
56
env:
67
- BUILD_TARGET=linux
78
- GEN_BINDING_AND_COCOSFILE=true
@@ -61,9 +62,10 @@ matrix:
6162
sudo: required
6263
- os: linux
6364
env: BUILD_TARGET=android_cocos_new_test
64-
language: cpp
65+
language: android
6566
sudo: required
6667
- os: linux
68+
dist: xenial
6769
env: BUILD_TARGET=linux_cocos_new_test
6870
language: cpp
6971
sudo: required

CMakeLists.txt

+25-6
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,34 @@ project(Cocos2d-x)
3434
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
3535
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
3636

37+
# prevent in-source-build
38+
include(PreventInSourceBuilds)
39+
AssureOutOfSourceBuilds()
40+
3741
# works before build libcocos2d
3842
include(CocosBuildSet)
3943

40-
# default tests include lua, js test project, so we set those option on to build libs
41-
set(BUILD_LUA_LIBS ON)
42-
set(BUILD_JS_LIBS ON)
44+
# for metal-support alpha release, we only test cpp
45+
set(BUILD_LUA_LIBS OFF)
46+
set(BUILD_JS_LIBS OFF)
47+
48+
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
49+
50+
# prevent tests project to build "cocos2d-x/cocos" again
51+
set(BUILD_ENGINE_DONE ON)
52+
53+
# add cpp tests default
54+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
55+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
56+
57+
if(BUILD_LUA_LIBS)
58+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
59+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
60+
endif(BUILD_LUA_LIBS)
4361

44-
if(NOT USE_COCOS_PREBUILT)
45-
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
62+
if(BUILD_JS_LIBS)
63+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
4664
endif()
47-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)
4865

66+
# add cpp-template-default into project(Cocos2d-x) for tmp test
67+
add_subdirectory(${COCOS2DX_ROOT_PATH}/templates/cpp-template-default ${ENGINE_BINARY_PATH}/tests/HelloCpp)

build/install-deps-linux.sh

+1-48
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/bin/bash
22

3-
# Change directory to the location of this script
43
echo "This Shell Script will install dependencies for cocos2d-x"
5-
echo "if you execute this shell more than once it will get errors when building libGLFW.so"
64
echo -n "Are you continue? (y/n) "
75
read answer
86
if echo "$answer" | grep -iq "^y" ;then
@@ -11,24 +9,13 @@ else
119
exit
1210
fi
1311

14-
cd $(dirname ${BASH_SOURCE[0]})
15-
16-
if [ ! $(command -v apt-get) ]; then
17-
echo "Not a .deb package system. Please install dependencies manually"
18-
exit 0
19-
fi
20-
21-
#install g++-4.9
22-
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y > /dev/null
2312
sudo apt-get update
2413

2514
DEPENDS='libx11-dev'
2615
DEPENDS+=' libxmu-dev'
2716
DEPENDS+=' libglu1-mesa-dev'
2817
DEPENDS+=' libgl2ps-dev'
2918
DEPENDS+=' libxi-dev'
30-
DEPENDS+=' gcc-4.9'
31-
DEPENDS+=' g++-4.9'
3219
DEPENDS+=' libzip-dev'
3320
DEPENDS+=' libpng12-dev'
3421
DEPENDS+=' libcurl4-gnutls-dev'
@@ -39,38 +26,4 @@ DEPENDS+=' libssl-dev'
3926
DEPENDS+=' libgtk-3-dev'
4027
DEPENDS+=' binutils'
4128

42-
MISSING=
43-
echo "Checking for missing packages ..."
44-
for i in $DEPENDS; do
45-
if ! dpkg-query -W --showformat='${Status}\n' $i | grep "install ok installed" > /dev/null; then
46-
MISSING+="$i "
47-
fi
48-
done
49-
50-
if [ -n "$MISSING" ]; then
51-
TXTCOLOR_DEFAULT="\033[0;m"
52-
TXTCOLOR_GREEN="\033[0;32m"
53-
echo -e $TXTCOLOR_GREEN"Missing packages: $MISSING.\nYou may be asked for your password for package installation."$TXTCOLOR_DEFAULT
54-
CUR_APT_VERSION="$(apt --version | grep -o '[0-9].[0-9]')"
55-
REQ_APT_VERSION="1.1"
56-
if [ 1 -ge "$(echo "${CUR_APT_VERSION} >= ${REQ_APT_VERSION}" | bc)" ]
57-
then
58-
sudo apt-get install --allow-change-held-packages $MISSING -y > /dev/null
59-
else
60-
sudo apt-get install --force-yes --yes $MISSING > /dev/null
61-
fi
62-
fi
63-
64-
65-
66-
sudo update-alternatives --remove-all gcc
67-
sudo update-alternatives --remove-all g++
68-
69-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60
70-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 60
71-
72-
echo "Cocos uses GCC Version: `gcc --version`"
73-
echo "Cocos uses G++ Version: `g++ --version`"
74-
echo "Cocos uses ld Version: `ld --version`"
75-
echo "Cocos uses /usr/bin/ld Version: `/usr/bin/ld --version`"
76-
29+
sudo apt-get install --force-yes --yes $DEPENDS > /dev/null

cmake/Modules/CocosBuildHelpers.cmake

+28-27
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,18 @@ function(cocos_mark_multi_resources res_out)
4545
set(${res_out} ${tmp_file_list} PARENT_SCOPE)
4646
endfunction()
4747

48-
# get `cocos_target` depend all dlls, save the result in `all_depend_dlls_out`
49-
function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
50-
set(all_depend_ext_dlls)
48+
# get all linked libraries including transitive ones, recursive
49+
function(search_depend_libs_recursive cocos_target all_depends_out)
50+
set(all_depends_inner)
5151
set(targets_prepare_search ${cocos_target})
52-
# targets_prepare_search, target need find ext libs
53-
set(have_searched_targets)
54-
set(need_search_targets)
5552
while(true)
5653
foreach(tmp_target ${targets_prepare_search})
5754
get_target_property(tmp_depend_libs ${tmp_target} LINK_LIBRARIES)
5855
list(REMOVE_ITEM targets_prepare_search ${tmp_target})
59-
# target itself use_cocos_pkg
6056
list(APPEND tmp_depend_libs ${tmp_target})
6157
foreach(depend_lib ${tmp_depend_libs})
6258
if(TARGET ${depend_lib})
63-
get_target_property(tmp_dlls ${depend_lib} CC_DEPEND_DLLS)
64-
if(tmp_dlls)
65-
list(APPEND all_depend_ext_dlls ${tmp_dlls})
66-
endif()
59+
list(APPEND all_depends_inner ${depend_lib})
6760
if(NOT (depend_lib STREQUAL tmp_target))
6861
list(APPEND targets_prepare_search ${depend_lib})
6962
endif()
@@ -75,6 +68,23 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
7568
break()
7669
endif()
7770
endwhile(true)
71+
set(${all_depends_out} ${all_depends_inner} PARENT_SCOPE)
72+
endfunction()
73+
74+
# get `cocos_target` depend all dlls, save the result in `all_depend_dlls_out`
75+
function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
76+
77+
set(depend_libs)
78+
set(all_depend_ext_dlls)
79+
search_depend_libs_recursive(${cocos_target} depend_libs)
80+
foreach(depend_lib ${depend_libs})
81+
if(TARGET ${depend_lib})
82+
get_target_property(tmp_dlls ${depend_lib} CC_DEPEND_DLLS)
83+
if(tmp_dlls)
84+
list(APPEND all_depend_ext_dlls ${tmp_dlls})
85+
endif()
86+
endif()
87+
endforeach()
7888

7989
set(${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE)
8090
endfunction()
@@ -168,7 +178,7 @@ function(setup_cocos_app_config app_name)
168178
elseif(MSVC)
169179
# only Debug and Release mode was supported when using MSVC.
170180
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/$<CONFIG>")
171-
set(APP_RES_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/${CMAKE_BUILD_TYPE}")
181+
set(APP_RES_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/${CMAKE_BUILD_TYPE}/Resources")
172182
#Visual Studio Defaults to wrong type
173183
set_target_properties(${app_name} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
174184
else(LINUX)
@@ -182,7 +192,6 @@ function(setup_cocos_app_config app_name)
182192
cocos_mark_code_files(${APP_NAME})
183193
endif()
184194

185-
set(APP_BIN_DIR ${APP_BIN_DIR} PARENT_SCOPE)
186195
set(APP_RES_DIR ${APP_RES_DIR} PARENT_SCOPE)
187196
endfunction()
188197

@@ -232,26 +241,18 @@ macro(cocos_pak_xcode cocos_target)
232241
set(MACOSX_BUNDLE_LONG_VERSION_STRING ${COCOS_APP_LONG_VERSION_STRING})
233242
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${COCOS_APP_SHORT_VERSION_STRING})
234243

235-
message("cocos package: ${cocos_target}, plist file: ${COCOS_APP_INFO_PLIST}")
244+
message(STATUS "cocos package: ${cocos_target}, plist file: ${COCOS_APP_INFO_PLIST}")
236245

237246
cocos_config_app_xcode_property(${cocos_target})
238247
endmacro()
239248

240249
# set Xcode property for application, include all depend target
241250
macro(cocos_config_app_xcode_property cocos_app)
242-
cocos_config_target_xcode_property(${cocos_app})
243-
# for example, cocos_target: cpp-tests link engine_lib: cocos2d
244-
get_target_property(engine_libs ${cocos_app} LINK_LIBRARIES)
245-
foreach(engine_lib ${engine_libs})
246-
if(TARGET ${engine_lib})
247-
cocos_config_target_xcode_property(${engine_lib})
248-
# for example, engine_lib: cocos2d link external_lib: flatbuffers
249-
get_target_property(external_libs ${engine_lib} LINK_LIBRARIES)
250-
foreach(external_lib ${external_libs})
251-
if(TARGET ${external_lib})
252-
cocos_config_target_xcode_property(${external_lib})
253-
endif()
254-
endforeach()
251+
set(depend_libs)
252+
search_depend_libs_recursive(${cocos_app} depend_libs)
253+
foreach(depend_lib ${depend_libs})
254+
if(TARGET ${depend_lib})
255+
cocos_config_target_xcode_property(${depend_lib})
255256
endif()
256257
endforeach()
257258
endmacro()

cmake/Modules/CocosBuildSet.cmake

+16-30
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
1-
# Disable in-source builds to prevent source tree corruption.
2-
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
3-
message(FATAL_ERROR "
4-
FATAL: In-source builds are not allowed.
5-
You should create a separate directory for build files.
6-
")
7-
endif()
8-
91
# print cmake debug info
102
set(CMAKE_DEBUG_TARGET_PROPERTIES
113
# INCLUDE_DIRECTORIES
124
# COMPILE_DEFINITIONS
5+
# COMPILE_OPTIONS
6+
# AUTOUIC_OPTIONS
137
# POSITION_INDEPENDENT_CODE
14-
# CONTAINER_SIZE_REQUIRED
15-
# LIB_VERSION
168
)
17-
# It ensures that when Find*.cmake files included from cmake's Modules dir
18-
# include another *.cmake file with relative path, that file will be included
19-
# also from cmake's Modules dir, to not clash with per-project files.
20-
cmake_policy(SET CMP0017 NEW)
21-
22-
# Use new behaviour with cmake >= 3.1:
23-
# Only interpret if() arguments as variables or keywords when unquoted.
24-
cmake_policy(SET CMP0054 NEW)
25-
26-
# print the info of CMAKE_TOOLCHAIN_FILE, if defined it
27-
if(DEFINED CMAKE_TOOLCHAIN_FILE)
28-
message(STATUS "using toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
29-
endif()
309

3110
# some useful variables for every one cocos project
32-
set(COCOS_EXTERNAL_DIR ${COCOS2DX_ROOT_PATH}/external)
3311
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)
3412

13+
if(CMAKE_TOOLCHAIN_FILE)
14+
message(STATUS "using toolchain file:" ${CMAKE_TOOLCHAIN_FILE})
15+
endif()
16+
3517
message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
3618
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
3719
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
3820
message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
39-
message(STATUS "COCOS_EXTERNAL_DIR:" ${COCOS_EXTERNAL_DIR})
4021
# delete binary dir if you hope a full clean re-build
4122
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
4223
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
4324

44-
# include helper functions for cmake build
45-
include(CocosBuildHelpers)
25+
# the default behavior of build module
26+
option(DEBUG_MODE "Debug or Release?" ON)
27+
option(BUILD_LUA_LIBS "Build lua libraries" OFF)
28+
option(BUILD_JS_LIBS "Build js libraries" OFF)
4629

47-
# select building modules
48-
include(CocosSelectModule)
30+
# include helper functions
31+
include(CocosBuildHelpers)
4932

5033
# set common compiler options
51-
include(CocosCompileOptions)
34+
# add target compile define function
35+
# add target compile options function
36+
include(CocosConfigDefine)
5237

38+
# config libraries dependence
5339
include(CocosConfigDepend)

0 commit comments

Comments
 (0)