50ecf00115
* fix win32 prebuilt error, and set cmake as default android native build * cpp-template support msvc * add msvc version check * add -D_USRLUASTATIC, fix lua lib cmake compile error * fix cpp-empty-test res copy dir, add function needed * improve msvc res copy * refactor cmake copy dll logic * fix cpp-tests compile error * refactor copy dll temp * refactor win32 exe using dlls * js-project compile support cmake using msvc * improve res mark for win32 * update the way of lua project res mark * add D_USRLUASTATIC for lua project * unify RELEASE Release to Release, add CMAKE_CONFIGURATION_TYPES * improve VS shows targets, add folder * improve mac/ios res mark * reduce useless comments * unify cpp src include variable * refactor cpp test project package logic * improve pkg app logic * start support prebuilt libs for cpp project using cmake * improve prebuilt libs generate * expand js/lua support prebuilt libs on mac * adapt IDE generate libs path * start do prebuilt for android * improve the way of using external libs for prebuilt * prebuilt libs support cpp-empty-test on android studio * cpp-tests prebuilt libs, and remove useless * start to improve libs using, to adapt prebuilt * improve cpp tests prebuilt on android * prebuilt support lua & js test on android * prebuilt support cpp&js template * rename prebuilt variabl, detail androd config * finish android support prebuilt using cmake * fix cmake script run in windows error * reduce variable name length * improve the way of win32 use dlls to adapt prebuilt * loosen pick js/lua engine lib condition * self review and start check linux build * unify compile option location * strict copy dlls condition * improve libs link order * start redo the way of copy dlls * unify dlls copy logic * fix linux res copy error * update cmake copy file path in linux * make prebuilt dir if needed, and divide Debug and Release dir * cmake win32 divide Debug and Release dir well * comment Lua Template project, for the unfinished lua simulator support * add simulator cmake file * start support simulator * simulator support cmake build on macOS * fix simulator compile error on win32 * add simulator prebuilt support * improve mark cocos app macro * improve cmake template project format * improve cmake app files format * fix format improve mistake * detail cmake readme * improve readme, useless comments * add game.rc to template project * check travis openssl version * try update travis openssl * upgrade travis openssl * change openssl link * change to upgrade openssl * re install python with upgrade openssl * add comment for macro and func, improve variable name |
||
---|---|---|
.. | ||
Modules | ||
AndroidNdkGdb.cmake | ||
AndroidNdkModules.cmake | ||
BuildHelpers.CMakeLists.txt | ||
README.md | ||
android.toolchain.cmake | ||
ios.toolchain.cmake |
README.md
CMake
CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.
Links
-
Official website: cmake.org
-
Documentation: cmake.org/documentation
-
CMake FAQ: Wiki/CMake_FAQ
CMake in Cocos2d-x
-
CMake in Cocos2d-x support platform iOS, Android, macOS, Linux, Win32.
-
Open your terminal, input
cmake --version
, if the cmake version is lower than 3.1, please upgrade -
You should use out-of-source build, that is said you need to create a different directory from
$cocos2dx_root
to execute cmake command.
Build Options
CMake Common
-
-G
, generate native build project you specified, for example-GXcode
generate Xcode project files.-GVisual Studio 15 2017
generate Visual Studio 2017 project, the default toolset is v141, add-T
option to specify toolset, like this-Tv140
-
CMAKE_BUILD_TYPE
, specify the build mode, Debug or Release-DCMAKE_BUILD_TYPE=Release
to generate the Release mode project, the default build mode is Debug
-
-H -B
,-H
specify the CMake project Home directory,-B
specify CMake-generated project binary directory. for example-H..\cocos2d-x -Bmsvc_build
the generated native project's location will bemsvc_build
directory.
-
--build <dir>
, build a CMake-generated project binary tree, for examplecmake --build ./msvc_build
, cmake will sellect corresponding build tools.
Cocos2d-x Options
-
GEN_COCOS_PREBUILT
, control the project have the feature to generate pre-build libraries or not. Default value isOFF
-DGEN_COCOS_PREBUILT=ON
, will add target prebuilt, build this target will generate prebuilt libraries
-
USE_COCOS_PREBUILT
, control the project have the feature to use pre-build libraries or not. Default value isOFF
-DUSE_COCOS_PREBUILT=ON
, will disable libraries target, and make app target use prebuilt libraries
-
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 examplearguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
set this value on app/build.gradle
-
Any options in SelectModule.cmake can be set manually. Do it if you know what you're doing.
Build Examples
build specified target in Linux
mkdir linux-build
cd linux-build
cmake $cocos2dx_root
make cpp_empty_test
execute make help
in generated make project to see all build targets
MSVC build on Terminal or Visual Studio
cmake -H"..\cocos2d-x\" -Bmsvc_build -G"Visual Studio 15 2017" -Tv141 -DCMAKE_BUILD_TYPE=Debug
execute cmake --build ./msvc_build
or open Cocos2d-x.sln
in Explorer to use the generated native project.
using CMake in Android Studio
see the Gradle properties: PROP_NDK_MODE
, it control the way of native build
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
PROP_NDK_MODE=cmake
add cmake arguments in externalNativeBuild/cmake
block of app/build.gradle file.
Generate Xcode macOS Project
cmake -H$COCOS_TEMPLATES_ROOT/.. -Bbuild_mac -GXcode
cd build_mac
open Cocos2d-x.xcodeproj
Generate Xcode iOS Project
cd build_ios
cmake -DCMAKE_TOOLCHAIN_FILE=$COCOS_TEMPLATES_ROOT/../cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR64 -H$COCOS_TEMPLATES_ROOT/.. -Bbuild_ios_sim64 -GXcode
cd build_ios_sim64
open Cocos2d-x.xcodeproj
TODO
- better support package iOS/MacOS App
- improve and refactor
- support MinGW on Windows
Issues
- info.plist always been generated when
cmake -GXcode
, it's bad friendly to custom info.plist