2013-12-05 11:37:27 +08:00
#/****************************************************************************
# Copyright (c) 2013 cocos2d-x.org
2014-08-06 22:43:19 +08:00
# Copyright (c) 2014 martell malone
#
2013-12-05 11:37:27 +08:00
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/
2013-11-30 17:11:36 +08:00
cmake_minimum_required ( VERSION 2.8 )
2014-09-11 07:26:32 +08:00
project ( Cocos2d-X )
2013-11-02 14:40:07 +08:00
# The version number
2014-11-15 05:07:34 +08:00
set ( COCOS2D_X_VERSION 3.3.0-rc1 )
2013-11-02 14:40:07 +08:00
2014-09-18 10:22:24 +08:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR}/cmake/Modules/" )
2014-11-11 15:25:14 +08:00
include ( CocosBuildHelpers )
2013-11-02 14:40:07 +08:00
2014-08-06 22:43:19 +08:00
message ( ${ BUILDING_STRING } )
2013-12-02 15:41:27 +08:00
2014-11-15 16:31:10 +08:00
set ( USE_WEBP_DEFAULT ON )
if ( WINRT OR WP8 )
2014-11-19 08:28:41 +08:00
set ( USE_WEBP_DEFAULT OFF )
endif ( )
set ( USE_PREBUILT_LIBS_DEFAULT ON )
if ( MINGW )
set ( USE_PREBUILT_LIBS_DEFAULT OFF )
2014-11-15 16:31:10 +08:00
endif ( )
2014-10-15 21:45:25 +08:00
option ( USE_CHIPMUNK "Use chipmunk for physics library" ON )
option ( USE_BOX2D "Use box2d for physics library" OFF )
2014-11-15 16:31:10 +08:00
option ( USE_WEBP "Use WebP codec" ${ USE_WEBP_DEFAULT } )
2014-11-18 22:48:54 +08:00
option ( BUILD_SHARED_LIBS "Build shared libraries" OFF )
2014-08-23 05:28:15 +08:00
option ( DEBUG_MODE "Debug or release?" ON )
option ( BUILD_EXTENSIONS "Build extension library" ON )
option ( BUILD_EDITOR_SPINE "Build editor support for spine" ON )
2014-10-15 21:45:25 +08:00
option ( BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON )
option ( BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON )
2014-10-15 21:48:47 +08:00
option ( BUILD_CPP_TESTS "Build TestCpp samples" ON )
2014-09-17 08:34:54 +08:00
option ( BUILD_LUA_LIBS "Build lua libraries" ON )
2014-10-15 21:45:25 +08:00
option ( BUILD_LUA_TESTS "Build TestLua samples" ON )
2014-11-19 08:28:41 +08:00
option ( USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${ USE_PREBUILT_LIBS_DEFAULT } )
2014-08-23 05:28:15 +08:00
2014-11-19 08:28:41 +08:00
if ( USE_PREBUILT_LIBS AND MINGW )
message ( FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages." )
endif ( )
2014-11-15 07:58:16 +08:00
2013-11-06 19:15:20 +08:00
if ( DEBUG_MODE )
2013-11-07 05:24:33 +08:00
set ( CMAKE_BUILD_TYPE DEBUG )
2013-11-06 19:15:20 +08:00
else ( DEBUG_MODE )
2013-11-07 05:24:33 +08:00
set ( CMAKE_BUILD_TYPE RELEASE )
2013-11-06 19:15:20 +08:00
endif ( DEBUG_MODE )
2013-11-30 14:09:12 +08:00
set ( CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1" )
set ( CMAKE_CXX_FLAGS_DEBUG ${ CMAKE_C_FLAGS_DEBUG } )
2014-09-12 08:36:49 +08:00
# Compiler options
2014-08-06 22:43:19 +08:00
if ( MSVC )
ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
- w d 4 2 5 1 - w d 4 2 4 4 - w d 4 3 3 4 - w d 4 0 0 5 - w d 4 8 2 0 - w d 4 7 1 0
- w d 4 5 1 4 - w d 4 0 5 6 - w d 4 9 9 6 - w d 4 0 9 9 )
else ( )
set ( CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1" )
set ( CMAKE_CXX_FLAGS_DEBUG ${ CMAKE_C_FLAGS_DEBUG } )
2014-08-06 22:06:37 +08:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -std=c99" )
2014-08-24 18:52:51 +08:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder" )
2014-09-12 08:36:49 +08:00
if ( CLANG )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
endif ( )
2014-08-06 22:43:19 +08:00
endif ( MSVC )
2013-11-30 14:09:12 +08:00
2014-11-16 02:13:25 +08:00
set ( COCOS_EXTERNAL_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /external )
2014-09-12 08:36:49 +08:00
# Some macro definitions
2014-08-06 22:43:19 +08:00
if ( WINDOWS )
2014-08-23 05:28:15 +08:00
2014-11-18 22:48:54 +08:00
if ( BUILD_SHARED_LIBS )
2014-09-17 08:18:24 +08:00
ADD_DEFINITIONS ( -D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL )
2014-11-18 22:48:54 +08:00
else ( )
ADD_DEFINITIONS ( -DCC_STATIC )
2014-08-23 05:28:15 +08:00
endif ( )
2014-11-19 08:28:41 +08:00
ADD_DEFINITIONS ( -DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32 )
2014-08-06 22:43:19 +08:00
set ( PLATFORM_FOLDER win32 )
2014-10-15 05:19:29 +08:00
elseif ( MACOSX OR APPLE )
2014-09-10 03:18:31 +08:00
ADD_DEFINITIONS ( -DCC_TARGET_OS_MAC )
ADD_DEFINITIONS ( -DUSE_FILE32API )
2014-08-06 22:43:19 +08:00
set ( PLATFORM_FOLDER mac )
2014-09-10 03:18:31 +08:00
elseif ( LINUX )
2014-08-06 22:43:19 +08:00
ADD_DEFINITIONS ( -DLINUX )
set ( PLATFORM_FOLDER linux )
2014-09-20 08:46:39 +08:00
elseif ( ANDROID )
ADD_DEFINITIONS ( -DUSE_FILE32API )
set ( PLATFORM_FOLDER android )
2014-09-10 03:18:31 +08:00
else ( )
message ( FATAL_ERROR "Unsupported platform, CMake will exit" )
2013-11-30 14:09:12 +08:00
endif ( )
2013-12-02 14:57:47 +08:00
if ( MINGW )
2014-11-18 04:44:16 +08:00
#add_definitions(-DGLEW_STATIC)
2014-05-28 00:17:09 +08:00
add_definitions ( -D__SSIZE_T )
2013-12-02 14:57:47 +08:00
2014-08-06 22:43:19 +08:00
if ( CLANG )
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions " )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions " )
endif ( )
endif ( )
2013-11-30 14:09:12 +08:00
2013-11-02 14:40:07 +08:00
# architecture
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2014-09-10 03:18:31 +08:00
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 ( )
2013-11-02 14:40:07 +08:00
include_directories (
2013-11-30 14:09:12 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o c o s
2014-08-24 18:52:51 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
2014-10-09 12:01:22 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / d e p r e c a t e d
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o c o s / p l a t f o r m
2013-11-30 14:09:12 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e n s i o n s
2014-08-25 10:12:36 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t e r n a l
2013-11-02 14:40:07 +08:00
)
2014-11-20 17:05:15 +08:00
if ( USE_PREBUILT_LIBS )
include ( CocosUsePrebuiltLibs )
endif ( )
2014-11-14 15:43:49 +08:00
# GLFW3 used on Mac, Windows and Linux desktop platforms
if ( LINUX OR MACOSX OR WINDOWS )
2014-11-20 17:05:15 +08:00
cocos_find_package ( OpenGL OPENGL REQUIRED )
2014-11-18 04:44:16 +08:00
if ( LINUX OR WINDOWS )
2014-11-20 17:05:15 +08:00
cocos_find_package ( GLEW GLEW REQUIRED )
2014-11-18 04:44:16 +08:00
endif ( )
2014-11-20 17:05:15 +08:00
cocos_find_package ( GLFW3 GLFW3 REQUIRED )
2014-10-09 12:34:27 +08:00
include_directories ( ${ GLFW3_INCLUDE_DIRS } )
2014-11-18 04:44:16 +08:00
2014-11-19 15:57:18 +08:00
if ( LINUX )
set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
find_package ( Threads REQUIRED )
set ( THREADS_LIBRARIES ${ CMAKE_THREAD_LIBS_INIT } )
2014-11-20 17:05:15 +08:00
cocos_find_package ( FMODEX FMODEX REQUIRED )
cocos_find_package ( Fontconfig FONTCONFIG REQUIRED )
2014-11-19 15:57:18 +08:00
endif ( )
2014-11-18 04:44:16 +08:00
if ( WINDOWS )
2014-11-20 17:05:15 +08:00
cocos_find_package ( Vorbis VORBIS REQUIRED )
cocos_find_package ( MPG123 MPG123 REQUIRED )
cocos_find_package ( OpenAL OPENAL REQUIRED )
2014-11-18 22:27:43 +08:00
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
set ( OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES" )
2014-11-18 04:44:16 +08:00
endif ( )
2014-11-14 15:43:49 +08:00
endif ( LINUX OR MACOSX OR WINDOWS )
2014-10-09 12:34:27 +08:00
2014-11-15 07:58:16 +08:00
# Freetype required on all platforms
2014-11-20 17:05:15 +08:00
cocos_find_package ( Freetype FREETYPE REQUIRED )
2014-09-17 11:23:59 +08:00
2014-11-15 16:31:10 +08:00
# WebP required if used
if ( USE_WEBP )
2014-11-20 17:05:15 +08:00
cocos_find_package ( WebP WEBP REQUIRED )
2014-11-15 18:17:23 +08:00
endif ( USE_WEBP )
2014-11-15 19:43:50 +08:00
# Chipmunk
2014-11-15 18:17:23 +08:00
if ( USE_CHIPMUNK )
2014-11-20 17:05:15 +08:00
cocos_find_package ( Chipmunk CHIPMUNK REQUIRED )
2014-11-15 18:17:23 +08:00
add_definitions ( -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 )
2014-11-16 17:19:19 +08:00
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 ( )
2014-11-15 18:38:10 +08:00
else ( USE_CHIPMUNK )
add_definitions ( -DCC_USE_PHYSICS=0 )
2014-11-15 18:17:23 +08:00
endif ( USE_CHIPMUNK )
2014-11-15 08:11:46 +08:00
2014-11-16 20:29:24 +08:00
# Box2d (not prebuilded, exists as source)
2014-11-15 22:46:13 +08:00
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}" )
2014-11-16 02:16:01 +08:00
add_definitions ( -DCC_ENABLE_BOX2D_INTEGRATION=1 )
else ( )
add_definitions ( -DCC_ENABLE_BOX2D_INTEGRATION=0 )
2014-11-15 22:46:13 +08:00
endif ( USE_BOX2D )
2014-11-16 20:29:24 +08:00
# Tinyxml2 (not prebuilded, exists as source)
2014-11-15 19:43:50 +08:00
if ( USE_PREBUILT_LIBS )
add_subdirectory ( external/tinyxml2 )
set ( TinyXML2_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /external/tinyxml2 )
set ( TinyXML2_LIBRARIES tinyxml2 )
else ( )
2014-11-20 17:05:15 +08:00
cocos_find_package ( TinyXML2 TinyXML2 REQUIRED )
2014-11-15 19:43:50 +08:00
endif ( )
message ( STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}" )
2014-11-16 02:16:39 +08:00
# libjpeg
2014-11-20 17:05:15 +08:00
cocos_find_package ( JPEG JPEG REQUIRED )
cocos_find_package ( ZLIB ZLIB REQUIRED )
2014-11-16 05:21:11 +08:00
2014-11-17 03:41:37 +08:00
# 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 )
add_subdirectory ( external/unzip )
set ( MINIZIP_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /external/unzip )
set ( MINIZIP_LIBRARIES unzip )
2014-11-20 17:05:15 +08:00
message ( STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}" )
2014-11-17 03:41:37 +08:00
else ( )
2014-11-20 17:05:15 +08:00
cocos_find_package ( MINIZIP MINIZIP REQUIRED )
2014-11-17 03:41:37 +08:00
# double check that we have needed functions
2014-11-17 06:42:04 +08:00
include ( CheckLibraryExists )
2014-11-17 03:41:37 +08:00
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 ( )
2014-11-16 18:22:54 +08:00
2014-11-20 17:05:15 +08:00
cocos_find_package ( PNG PNG REQUIRED )
cocos_find_package ( TIFF TIFF REQUIRED )
cocos_find_package ( WEBSOCKETS WEBSOCKETS REQUIRED )
cocos_find_package ( CURL CURL REQUIRED )
2014-11-16 18:55:42 +08:00
2014-11-16 20:29:24 +08:00
# protobuf-lite (not prebuilded, exists as source)
# TODO: for now we can't use upstream protobuf because these files:
# cocos/editor-support/cocostudio/CSParseBinary.pb.h
# cocos/editor-support/cocostudio/CSParseBinary.pb.cc
# was generated by concrete version of protobuf compiler
# and source file not provided. So these files can be
# compiled only with our in-source version of protobuf-lite
## if(USE_PREBUILT_LIBS)
add_subdirectory ( external/protobuf-lite )
2014-11-19 05:27:25 +08:00
set ( PROTOBUF_LITE_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /external/protobuf-lite/src )
2014-11-16 20:29:24 +08:00
set ( PROTOBUF_LITE_LIBRARIES protobuf )
## else()
2014-11-20 17:05:15 +08:00
## cocos_find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES)
2014-11-19 05:27:25 +08:00
## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
2014-11-16 20:29:24 +08:00
## endif()
message ( STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}" )
2014-11-19 05:27:25 +08:00
message ( STATUS "Protobuf include dirs: ${PROTOBUF_LITE_INCLUDE_DIRS}" )
2014-09-17 11:23:59 +08:00
2014-11-21 18:08:09 +08:00
# flatbuffers (not prebuilded, exists as source)
# TODO: for now we can't use upstream flatbuffers because these files:
# cocos/editor-support/cocostudio/CSParseBinary_generated.h
# was generated by concrete version of flatbuffers compiler
# and source file not provided. So these files can be
# compiled only with our in-source version of flatbuffers
## if(USE_PREBUILT_LIBS)
add_subdirectory ( external )
set ( FLATBUFFERS_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /external )
set ( FLATBUFFERS_LIBRARIES flatbuffers )
## else()
## cocos_find_package(Flatbuffers REQUIRED FLATBUFFERS_LIBRARIES)
## set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIRS})
## endif()
message ( STATUS "Flatbuffers libs: ${FLATBUFFERS_LIBRARIES}" )
message ( STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}" )
2014-09-17 11:23:59 +08:00
2014-10-09 12:01:22 +08:00
# build for 3rd party libraries
2014-10-15 21:25:51 +08:00
if ( LINUX OR APPLE )
2014-10-09 12:01:22 +08:00
add_subdirectory ( external/xxhash )
endif ( )
2014-09-17 11:23:59 +08:00
2014-08-24 18:52:51 +08:00
# libcocos2d.a
2014-05-02 04:01:51 +08:00
add_subdirectory ( cocos )
2013-11-02 18:07:34 +08:00
2014-09-17 08:34:54 +08:00
# build cpp tests
if ( BUILD_CPP_TESTS )
add_subdirectory ( tests/cpp-empty-test )
add_subdirectory ( tests/cpp-tests )
endif ( BUILD_CPP_TESTS )
2014-03-10 17:10:08 +08:00
## Scripting
2014-09-17 08:34:54 +08:00
if ( BUILD_LUA_LIBS )
add_subdirectory ( cocos/scripting/lua-bindings )
2014-06-04 11:50:04 +08:00
2014-09-17 08:34:54 +08:00
# build lua tests
if ( BUILD_LUA_TESTS )
add_subdirectory ( tests/lua-tests/project )
add_subdirectory ( tests/lua-empty-test/project )
endif ( BUILD_LUA_TESTS )
2014-03-11 17:52:28 +08:00
2014-09-27 16:26:35 +08:00
endif ( BUILD_LUA_LIBS )