Merge pull request #15442 from minggo/cmake-refactor

refactor cmake
This commit is contained in:
minggo 2016-04-18 15:45:54 +08:00
commit 3e183f7206
4 changed files with 329 additions and 290 deletions

View File

@ -41,60 +41,19 @@ project (Cocos2d-X)
# The version number
set(COCOS2D_X_VERSION 3.11)
# define some variables
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
include(CocosBuildHelpers)
message(${BUILDING_STRING})
set(USE_WEBP_DEFAULT ON)
if(WINRT OR WP8)
set(USE_WEBP_DEFAULT OFF)
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()
set(USE_PREBUILT_LIBS_DEFAULT ON)
if(MINGW)
set(USE_PREBUILT_LIBS_DEFAULT OFF)
endif()
set(BUILD_CPP_EMPTY_TEST_DEFAULT ON)
set(BUILD_CPP_TESTS_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
set(BUILD_JS_LIBS_DEFAULT ON)
set(BUILD_JS_TESTS_DEFAULT ON)
# TODO: fix test samples for MSVC
if(MSVC)
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
set(BUILD_CPP_TESTS_DEFAULT OFF)
set(BUILD_LUA_LIBS_DEFAULT OFF)
set(BUILD_LUA_TESTS_DEFAULT OFF)
set(BUILD_JS_LIBS_DEFAULT OFF)
set(BUILD_JS_TESTS_DEFAULT OFF)
endif()
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(USE_BULLET "Use bullet for physics3d library" ON)
option(USE_RECAST "Use Recast for navigation mesh" ON)
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DEBUG_MODE "Debug or release?" ON)
option(BUILD_EXTENSIONS "Build extension library" ON)
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
option(BUILD_CPP_EMPTY_TEST "Build TestCpp samples" ${BUILD_CPP_EMPTY_TEST_DEFAULT})
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
if(USE_PREBUILT_LIBS AND MINGW)
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
endif()
# CMAKE_BUILD_TYPE has precedence over DEBUG_MODE
# Still supporting DEBUG_MODE for backwards compatibility
if (NOT CMAKE_BUILD_TYPE)
@ -105,259 +64,32 @@ if (NOT CMAKE_BUILD_TYPE)
endif(DEBUG_MODE)
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
include(CocosBuildHelpers)
# Compiler options
if(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
message(${BUILDING_STRING})
# Use inline debug info (/Z7) format. Or internal error may occur.
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
foreach(lang C CXX)
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
endforeach()
# SelectModule() is a macro to select building modules
include(SelectModule)
SelectModule()
else()
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
if(CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif(MSVC)
set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
# Some macro definitions
if(WINDOWS)
if(BUILD_SHARED_LIBS)
ADD_DEFINITIONS (-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
else()
ADD_DEFINITIONS (-DCC_STATIC)
endif()
ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
set(PLATFORM_FOLDER win32)
elseif(MACOSX OR APPLE)
ADD_DEFINITIONS (-DCC_TARGET_OS_MAC)
ADD_DEFINITIONS (-DUSE_FILE32API)
set(PLATFORM_FOLDER mac)
elseif(LINUX)
ADD_DEFINITIONS(-DLINUX)
set(PLATFORM_FOLDER linux)
elseif(ANDROID)
ADD_DEFINITIONS (-DUSE_FILE32API)
set(PLATFORM_FOLDER android)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -latomic")
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
if(MINGW)
#add_definitions(-DGLEW_STATIC)
add_definitions(-D__SSIZE_T)
if(CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
endif()
endif()
# 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" )
endif()
# set compiler options
include(SetCompilerOptions)
SetCompilerOptions()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/cocos
${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()
# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL REQUIRED)
if(LINUX OR WINDOWS)
cocos_find_package(GLEW GLEW REQUIRED)
#TODO: implement correct schema for pass cocos2d specific requirements to projects
include_directories(${GLEW_INCLUDE_DIRS})
endif()
cocos_find_package(GLFW3 GLFW3 REQUIRED)
include_directories(${GLFW3_INCLUDE_DIRS})
if(LINUX)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
endif()
if(WINDOWS)
cocos_find_package(Vorbis VORBIS REQUIRED)
cocos_find_package(MPG123 MPG123 REQUIRED)
cocos_find_package(OpenAL OPENAL REQUIRED)
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
endif()
endif(LINUX OR MACOSX OR WINDOWS)
# Freetype required on all platforms
cocos_find_package(Freetype FREETYPE REQUIRED)
# WebP required if used
if(USE_WEBP)
cocos_find_package(WebP WEBP REQUIRED)
endif(USE_WEBP)
# Chipmunk
if(USE_CHIPMUNK)
if(USE_PREBUILT_LIBS)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
endif()
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
if(IOS OR MACOSX)
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
add_definitions(-DCP_USE_CGPOINTS=0)
endif()
else(USE_CHIPMUNK)
add_definitions(-DCC_USE_PHYSICS=0)
endif(USE_CHIPMUNK)
# Box2d (not prebuilded, exists as source)
if(USE_BOX2D)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/Box2D)
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
set(Box2D_LIBRARIES box2d)
else()
find_package(Box2D REQUIRED CONFIG)
# actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake
set(Box2D_LIBRARIES Box2D)
endif()
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)
# Bullet (not prebuilded, exists as source)
if(USE_BULLET)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/bullet)
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_LIBRARIES bullet)
else()
cocos_find_package(bullet BULLET REQUIRED)
set(BULLET_LIBRARIES bullet)
endif()
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
else()
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)
add_subdirectory(external/recast)
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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()
add_definitions(-DCC_USE_NAVMESH=0)
endif(USE_RECAST)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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)
# 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)
#TODO: hack! should be in external/unzip/CMakeLists.txt
include_directories(${ZLIB_INCLUDE_DIRS})
add_subdirectory(external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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")
endif()
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()
cocos_find_package(PNG PNG REQUIRED)
cocos_find_package(TIFF TIFF REQUIRED)
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
# flatbuffers
if(USE_PREBUILT_LIBS)
add_subdirectory(external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
cocos_find_package(flatbuffers flatbuffers REQUIRED)
endif()
# xxhash
if(USE_PREBUILT_LIBS)
add_subdirectory(external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()
# libcocos2d.a
add_subdirectory(cocos)
include(BuildModules)
BuildModules()
# build cpp-empty-test
if(BUILD_CPP_EMPTY_TEST)

View File

@ -0,0 +1,151 @@
macro (BuildModules)
# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL REQUIRED)
if(LINUX OR WINDOWS)
cocos_find_package(GLEW GLEW REQUIRED)
#TODO: implement correct schema for pass cocos2d specific requirements to projects
include_directories(${GLEW_INCLUDE_DIRS})
endif()
cocos_find_package(GLFW3 GLFW3 REQUIRED)
include_directories(${GLFW3_INCLUDE_DIRS})
if(LINUX)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
endif()
if(WINDOWS)
cocos_find_package(Vorbis VORBIS REQUIRED)
cocos_find_package(MPG123 MPG123 REQUIRED)
cocos_find_package(OpenAL OPENAL REQUIRED)
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
endif()
endif(LINUX OR MACOSX OR WINDOWS)
# Freetype required on all platforms
cocos_find_package(Freetype FREETYPE REQUIRED)
# WebP required if used
if(USE_WEBP)
cocos_find_package(WebP WEBP REQUIRED)
endif(USE_WEBP)
# Chipmunk
if(USE_CHIPMUNK)
if(USE_PREBUILT_LIBS)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
endif()
endif(USE_CHIPMUNK)
# Box2d (not prebuilded, exists as source)
if(USE_BOX2D)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/Box2D)
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
set(Box2D_LIBRARIES box2d)
else()
find_package(Box2D REQUIRED CONFIG)
# actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake
set(Box2D_LIBRARIES Box2D)
endif()
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
endif(USE_BOX2D)
# Bullet (not prebuilded, exists as source)
if(USE_BULLET)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/bullet)
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_LIBRARIES bullet)
else()
cocos_find_package(bullet BULLET REQUIRED)
set(BULLET_LIBRARIES bullet)
endif()
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
endif(USE_BULLET)
# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/recast)
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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}")
endif(USE_RECAST)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS)
add_subdirectory(external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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)
# 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)
#TODO: hack! should be in external/unzip/CMakeLists.txt
include_directories(${ZLIB_INCLUDE_DIRS})
add_subdirectory(external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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()
endif()
cocos_find_package(PNG PNG REQUIRED)
cocos_find_package(TIFF TIFF REQUIRED)
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
# flatbuffers
if(USE_PREBUILT_LIBS)
add_subdirectory(external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
cocos_find_package(flatbuffers flatbuffers REQUIRED)
endif()
# xxhash
if(USE_PREBUILT_LIBS)
add_subdirectory(external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()
# libcocos2d.a
add_subdirectory(cocos)
endmacro(BuildModules)

View File

@ -0,0 +1,52 @@
macro (SelectModule)
set(USE_WEBP_DEFAULT ON)
if(WINRT OR WP8)
set(USE_WEBP_DEFAULT OFF)
endif()
set(USE_PREBUILT_LIBS_DEFAULT ON)
if(MINGW)
set(USE_PREBUILT_LIBS_DEFAULT OFF)
endif()
set(BUILD_CPP_EMPTY_TEST_DEFAULT ON)
set(BUILD_CPP_TESTS_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
set(BUILD_JS_LIBS_DEFAULT ON)
set(BUILD_JS_TESTS_DEFAULT ON)
# TODO: fix test samples for MSVC
if(MSVC)
set(BUILD_CPP_EMPTY_TEST_DEFAULT OFF)
set(BUILD_CPP_TESTS_DEFAULT OFF)
set(BUILD_LUA_LIBS_DEFAULT OFF)
set(BUILD_LUA_TESTS_DEFAULT OFF)
set(BUILD_JS_LIBS_DEFAULT OFF)
set(BUILD_JS_TESTS_DEFAULT OFF)
endif()
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(USE_BULLET "Use bullet for physics3d library" ON)
option(USE_RECAST "Use Recast for navigation mesh" ON)
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DEBUG_MODE "Debug or release?" ON)
option(BUILD_EXTENSIONS "Build extension library" ON)
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
option(BUILD_CPP_EMPTY_TEST "Build TestCpp samples" ${BUILD_CPP_EMPTY_TEST_DEFAULT})
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
if(USE_PREBUILT_LIBS AND MINGW)
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
return()
endif()
endmacro(SelectModule)

View File

@ -0,0 +1,104 @@
macro (SetCompilerOptions)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
# definitions for chipmunk
if (USE_CHIPMUNK)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
if (IOS OR MACOSX)
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
add_definitions(-DCP_USE_CGPOINTS=0)
endif()
else()
add_definitions(-DCC_USE_PHYSICS=0)
endif()
# definitions for box2d
if (USE_BOX2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif()
# definitions for bullet
if (USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
else()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif()
# definitions for recast
if (USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=1)
else()
add_definitions(-DCC_USE_NAVMESH=0)
endif()
# Compiler options
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
# Use inline debug info (/Z7) format. Or internal error may occur.
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
foreach(lang C CXX)
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
endforeach()
else()
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
if(CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif(MSVC)
# Some macro definitions
if(WINDOWS)
if(BUILD_SHARED_LIBS)
add_definitions(-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
else()
add_definitions(-DCC_STATIC)
endif()
add_definitions(-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
set(PLATFORM_FOLDER win32)
elseif(MACOSX OR APPLE)
add_definitions(-DCC_TARGET_OS_MAC)
add_definitions(-DUSE_FILE32API)
set(PLATFORM_FOLDER mac)
elseif(LINUX)
add_definitions(-DLINUX)
set(PLATFORM_FOLDER linux)
elseif(ANDROID)
add_definitions(-DUSE_FILE32API)
set(PLATFORM_FOLDER android)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -latomic")
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
return()
endif()
if(MINGW)
#add_definitions(-DGLEW_STATIC)
add_definitions(-D__SSIZE_T)
if(CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
endif()
endif()
if (MINGW OR NOT USE_PREBUILT_LIBS)
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()
endmacro (SetCompilerOptions)