Skip to content

Commit

Permalink
V3 android cmake support, add mac/ios support (#18646)
Browse files Browse the repository at this point in the history
* 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 272ddc1.
  • Loading branch information
drelaptop authored and minggo committed Feb 8, 2018
1 parent f1dbc31 commit edee972
Show file tree
Hide file tree
Showing 70 changed files with 2,379 additions and 1,234 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ tests/cpp-empty-test/proj.tizen/res/
tests/cpp-tests/proj.tizen/res/
tests/lua-empty-test/project/proj.tizen/res/
tests/lua-tests/project/proj.tizen/res/

# Ignore vscode folder
.vscode/

# Ignore static libraries
*.a
115 changes: 18 additions & 97 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,108 +24,29 @@
# THE SOFTWARE.
# ****************************************************************************/

cmake_minimum_required(VERSION 3.1)
# It ensures that when Find*.cmake files included from cmake's Modules dir
# include another *.cmake file with relative path, that file will be included
# also from cmake's Modules dir, to not clash with per-project files.
cmake_policy(SET CMP0017 NEW)

# Use new behaviour with cmake >= 3.1:
# Only interpret if() arguments as variables or keywords when unquoted.
if(CMAKE_VERSION VERSION_GREATER 3.1)
cmake_policy(SET CMP0054 NEW)
endif()

project (Cocos2d-X)

# The version number
set(COCOS2D_X_VERSION 3.13)

# define some variables

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
# architecture
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(FATAL_ERROR "Unsupported architecture, CMake will exit")
return()
endif()
# CMAKE_BUILD_TYPE has precedence over DEBUG_MODE
# Still supporting DEBUG_MODE for backwards compatibility
if (NOT CMAKE_BUILD_TYPE)
if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE DEBUG)
else(DEBUG_MODE)
set(CMAKE_BUILD_TYPE RELEASE)
endif(DEBUG_MODE)
endif(NOT CMAKE_BUILD_TYPE)

include(CocosBuildHelpers)

message(${BUILDING_STRING})
# build engine library and all tests

# SelectModule() is a macro to select building modules
include(SelectModule)
SelectModule()

# set compiler options
include(SetCompilerOptions)
SetCompilerOptions()

if (CMAKE_FIND_ROOT_PATH AND USE_PREBUILT_LIBS)
# 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 ()

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cocos
${CMAKE_CURRENT_SOURCE_DIR}/deprecated
${CMAKE_CURRENT_SOURCE_DIR}/cocos/platform
${CMAKE_CURRENT_SOURCE_DIR}/extensions
${CMAKE_CURRENT_SOURCE_DIR}/external
)

if(USE_PREBUILT_LIBS)
include(CocosUsePrebuiltLibs)
endif()

include(BuildModules)
BuildModules()

# build cpp-empty-test
if(BUILD_CPP_EMPTY_TEST)
add_subdirectory(tests/cpp-empty-test)
endif(BUILD_CPP_EMPTY_TEST)
cmake_minimum_required(VERSION 3.1)

# build cpp-tests
if(BUILD_CPP_TESTS)
add_subdirectory(tests/cpp-tests)
endif(BUILD_CPP_TESTS)
project(Cocos2d-x)

## Scripting
if(BUILD_LUA_LIBS)
add_subdirectory(cocos/scripting/lua-bindings)
# cocos2dx root path
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)

# build lua tests
if(BUILD_LUA_TESTS)
add_subdirectory(tests/lua-tests/project)
add_subdirectory(tests/lua-empty-test/project)
endif(BUILD_LUA_TESTS)
# works before build libcocos2d
include(CocosBuildSet)
CocosBuildSet()

endif(BUILD_LUA_LIBS)
# TODO: use cocos prebuilt library
if(USE_COCOS_PREBUILT_LIBS)
# use prebuilt library, not build
else(USE_COCOS_PREBUILT_LIBS)
# build engine library
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)

## JS
if(BUILD_JS_LIBS)
add_subdirectory(cocos/scripting/js-bindings)
# build engine all tests project
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)

# build js tests
if(BUILD_JS_TESTS)
add_subdirectory(tests/js-tests/project)
endif(BUILD_JS_TESTS)
endif(USE_COCOS_PREBUILT_LIBS)

endif(BUILD_JS_LIBS)
40 changes: 0 additions & 40 deletions README.cmake

This file was deleted.

133 changes: 97 additions & 36 deletions cmake/Modules/BuildModules.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
macro (BuildModules)

# header files third libiary needed, such as tinyxml2.h
include_directories(
${COCOS2DX_ROOT_PATH}
${COCOS2DX_ROOT_PATH}/cocos
${COCOS2DX_ROOT_PATH}/deprecated
${COCOS2DX_ROOT_PATH}/cocos/platform
${COCOS2DX_ROOT_PATH}/extensions
${COCOS2DX_ROOT_PATH}/external
)

# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL REQUIRED)
cocos_find_package(OpenGL OPENGL REQUIRED)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)

if(LINUX OR WINDOWS)
cocos_find_package(GLEW GLEW REQUIRED)
Expand All @@ -17,7 +29,6 @@ macro (BuildModules)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})

cocos_find_package(SQLite3 SQLITE3 REQUIRED)
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
Expand All @@ -42,100 +53,150 @@ macro (BuildModules)

# Chipmunk
if(USE_CHIPMUNK)
if(USE_PREBUILT_LIBS)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
endif()
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
else(USE_CHIPMUNK)
add_definitions(-DCC_USE_PHYSICS=0)
endif(USE_CHIPMUNK)

# Box2d
if(USE_BOX2D)
if(USE_PREBUILT_LIBS)
if(USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(box2d Box2D REQUIRED)
endif(USE_PREBUILT_LIBS)
endif(USE_EXTERNAL_PREBUILT_LIBS)
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
elseif(BUILD_BOX2D)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/Box2D ${ENGINE_BINARY_PATH}/external/Box2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)

# Bullet
if(USE_BULLET)
if(USE_PREBUILT_LIBS)
if(USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(bullet BULLET REQUIRED)
endif()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
else(USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif(USE_BULLET)

# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/recast ${ENGINE_BINARY_PATH}/external/recast)
set(RECAST_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/recast)
set(RECAST_LIBRARIES recast)
else()
cocos_find_package(recast RECAST REQUIRED)
set(RECAST_LIBRARIES recast)
endif()
message(STATUS "Recast include dirs: ${RECAST_INCLUDE_DIRS}")
add_definitions(-DCC_USE_NAVMESH=1)
else(USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=0)
endif(USE_RECAST)

# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/tinyxml2 ${ENGINE_BINARY_PATH}/external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/tinyxml2)
set(TinyXML2_LIBRARIES tinyxml2)
else()
cocos_find_package(TinyXML2 TinyXML2 REQUIRED)
endif()
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")

# libjpeg
cocos_find_package(JPEG JPEG REQUIRED)
cocos_find_package(ZLIB ZLIB REQUIRED)
# need review
if(NOT IOS)
cocos_find_package(ZLIB ZLIB REQUIRED)
endif()
if(IOS)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)
endif(IOS)

if(ANDROID)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec ${ENGINE_BINARY_PATH}/external/android-specific/pvmp3dec)
set(PVMP3DEC_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/include ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/src)
set(PVMP3DEC_LIBRARIES pvmp3dec)
message(STATUS "pvmp3dec include dirs: ${PVMP3DEC_INCLUDE_DIRS}")

add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo ${ENGINE_BINARY_PATH}/external/android-specific/tremolo)
set(TREMOLO_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo)
set(TREMOLO_LIBRARIES tremolo)
message(STATUS "Tremolo include dirs: ${TREMOLO_INCLUDE_DIRS}")
endif()

# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
# only msys2 currently provides package for this variant, all other
# dists have packages from zlib, thats very old for us.
# moreover our embedded version modified to quick provide
# functionality needed by cocos.
if(USE_PREBUILT_LIBS OR NOT MINGW)
if(USE_EXTERNAL_PREBUILT_LIBS OR NOT MINGW OR USE_SOURCES_EXTERNAL)
#TODO: hack! should be in external/unzip/CMakeLists.txt
include_directories(${ZLIB_INCLUDE_DIRS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip ${ZLIB_INCLUDE_DIRS})
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/unzip ${ENGINE_BINARY_PATH}/external/unzip)
set(MINIZIP_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/unzip ${ZLIB_INCLUDE_DIRS})
set(MINIZIP_LIBRARIES unzip ${ZLIB_LIBRARIES})
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
else()
cocos_find_package(MINIZIP MINIZIP REQUIRED)
# double check that we have needed functions
include(CheckLibraryExists)
check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2)
if(NOT MINIZIP_HAS_GOTOFIRSTFILE2)
message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS")
return()
endif()
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()

cocos_find_package(PNG PNG REQUIRED)
cocos_find_package(TIFF TIFF REQUIRED)

# Jpeg
if(USE_JPEG)
cocos_find_package(JPEG JPEG REQUIRED)
add_definitions(-DCC_USE_JPEG=1)
else(USE_JPEG)
add_definitions(-DCC_USE_JPEG=0)
endif(USE_JPEG)

# Tiff
if(USE_TIFF)
cocos_find_package(TIFF TIFF REQUIRED)
add_definitions(-DCC_USE_TIFF=1)
else(USE_TIFF)
add_definitions(-DCC_USE_TIFF=0)
endif(USE_TIFF)

# Png
if(USE_PNG)
cocos_find_package(PNG PNG REQUIRED)
add_definitions(-DCC_USE_PNG=1)
else(USE_PNG)
add_definitions(-DCC_USE_PNG=0)
endif(USE_PNG)

cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
if(NOT USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(OpenSSL OPENSSL REQUIRED)
endif()

# flatbuffers
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/flatbuffers ${ENGINE_BINARY_PATH}/external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
cocos_find_package(flatbuffers flatbuffers REQUIRED)
endif()

# xxhash
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/xxhash ${ENGINE_BINARY_PATH}/external/xxhash)
set(XXHASH_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()

# libcocos2d.a
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cocos)
endmacro(BuildModules)
Loading

0 comments on commit edee972

Please sign in to comment.