axmol/cmake/README.md

148 lines
5.8 KiB
Markdown
Raw Normal View History

V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
# CMake Guide
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
cmake support win32 ,and support generate&use prebuilt libs (#18683) * 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
2018-03-08 09:47:57 +08:00
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.
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
## Requirement
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
1. Open your terminal, input `cmake --version`, if the cmake version is lower than 3.1, please upgrade
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
2. You should use out-of-source build, that is said you need to create a different directory from `cocos2d-x` to execute cmake command.
## Step by Step
### Build in Linux
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
```sh
cd cocos2d-x
mkdir linux-build && cd linux-build
cmake ..
make
```
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
Execute `make help` to see all build targets, `make <target>` build specified target
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
### Generate Visual Studio project
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
```sh
cd cocos2d-x
mkdir win32-build && cd win32-build
cmake .. -G"Visual Studio 15 2017" -Tv141
```
Execute `cmake --build .` to compile, or open `Cocos2d-x.sln` in Explorer to use the generated project.
### Generate macOS Project
```sh
cd cocos2d-x
mkdir mac-build && cd mac-build
cmake .. -GXcode
open Cocos2d-x.xcodeproj
```
### Generate iOS Project
```sh
cd cocos2d-x
mkdir ios-build && cd ios-build
cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake
open Cocos2d-x.xcodeproj
```
The default build is for iOS device, if you want to run on simulator, please add `-DIOS_PLATFORM=SIMULATOR` for architecture i386 or `-DIOS_PLATFORM=SIMULATOR64` for x86_64.
### CMake in Android Studio
We use the Gradle to Android applacition, and Gradle use cmake to build the native code, see the [property](https://github.com/cocos2d/cocos2d-x/blob/84be684e3858393a6f3efc50e3f95d4e0ac92a20/tests/cpp-empty-test/proj.android/gradle.properties#L38): `PROP_NDK_MODE`, it control the way of native build
```sh
# android native code build type
# none, native code will never be compiled.
# cmake, native code will be compiled by CMakeLists.txt
# ndk-build, native code will be compiled by Android.mk
PROP_BUILD_TYPE=ndk-build
```
If you want to add cmake build arguments, please add it at [externalNativeBuild](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 feature
To solve the problem that compiling engine sources spends too long time, we add the feature of pre-builds libs. Using this feature you only need build engine sources once for a specific environment.
### Example
This is an example of build cpp libs once, and use it in different cpp project.
```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
```
Close option `GEN_COCOS_PREBUILT` and open `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
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
Using this feature on Android exists a little difference, for CMake can't find system environment when build in Gradle. So 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.
cmake support win32 ,and support generate&use prebuilt libs (#18683) * 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
2018-03-08 09:47:57 +08:00
## Build Options
### CMake Common
1. __`-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`
1. __`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
1. __`-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 be `msvc_build` directory.
1. __`--build <dir>`__, build a CMake-generated project binary tree, for example
* `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.
cmake support win32 ,and support generate&use prebuilt libs (#18683) * 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
2018-03-08 09:47:57 +08:00
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 support win32 ,and support generate&use prebuilt libs (#18683) * 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
2018-03-08 09:47:57 +08:00
* Official website: [cmake.org](https://cmake.org/)
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
* Documentation: [cmake.org/documentation](https://cmake.org/documentation/)
V3 android cmake support, add mac/ios support (#18646) * CMake build improvements * android cmake support * Enable proguard for cocos2d * examples & test cmake support * add android build type param to gradle.properties file * less warnings * update all android configs to recomended settings * fix network cmake error * fix js-tests cmake error * android build config, add cmake * android build config, add cmake * add lua share lib * android lua cmake build fix * fix * luajit test * run fail, still * fix js-warning * correct lua main include * lua test project cmake support android * try to add lua-template cmake support * lua template fix * js_tests support cmake on android * js-tests improve * cmake support js-template * test to realise prebuild * cmake improve, no feature * improve templates cmake * refactor cmake struct * correct cpp-tests cmake * cpp-templates cmake improve * typo fix * cmake struct refator * change default option * adapt new project struct * uniform cmake test style * add_dependencies to support make -j * little struct improve * little fix * adapt cmake bin dir * little improve about cmake version * change build all tests condition * add source_group for Xcode * add mark source files * add more mark source code * add template project to test * add macos info.plist template * add pak macos for all project * lua test icon fix * not consider lua project for now * modify pak method * add another ios toolchain * add ios system library * update ios toolchain, and reduce ios compile errors * reduce error * make ios engine lib compile pass * cpp-empty-test ios bundle * cpp-tests ios support * js-tests ios support * templates project support ios * fix the way of lua-tests package * try to fix lua-template on macOS * comment lua-template sim file * improve display on xcode * update cmake readme * check android compile again * fix android compile error * fix linux cmake res error * update deps version, for cmake * fix lua_template linux compile error * close android cmake support for now * review template android share library name * change PROP_BUILD_TOOLS_VERSION version to 27.0.1 * change android compile version * make `PROP_APP_PLATFORM` back, add comments for android native build * Revert "make `PROP_APP_PLATFORM` back, add comments for android native build" This reverts commit 272ddc19886891b9502cde070753a870c0fdb588.
2018-02-08 09:24:33 +08:00
* CMake FAQ: [Wiki/CMake_FAQ](https://cmake.org/Wiki/CMake_FAQ)