Skip to content

Commit d80c3d8

Browse files
drelaptopminggo
authored and
minggo
committed
sync v3 cmake improvements into metal-support (cocos2d#172)
* pick: modern cmake, compile definitions improvement (cocos2d#19139) * modern cmake, use target_compile_definitions partly * simplify macro define, remove USE_* * modern cmake, macro define * add physics 2d macro define into ccConfig.h * remove USE_CHIPMUNK macro in build.gradle * remove CocosSelectModule.cmake * shrink useless define * simplify compile options config, re-add if necessary * update external for tmp CI test * un-quote target_compile_options value * add "-g" parameter only when debug mode * keep single build type when generator Xcode & VS projecy * update external for tmp CI tes * add static_cast<char>(-1), fix -Wc++11-narrowing * simplify win32 compile define * not modify code, only improve compile options # Conflicts: # .gitignore # cmake/Modules/CocosConfigDepend.cmake # cocos/CMakeLists.txt # external/config.json # tests/cpp-tests/CMakeLists.txt * modern cmake, improve cmake_compiler_flags (cocos2d#19145) * cmake_compiler_flags * Fix typo * Fix typo2 * Remove chanages from Android.mk * correct lua template cmake build (cocos2d#19149) * don't add -Wno-deprecated into jsb target * correct lua template cmake build * fix win32 lua template compile error * prevent cmake in-source-build friendly (cocos2d#19151) * pick: Copy resources to "Resources/" on win32 like in linux configuration * add "/Z7" for cpp-tests on windows * [cmake] fix iOS xcode property setting failed (cocos2d#19208) * fix iOS xcode property setting failed * use search_depend_libs_recursive at dlls collect * fix typo * [cmake] add find_host_library into iOS toolchain file (cocos2d#19230) * pick: [lua android] use luajit & template cmake update (cocos2d#19239) * increase cmake stability , remove tests/CMakeLists.txt (cocos2d#19261) * cmake win32 Precompiled header (cocos2d#19273) * Precompiled header * Fix * Precompiled header for cocos * Precompiled header jscocos2d * Fix for COCOS2D_DEBUG is always 1 on Android (cocos2d#19291) Related cocos2d#19289 * little build fix, tests cpp-tests works on mac
1 parent 578c71a commit d80c3d8

File tree

42 files changed

+506
-572
lines changed

Some content is hidden

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

42 files changed

+506
-572
lines changed

CMakeLists.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,24 @@ 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

4044
# default tests include lua, js test project, so we set those option on to build libs
4145
set(BUILD_LUA_LIBS ON)
4246
set(BUILD_JS_LIBS ON)
4347

44-
if(NOT USE_COCOS_PREBUILT)
45-
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
46-
endif()
47-
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)
48+
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
4849

50+
# prevent tests project to build "cocos2d-x/cocos" again
51+
set(BUILD_ENGINE_DONE ON)
52+
# add engine all tests project
53+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
54+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
55+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
56+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
57+
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)

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-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ endif()
1010
set(CMAKE_DEBUG_TARGET_PROPERTIES
1111
# INCLUDE_DIRECTORIES
1212
# COMPILE_DEFINITIONS
13+
# COMPILE_OPTIONS
14+
# AUTOUIC_OPTIONS
1315
# POSITION_INDEPENDENT_CODE
14-
# CONTAINER_SIZE_REQUIRED
15-
# LIB_VERSION
1616
)
1717
# It ensures that when Find*.cmake files included from cmake's Modules dir
1818
# include another *.cmake file with relative path, that file will be included
@@ -32,6 +32,10 @@ endif()
3232
set(COCOS_EXTERNAL_DIR ${COCOS2DX_ROOT_PATH}/external)
3333
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)
3434

35+
if(CMAKE_TOOLCHAIN_FILE)
36+
message(STATUS "using toolchain file:" ${CMAKE_TOOLCHAIN_FILE})
37+
endif()
38+
3539
message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
3640
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
3741
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
@@ -41,13 +45,18 @@ message(STATUS "COCOS_EXTERNAL_DIR:" ${COCOS_EXTERNAL_DIR})
4145
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
4246
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
4347

44-
# include helper functions for cmake build
45-
include(CocosBuildHelpers)
48+
# the default behavior of build module
49+
option(DEBUG_MODE "Debug or Release?" ON)
50+
option(BUILD_LUA_LIBS "Build lua libraries" OFF)
51+
option(BUILD_JS_LIBS "Build js libraries" OFF)
4652

47-
# select building modules
48-
include(CocosSelectModule)
53+
# include helper functions
54+
include(CocosBuildHelpers)
4955

5056
# set common compiler options
51-
include(CocosCompileOptions)
57+
# add target compile define function
58+
# add target compile options function
59+
include(CocosConfigDefine)
5260

61+
# config libraries dependence
5362
include(CocosConfigDepend)

cmake/Modules/CocosCompileOptions.cmake

-191
This file was deleted.

0 commit comments

Comments
 (0)