Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,24 @@ project(Cocos2d-x)
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)

# prevent in-source-build
include(PreventInSourceBuilds)
AssureOutOfSourceBuilds()

# works before build libcocos2d
include(CocosBuildSet)

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

if(NOT USE_COCOS_PREBUILT)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)

# prevent tests project to build "cocos2d-x/cocos" again
set(BUILD_ENGINE_DONE ON)
# add engine all tests project
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/js-tests/project ${ENGINE_BINARY_PATH}/tests/js-tests)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
55 changes: 28 additions & 27 deletions cmake/Modules/CocosBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,18 @@ function(cocos_mark_multi_resources res_out)
set(${res_out} ${tmp_file_list} PARENT_SCOPE)
endfunction()

# get `cocos_target` depend all dlls, save the result in `all_depend_dlls_out`
function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
set(all_depend_ext_dlls)
# get all linked libraries including transitive ones, recursive
function(search_depend_libs_recursive cocos_target all_depends_out)
set(all_depends_inner)
set(targets_prepare_search ${cocos_target})
# targets_prepare_search, target need find ext libs
set(have_searched_targets)
set(need_search_targets)
while(true)
foreach(tmp_target ${targets_prepare_search})
get_target_property(tmp_depend_libs ${tmp_target} LINK_LIBRARIES)
list(REMOVE_ITEM targets_prepare_search ${tmp_target})
# target itself use_cocos_pkg
list(APPEND tmp_depend_libs ${tmp_target})
foreach(depend_lib ${tmp_depend_libs})
if(TARGET ${depend_lib})
get_target_property(tmp_dlls ${depend_lib} CC_DEPEND_DLLS)
if(tmp_dlls)
list(APPEND all_depend_ext_dlls ${tmp_dlls})
endif()
list(APPEND all_depends_inner ${depend_lib})
if(NOT (depend_lib STREQUAL tmp_target))
list(APPEND targets_prepare_search ${depend_lib})
endif()
Expand All @@ -75,6 +68,23 @@ function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
break()
endif()
endwhile(true)
set(${all_depends_out} ${all_depends_inner} PARENT_SCOPE)
endfunction()

# get `cocos_target` depend all dlls, save the result in `all_depend_dlls_out`
function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)

set(depend_libs)
set(all_depend_ext_dlls)
search_depend_libs_recursive(${cocos_target} depend_libs)
foreach(depend_lib ${depend_libs})
if(TARGET ${depend_lib})
get_target_property(tmp_dlls ${depend_lib} CC_DEPEND_DLLS)
if(tmp_dlls)
list(APPEND all_depend_ext_dlls ${tmp_dlls})
endif()
endif()
endforeach()

set(${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE)
endfunction()
Expand Down Expand Up @@ -168,7 +178,7 @@ function(setup_cocos_app_config app_name)
elseif(MSVC)
# only Debug and Release mode was supported when using MSVC.
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/$<CONFIG>")
set(APP_RES_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/${CMAKE_BUILD_TYPE}")
set(APP_RES_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/${CMAKE_BUILD_TYPE}/Resources")
#Visual Studio Defaults to wrong type
set_target_properties(${app_name} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
else(LINUX)
Expand All @@ -182,7 +192,6 @@ function(setup_cocos_app_config app_name)
cocos_mark_code_files(${APP_NAME})
endif()

set(APP_BIN_DIR ${APP_BIN_DIR} PARENT_SCOPE)
set(APP_RES_DIR ${APP_RES_DIR} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -232,26 +241,18 @@ macro(cocos_pak_xcode cocos_target)
set(MACOSX_BUNDLE_LONG_VERSION_STRING ${COCOS_APP_LONG_VERSION_STRING})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${COCOS_APP_SHORT_VERSION_STRING})

message("cocos package: ${cocos_target}, plist file: ${COCOS_APP_INFO_PLIST}")
message(STATUS "cocos package: ${cocos_target}, plist file: ${COCOS_APP_INFO_PLIST}")

cocos_config_app_xcode_property(${cocos_target})
endmacro()

# set Xcode property for application, include all depend target
macro(cocos_config_app_xcode_property cocos_app)
cocos_config_target_xcode_property(${cocos_app})
# for example, cocos_target: cpp-tests link engine_lib: cocos2d
get_target_property(engine_libs ${cocos_app} LINK_LIBRARIES)
foreach(engine_lib ${engine_libs})
if(TARGET ${engine_lib})
cocos_config_target_xcode_property(${engine_lib})
# for example, engine_lib: cocos2d link external_lib: flatbuffers
get_target_property(external_libs ${engine_lib} LINK_LIBRARIES)
foreach(external_lib ${external_libs})
if(TARGET ${external_lib})
cocos_config_target_xcode_property(${external_lib})
endif()
endforeach()
set(depend_libs)
search_depend_libs_recursive(${cocos_app} depend_libs)
foreach(depend_lib ${depend_libs})
if(TARGET ${depend_lib})
cocos_config_target_xcode_property(${depend_lib})
endif()
endforeach()
endmacro()
Expand Down
23 changes: 16 additions & 7 deletions cmake/Modules/CocosBuildSet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ endif()
set(CMAKE_DEBUG_TARGET_PROPERTIES
# INCLUDE_DIRECTORIES
# COMPILE_DEFINITIONS
# COMPILE_OPTIONS
# AUTOUIC_OPTIONS
# 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
Expand All @@ -32,6 +32,10 @@ endif()
set(COCOS_EXTERNAL_DIR ${COCOS2DX_ROOT_PATH}/external)
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)

if(CMAKE_TOOLCHAIN_FILE)
message(STATUS "using toolchain file:" ${CMAKE_TOOLCHAIN_FILE})
endif()

message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
Expand All @@ -41,13 +45,18 @@ message(STATUS "COCOS_EXTERNAL_DIR:" ${COCOS_EXTERNAL_DIR})
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})

# include helper functions for cmake build
include(CocosBuildHelpers)
# the default behavior of build module
option(DEBUG_MODE "Debug or Release?" ON)
option(BUILD_LUA_LIBS "Build lua libraries" OFF)
option(BUILD_JS_LIBS "Build js libraries" OFF)

# select building modules
include(CocosSelectModule)
# include helper functions
include(CocosBuildHelpers)

# set common compiler options
include(CocosCompileOptions)
# add target compile define function
# add target compile options function
include(CocosConfigDefine)

# config libraries dependence
include(CocosConfigDepend)
191 changes: 0 additions & 191 deletions cmake/Modules/CocosCompileOptions.cmake

This file was deleted.

Loading