Skip to content

Commit

Permalink
refactor cmake on use libs (cocos2d#19054)
Browse files Browse the repository at this point in the history
* link external build by modern cmake

* use "--whole-archive" for part android spec

* update travis

* update CI, add cmake tests on win32
  • Loading branch information
drelaptop authored Sep 25, 2018
1 parent a504c54 commit 98120fb
Show file tree
Hide file tree
Showing 31 changed files with 544 additions and 1,163 deletions.
5 changes: 3 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ environment:
PYTHON_VERSION: "2.7.13"
PYTHON_ARCH: "32"
matrix:
- build_type: windows32_cocos_new_test
- build_type: windows32
- build_type: windows32_cmake_test
- build_type: windows32_sln_test
- build_type: android_cpp_tests
- build_type: android_lua_tests
# - build_type: android_cocos_new_test
# - build_type: android_cpp_empty_test
# - build_type: android_gen_libs
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ matrix:
env: BUILD_TARGET=android_lua_cmake
language: android
sudo: required
# android_js cmake
- os: linux
env: BUILD_TARGET=android_js_cmake
language: android
sudo: required
# mac
- os: osx
env: BUILD_TARGET=mac
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# build engine library and all tests

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.6)

project(Cocos2d-x)

Expand Down
79 changes: 11 additions & 68 deletions cmake/Modules/CocosBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
list(APPEND tmp_depend_libs ${tmp_target})
foreach(depend_lib ${tmp_depend_libs})
if(TARGET ${depend_lib})
get_target_property(tmp_dlls ${depend_lib} DEPEND_DLLS)
get_target_property(tmp_dlls ${depend_lib} CC_DEPEND_DLLS)
if(tmp_dlls)
list(APPEND all_depend_ext_dlls ${tmp_dlls})
endif()
Expand All @@ -103,7 +103,10 @@ function(cocos_copy_target_dll cocos_target)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_target_depends_ext_dlls(${cocos_target} all_depend_dlls)
# remove repeat items
list(REMOVE_DUPLICATES all_depend_dlls)
if(all_depend_dlls)
list(REMOVE_DUPLICATES all_depend_dlls)
endif()
# todo, add a option to enable/disable debug print
message(STATUS "prepare to copy external dlls for ${cocos_target}:${all_depend_dlls}")
foreach(cc_dll_file ${all_depend_dlls})
get_filename_component(cc_dll_name ${cc_dll_file} NAME)
Expand Down Expand Up @@ -188,34 +191,8 @@ function(source_group_single_file single_file)
source_group("${ide_file_group}" FILES ${single_file})
endfunction()

# build a cocos application
# hrough compile the files `APP_SRC`, link the libs in `*LIBS`, use the packages in `*.PKGS`
# this method hide the link lib details, those is prebuilt libs or not
function(cocos_build_app app_name)
set(multiValueArgs
APP_SRC
DEPEND_COMMON_LIBS
DEPEND_ANDROID_LIBS
COMMON_USE_PKGS
LINUX_USE_PKGS
DEPEND_MACOSX_LIBS
DEPEND_WINDOWS_LIBS
)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(ANDROID)
add_library(${app_name} SHARED ${opt_APP_SRC})
foreach(android_lib ${opt_DEPEND_ANDROID_LIBS})
if(USE_COCOS_PREBUILT)
target_link_libraries(${app_name} -Wl,-whole-archive "${${_${android_lib}_prefix}_LIBRARIES}" -Wl,-no-whole-archive)
else()
target_link_libraries(${app_name} -Wl,-whole-archive ${android_lib} -Wl,-no-whole-archive)
add_dependencies(${app_name} ${android_lib})
endif()
endforeach()
else()
add_executable(${app_name} ${opt_APP_SRC})
endif()
# setup a cocos application, include "APP_BIN_DIR", "APP_RES_DIR" config
function(setup_cocos_app_config app_name)
# set target PROPERTIES, depend different platforms
if(APPLE)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
Expand All @@ -233,47 +210,13 @@ function(cocos_build_app app_name)
endif()
set_target_properties(${app_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")

if(MACOSX)
list(APPEND opt_DEPEND_COMMON_LIBS ${opt_DEPEND_MACOSX_LIBS})
elseif(WINDOWS)
list(APPEND opt_DEPEND_COMMON_LIBS ${opt_DEPEND_WINDOWS_LIBS})
endif()
# link commom libs, and common libs need external or system libs
if(USE_COCOS_PREBUILT)
include(CocosUseLibs)
foreach(common_lib ${opt_DEPEND_COMMON_LIBS})
message(STATUS "${app_name} prepare to link engine lib: ${common_lib}")
cocos_use_pkg(${app_name} ${_${common_lib}_prefix})
if(common_lib STREQUAL "cocos2d")
target_use_cocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "jscocos2d")
target_use_jscocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "luacocos2d")
target_use_luacocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "simulator")
target_use_simulator_depend_libs(${app_name})
endif()
endforeach()
else()
foreach(common_lib ${opt_DEPEND_COMMON_LIBS})
target_link_libraries(${app_name} ${common_lib})
add_dependencies(${app_name} ${common_lib})
endforeach()
endif()

if(LINUX)
foreach(_pkg ${opt_LINUX_USE_PKGS})
cocos_use_pkg(${app_name} ${_pkg})
endforeach()
endif()
foreach(_pkg ${opt_COMMON_USE_PKGS})
cocos_use_pkg(${app_name} ${_pkg})
endforeach()
# auto mark code files for IDE when mark app
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()

# generate prebuilt auto when build app if GEN_COCOS_PREBUILT=ON
# tocheck, do we really need prebuilt cocos2dx libs?
if(GEN_COCOS_PREBUILT)
add_dependencies(${APP_NAME} prebuilt)
endif()
Expand Down Expand Up @@ -440,13 +383,13 @@ function(cocos_use_pkg target pkg)
# message(STATUS "${target} add dll: ${_dlls}")
get_property(pre_dlls
TARGET ${target}
PROPERTY DEPEND_DLLS)
PROPERTY CC_DEPEND_DLLS)
if(pre_dlls)
set(_dlls ${pre_dlls} ${_dlls})
endif()
set_property(TARGET ${target}
PROPERTY
DEPEND_DLLS ${_dlls}
CC_DEPEND_DLLS ${_dlls}
)
endif()
endif()
Expand Down
208 changes: 0 additions & 208 deletions cmake/Modules/CocosBuildModules.cmake

This file was deleted.

14 changes: 9 additions & 5 deletions cmake/Modules/CocosBuildSet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
")
endif()

# print cmake debug info
set(CMAKE_DEBUG_TARGET_PROPERTIES
# INCLUDE_DIRECTORIES
# COMPILE_DEFINITIONS
# POSITION_INDEPENDENT_CODE
# CONTAINER_SIZE_REQUIRED
# LIB_VERSION
)
# It ensures that when Find*.cmake files included from cmake's Modules dir
# include another *.cmake file with relative path, that file will be included
# also from cmake's Modules dir, to not clash with per-project files.
Expand Down Expand Up @@ -38,8 +46,4 @@ include(CocosSelectModule)
# set common compiler options
include(CocosCompileOptions)

# collect prebuilt libraries
include(CocosPickLibs)

# compile source libraries
include(CocosBuildModules)
include(CocosConfigDepend)
Loading

0 comments on commit 98120fb

Please sign in to comment.