2015-04-15 17:49:33 +08:00
#/****************************************************************************
# Copyright (c) 2014 Chukong Technologies Inc.
#
# 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.
# ****************************************************************************/
cmake_minimum_required ( VERSION 2.8 )
set ( APP_NAME MyGame )
project ( ${ APP_NAME } )
2015-04-17 14:59:12 +08:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cmake/Modules/" )
2015-04-15 17:49:33 +08:00
include ( CocosBuildHelpers )
option ( USE_CHIPMUNK "Use chipmunk for physics library" ON )
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 ( USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON )
if ( DEBUG_MODE )
set ( CMAKE_BUILD_TYPE DEBUG )
else ( DEBUG_MODE )
set ( CMAKE_BUILD_TYPE RELEASE )
endif ( DEBUG_MODE )
set ( CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1" )
set ( CMAKE_CXX_FLAGS_DEBUG ${ CMAKE_C_FLAGS_DEBUG } )
if ( WIN32 )
ADD_DEFINITIONS ( -D_USRDLL -DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 )
if ( MSVC )
ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS
- D _ S C L _ S E C U R E _ N O _ W A R N I N G S
- 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 ( MSVC ) #MINGW
endif ( MSVC )
elseif ( APPLE )
else ( ) #Linux
ADD_DEFINITIONS ( -DLINUX -DCC_RESOURCE_FOLDER_LINUX= "/" )
endif ( )
if ( NOT MSVC ) # all gcc
set ( CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1" )
set ( CMAKE_CXX_FLAGS_DEBUG ${ CMAKE_C_FLAGS_DEBUG } )
set ( CMAKE_C_FLAGS ${ CMAKE_C_FLAGS } "-std=c99" )
set ( CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } "-std=c++11" )
endif ( )
if ( MINGW )
add_definitions ( -DGLEW_STATIC )
endif ( )
if ( USE_CHIPMUNK )
message ( "Using chipmunk ..." )
add_definitions ( -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 )
elseif ( USE_BOX2D )
message ( "Using box2d ..." )
add_definitions ( -DCC_ENABLE_BOX2D_INTEGRATION=1 )
else ( USE_CHIPMUNK )
message ( FATAL_ERROR "Must choose a physics library." )
endif ( USE_CHIPMUNK )
# architecture
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( ARCH_DIR "64-bit" )
else ( )
set ( ARCH_DIR "32-bit" )
endif ( )
if ( WIN32 ) # Win32
set ( PLATFORM_FOLDER win32 )
elseif ( APPLE ) # osx or ios
set ( PLATFORM_FOLDER mac )
else ( ) # Assume Linux
set ( PLATFORM_FOLDER linux )
endif ( )
2015-04-17 14:59:12 +08:00
set ( COCOS_EXTERNAL_DIR ${ CMAKE_CURRENT_SOURCE_DIR } /frameworks/cocos2d-x/external )
2015-04-15 17:49:33 +08:00
include_directories (
2015-04-17 14:59:12 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x /
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / b a s e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / 2 d
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / u i
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / a u d i o / i n c l u d e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / s t o r a g e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / n e t w o r k
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / p l a t f o r m
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / e d i t o r - s u p p o r t
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / e d i t o r - s u p p o r t / s p i n e
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / e d i t o r - s u p p o r t / c o c o s b u i l d e r
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / e d i t o r - s u p p o r t / c o c o s t u d i o
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / 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 } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / p l a t f o r m
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / e x t e n s i o n s
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / e x t e r n a l
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / e x t e r n a l / c h i p m u n k / i n c l u d e / c h i p m u n k
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / e x t e r n a l / s p i d e r m o n k e y / i n c l u d e / $ { P L A T F O R M _ F O L D E R }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / s c r i p t i n g / j s - b i n d i n g s / a u t o
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / s c r i p t i n g / j s - b i n d i n g s / m a n u a l
2015-04-15 17:49:33 +08:00
)
link_directories (
2015-04-17 14:59:12 +08:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / e x t e r n a l / s p i d e r m o n k e y / p r e b u i l t / $ { P L A T F O R M _ F O L D E R } / $ { A R C H _ D I R }
2015-04-15 17:49:33 +08:00
)
if ( USE_PREBUILT_LIBS )
include ( CocosUsePrebuiltLibs )
endif ( )
# GLFW3 used on Mac, Windows and Linux desktop platforms
if ( LINUX OR MACOSX OR WINDOWS )
cocos_find_package ( OpenGL OPENGL REQUIRED )
if ( LINUX OR WINDOWS )
cocos_find_package ( GLEW GLEW REQUIRED )
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(FMODEX FMODEX REQUIRED)
cocos_find_package ( Fontconfig FONTCONFIG 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 )
cocos_find_package ( Chipmunk CHIPMUNK REQUIRED )
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 )
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/external/Box2D )
2015-04-15 17:49:33 +08:00
set ( Box2D_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /frameworks/js-bindings/cocos2d-x/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 )
# Tinyxml2 (not prebuilded, exists as source)
if ( USE_PREBUILT_LIBS )
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/external/tinyxml2 )
set ( TinyXML2_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /frameworks/cocos2d-x/external/tinyxml2 )
2015-04-15 17:49:33 +08:00
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 )
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/external/unzip )
set ( MINIZIP_INCLUDE_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } /frameworks/cocos2d-x/external/unzip )
2015-04-15 17:49:33 +08:00
set ( MINIZIP_LIBRARIES unzip )
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 )
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/external/flatbuffers )
set ( FLATBUFFERS_INCLUDE_DIRS frameworks/cocos2d-x/external )
2015-04-15 17:49:33 +08:00
message ( STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}" )
# build xxhash
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/external/xxhash )
include_directories ( frameworks/cocos2d-x/external/xxhash )
2015-04-15 17:49:33 +08:00
set ( GAME_SRC
f r a m e w o r k s / r u n t i m e - s r c / p r o j . l i n u x / m a i n . c p p
f r a m e w o r k s / r u n t i m e - s r c / C l a s s e s / A p p D e l e g a t e . c p p
)
# cocos2d
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/cocos )
2015-04-15 17:49:33 +08:00
#jsbindings library
2015-04-17 14:59:12 +08:00
add_subdirectory ( frameworks/cocos2d-x/cocos/scripting/js-bindings )
2015-04-15 17:49:33 +08:00
# add the executable
add_executable ( ${ APP_NAME }
$ { G A M E _ S R C }
)
target_link_libraries ( ${ APP_NAME }
2015-04-20 18:09:39 +08:00
j s c o c o s 2 d
2015-04-15 17:49:33 +08:00
c o c o s 2 d
)
set ( APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin" )
set_target_properties ( ${ APP_NAME } PROPERTIES
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { A P P _ B I N _ D I R } " )
pre_build ( ${ APP_NAME }
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y $ { A P P _ B I N _ D I R } / s c r i p t
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y $ { A P P _ B I N _ D I R } / r e s
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e _ d i r e c t o r y $ { A P P _ B I N _ D I R } / s r c
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e $ { A P P _ B I N _ D I R } / * . j s
C O M M A N D $ { C M A K E _ C O M M A N D } - E r e m o v e $ { A P P _ B I N _ D I R } / * . j s o n
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ d i r e c t o r y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / r e s $ { A P P _ B I N _ D I R } / r e s
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ d i r e c t o r y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / s r c $ { A P P _ B I N _ D I R } / s r c
2015-04-17 14:59:12 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ d i r e c t o r y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / f r a m e w o r k s / c o c o s 2 d - x / c o c o s / s c r i p t i n g / j s - b i n d i n g s / s c r i p t $ { A P P _ B I N _ D I R } / s c r i p t
2015-04-15 17:49:33 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / m a i n . j s $ { A P P _ B I N _ D I R } / m a i n . j s
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / p r o j e c t . j s o n $ { A P P _ B I N _ D I R } / p r o j e c t . j s o n
)