axmol/cmake
leda 50ecf00115 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
..
Modules cmake support win32 ,and support generate&use prebuilt libs (#18683) 2018-03-08 09:47:57 +08:00
AndroidNdkGdb.cmake Various CMake improvements 2016-06-14 10:20:57 -04:00
AndroidNdkModules.cmake cmake support win32 ,and support generate&use prebuilt libs (#18683) 2018-03-08 09:47:57 +08:00
BuildHelpers.CMakeLists.txt Move BuildHelpers.CMakeLists.txt to Modules/CocosBuildHelpers.cmake, this name is more standard for cmake include files, and in future this file can be installed to use by external applications. 2014-11-11 10:30:48 +03:00
README.md cmake support win32 ,and support generate&use prebuilt libs (#18683) 2018-03-08 09:47:57 +08:00
android.toolchain.cmake Various CMake improvements 2016-06-14 10:20:57 -04:00
ios.toolchain.cmake V3 android cmake support, add mac/ios support (#18646) 2018-02-08 09:24:33 +08:00

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.

CMake in Cocos2d-x

  1. CMake in Cocos2d-x support platform iOS, Android, macOS, Linux, Win32.

  2. Open your terminal, input cmake --version, if the cmake version is lower than 3.1, please upgrade

  3. 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

  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
  2. 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
  3. -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.
  4. --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
  2. 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
  3. 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 app/build.gradle
  4. 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

  1. better support package iOS/MacOS App
  2. improve and refactor
  3. support MinGW on Windows

Issues

  1. info.plist always been generated when cmake -GXcode, it's bad friendly to custom info.plist