remove un-elegant prebuilt feature in cmake (#19109)

* remove unclearly cmake prebuilt feature

* reduce useless code

* add project info print
This commit is contained in:
leda 2018-10-12 12:36:17 +08:00 committed by GitHub
parent 57cdad95b2
commit 48cce75be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 9 additions and 189 deletions

View File

@ -1,23 +1,5 @@
include(CMakeParseArguments)
# find a prebuilt lib by `lib_name` and save the result in `lib_out`
function(cocos_find_prebuilt_lib_by_name lib_name lib_out)
set(search_path ${COCOS_PREBUILT_PATH})
if(XCODE OR VS)
set(search_path ${COCOS_PREBUILT_PATH}/${CMAKE_BUILD_TYPE})
endif()
message(STATUS "search_path cocos prebuilt library: ${search_path}")
find_library(found_lib ${lib_name} PATHS ${search_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
if(found_lib)
message(STATUS "found cocos prebuilt library: ${found_lib}")
else()
message(STATUS "can't found cocos prebuilt library: ${lib_name}")
endif()
set(${lib_out} ${found_lib} PARENT_SCOPE)
unset(found_lib CACHE)
endfunction()
# copy resource `FILES` and `FOLDERS` to `COPY_TO` folder
function(cocos_copy_res)
set(oneValueArgs COPY_TO)
@ -114,21 +96,6 @@ function(cocos_copy_target_dll cocos_target)
endforeach()
endfunction()
# find dlls in a dir which `LIB_ABS_PATH` located, and save the result in `dlls_out`
function(cocos_find_dlls_for_lib dlls_out)
set(oneValueArgs LIB_ABS_PATH)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_filename_component(lib_dir ${opt_LIB_ABS_PATH} DIRECTORY)
file(GLOB lib_dir_files "${lib_dir}/*")
set(cc_dlls)
foreach(dir_file ${lib_dir_files})
if(${dir_file} MATCHES "dll$")
list(APPEND cc_dlls ${dir_file})
endif()
endforeach()
set(${dlls_out} ${cc_dlls} PARENT_SCOPE)
endfunction()
# mark `FILES` as resources, files will be put into sub-dir tree depend on its absolute path
function(cocos_mark_resources)
set(oneValueArgs BASEDIR RESOURCEBASE)
@ -215,12 +182,6 @@ function(setup_cocos_app_config app_name)
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()
set(APP_BIN_DIR ${APP_BIN_DIR} PARENT_SCOPE)
set(APP_RES_DIR ${APP_RES_DIR} PARENT_SCOPE)
endfunction()
@ -311,7 +272,7 @@ endfunction(set_xcode_property)
# works same as find_package, but do additional care to properly find
macro(cocos_find_package pkg_name pkg_prefix)
if(NOT USE_EXTERNAL_PREBUILT OR NOT ${pkg_prefix}_FOUND)
if(NOT ${pkg_prefix}_FOUND)
find_package(${pkg_name} ${ARGN})
endif()
if(NOT ${pkg_prefix}_INCLUDE_DIRS AND ${pkg_prefix}_INCLUDE_DIR)

View File

@ -32,9 +32,13 @@ endif()
set(COCOS_EXTERNAL_DIR ${COCOS2DX_ROOT_PATH}/external)
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)
message(STATUS "PROJECT_NAME:" ${PROJECT_NAME})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
message(STATUS "COCOS_EXTERNAL_DIR:" ${COCOS_EXTERNAL_DIR})
# delete binary dir if you hope a full clean re-build
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
# include helper functions for cmake build

View File

@ -47,17 +47,6 @@
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
# ARCH_DIR only useful for search linux prebuilt libs
if(LINUX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_DIR "64-bit")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_DIR "32-bit")
else()
message(WARNING "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}")
endif()
endif()
# check and print compiler infos
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(COMPILER_STRING ${CMAKE_CXX_COMPILER_ID})
@ -160,7 +149,7 @@
return()
endif()
if(CMAKE_FIND_ROOT_PATH AND USE_EXTERNAL_PREBUILT)
if(CMAKE_FIND_ROOT_PATH)
# Adds cocos2d-x external folder to the list of valid include/library paths when cross-compiling and using prebuilds
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${COCOS_EXTERNAL_DIR})
endif()
@ -183,39 +172,6 @@
endif()
endif()
# check prebuilt config
if(GEN_COCOS_PREBUILT AND USE_COCOS_PREBUILT)
message(FATAL_ERROR "can't generate prebuilt libs and use prebuilt libs at the same time")
endif()
if(GEN_COCOS_PREBUILT OR USE_COCOS_PREBUILT)
if(DEFINED COCOS_PREBUILT_ROOT)
message(STATUS "pre-defined COCOS_PREBUILT_ROOT: ${COCOS_PREBUILT_ROOT}")
else()
# the default prebuilt path is cocos2d-x/prebuilt
set(COCOS_PREBUILT_ROOT $ENV{COCOS_TEMPLATES_ROOT}/../prebuilt)
endif()
if(NOT IS_DIRECTORY ${COCOS_PREBUILT_ROOT})
message(STATUS "prebuilt root directory defined but not existed, create: ${COCOS_PREBUILT_ROOT}")
file(MAKE_DIRECTORY ${COCOS_PREBUILT_ROOT})
endif()
if(IS_DIRECTORY ${COCOS_PREBUILT_ROOT})
# prebuilt libs path
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER}/${CMAKE_BUILD_TYPE})
if(XCODE OR VS)
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER})
endif()
if(ANDROID)
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER}/${ANDROID_ABI})
endif()
message(STATUS "COCOS_PREBUILT_PATH:" ${COCOS_PREBUILT_PATH})
else()
if(ANDROID)
message(WARNING "using cmake in Android Studio, can't get value of environment variable, please define COCOS_PREBUILT_ROOT manually")
endif()
message(FATAL_ERROR "can't find prebuilt libs location")
endif()
endif()
# custom target property for dll collect
define_property(TARGET
PROPERTY CC_DEPEND_DLLS

View File

@ -143,7 +143,6 @@ endmacro()
macro(target_use_cocos2dx_depend target)
cocos2dx_depend()
cocos2dx_define()
message(STATUS "${target} prepare to use system depend: ${PLATFORM_SPECIFIC_LIBS}")
foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(${target} ${platform_lib})
endforeach()

View File

@ -1,10 +1,4 @@
# the default behavior of using prebuilt
set(GEN_COCOS_PREBUILT_DEFAULT OFF)
set(USE_COCOS_PREBUILT_DEFAULT OFF)
# the default behavior of build module
set(USE_WEBP_DEFAULT ON)
set(USE_EXTERNAL_PREBUILT_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT OFF)
set(BUILD_JS_LIBS_DEFAULT OFF)
@ -12,7 +6,7 @@ option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(USE_BULLET "Use bullet for physics3d library" ON)
option(USE_RECAST "Use Recast for navigation mesh" ON)
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
option(USE_WEBP "Use WebP codec" ON)
option(USE_PNG "Use PNG codec" ON)
option(USE_TIFF "Use TIFF codec" ON)
option(USE_JPEG "Use JPEG codec" ON)
@ -24,6 +18,4 @@ option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
option(USE_EXTERNAL_PREBUILT "Use prebuilt libraries in external directory" ${USE_EXTERNAL_PREBUILT_DEFAULT})
option(GEN_COCOS_PREBUILT "generate cocos static libraries, put libraries into prebuilt folder in cocos root" ${GEN_COCOS_PREBUILT_DEFAULT})
option(USE_COCOS_PREBUILT "use cocos static libraries, return warning if not find" ${USE_COCOS_PREBUILT_DEFAULT})

View File

@ -69,42 +69,6 @@ PROP_BUILD_TYPE=cmake
If you want to add cmake build arguments, please add it at [external Native Build](https://github.com/cocos2d/cocos2d-x/blob/84be684e3858393a6f3efc50e3f95d4e0ac92a20/tests/cpp-empty-test/proj.android/app/build.gradle#L25) block of __app/build.gradle__ file.
## Prebuilt libraries feature
To solve long compilation times of the engine source code one can use prebuilt libraries. Using this feature you only need build engine sources once for a specific environment or again when the engine version changes and you wish to utilize the new version.
### Example
This is an example of building c++ libs once, and use them in different c++ projects.
```sh
cocos new -l cpp -p my.pack.app1 test_app1
mkdir app1_build && cd app1_build
cmake ../test_app1 -DGEN_COCOS_PREBUILT=ON
make prebuilt
```
Change option `GEN_COCOS_PREBUILT` and use instead `USE_COCOS_PREBUILT` to use prebuilt in the same project
```sh
cmake ../test_app1 -DGEN_COCOS_PREBUILT=OFF -DUSE_COCOS_PREBUILT=ON
make TemplateCpp
open bin/TemplateCpp.app
```
Add `-DUSE_COCOS_PREBUILT=ON` to use prebuilt libs in another cmake build.
```sh
cocos new -l cpp -p my.pack.app2 test_app2
mkdir app2_build && cd app2_build
cmake ../test_app2 -DUSE_COCOS_PREBUILT=ON
make TemplateCpp
open bin/TemplateCpp.app
```
> Any other cpp project can use prebuilt in this way
When using the prebuilt libraries on Android there is a small difference as CMake can't find system environment when built using Gradle. You need to [supply a path](https://github.com/cocos2d/cocos2d-x/blob/c087be314c2c56a757bf66163b173746b5d6ad34/tests/cpp-empty-test/proj.android/app/build.gradle#L34) as the location of prebuilt libs.
## Build Options
@ -127,22 +91,6 @@ When using the prebuilt libraries on Android there is a small difference as CMak
* `cmake --build ./msvc_build`, cmake will sellect corresponding build tools.
### Cocos2d-x Options
1. __`GEN_COCOS_PREBUILT`__, control the project have the feature to generate pre-build libraries or not. Default value is `OFF`
* `-DGEN_COCOS_PREBUILT=ON`, will add target prebuilt, build this target will generate prebuilt libraries
1. __`USE_COCOS_PREBUILT`__, control the project have the feature to use pre-build libraries or not. Default value is `OFF`
* `-DUSE_COCOS_PREBUILT=ON`, will disable libraries target, and make app target use prebuilt libraries
1. __`COCOS_PREBUILT_ROOT`__, a path means the prebuilt libraries root location, it's not optional for Android Project on Android Studio, optional for other supported platforms. the default value is $cocos2dx_root/prebuilt if the cmake can access to cocos2d-x environment variable. for example
* `arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"` set this value on [cmake block](https://github.com/cocos2d/cocos2d-x/blob/84be684e3858393a6f3efc50e3f95d4e0ac92a20/tests/cpp-empty-test/proj.android/app/build.gradle#L31) of build.gradle file.
1. Any options in [SelectModule.cmake](./Modules/SelectModule.cmake) can be set manually. Do it if you know what you're doing.
## Useful Links
* CMake Official website: [cmake.org](https://cmake.org/)

View File

@ -30,7 +30,7 @@
# build jscocos2d if BUILD_JS_LIBS=ON
# The version number
set(COCOS2D_X_VERSION 3.17)
set(COCOS2D_X_VERSION 3.18)
set(COCOS_CORE_LIB cocos2d)

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -36,11 +36,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_JS_LIBS=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -36,11 +36,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_LUA_LIBS=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang",
"-DANDROID_ARM_NEON=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"
}
}
}

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_JS_LIBS=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_LUA_LIBS=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -37,11 +37,6 @@ android {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DBUILD_LUA_LIBS=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}