CMake Guide

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 generates native makefiles and workspaces that can be used in the compiler environment of your choice.


  1. Open your terminal and execute:

    cmake --version

    If the CMake version is lower than 3.1, please upgrade.

  2. You should use out-of-source builds, this means you need to create a different directory than Cocos2d-x to execute the cmake command.

Step by Step


To compile Cocos2d-x for Linux:

cd cocos2d-x
mkdir linux-build && cd linux-build
cmake ..

Execute make help to see all build targets, make <target> build specified target

Generate Visual Studio projects

To generate a Visual Studio project to compile Cocos2d-x:

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

To generate an XCode project to compile Cocos2d-x:

cd cocos2d-x
mkdir mac-build && cd mac-build
cmake .. -GXcode
open Cocos2d-x.xcodeproj

Generate iOS Project

To generate an XCode project to compile Cocos2d-x:

cd cocos2d-x
mkdir ios-build && cd ios-build
open Cocos2d-x.xcodeproj

The parameter -DCMAKE_OSX_SYSROOT=iphoneos is optional, it generates a build for running on the iOS device. If you want to run in the simulator, please add -DCMAKE_OSX_SYSROOT=iphonesimulator instead, but remember you can't run a metal-support app in the simulator until Xcode 11 and MacOS 10.15.

Android Studio

If you want to add cmake build arguments, please add it at external Native Build block of app/build.gradle file.

Build Options

CMake Common Build Options

  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.

results matching ""

    No results matching ""