|
| 1 | +#/**************************************************************************** |
| 2 | +# Copyright (c) 2014 Chukong Technologies Inc. |
| 3 | +# |
| 4 | +# http://www.cocos2d-x.org |
| 5 | +# |
| 6 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +# of this software and associated documentation files (the "Software"), to deal |
| 8 | +# in the Software without restriction, including without limitation the rights |
| 9 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +# copies of the Software, and to permit persons to whom the Software is |
| 11 | +# furnished to do so, subject to the following conditions: |
| 12 | + |
| 13 | +# The above copyright notice and this permission notice shall be included in |
| 14 | +# all copies or substantial portions of the Software. |
| 15 | + |
| 16 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | +# THE SOFTWARE. |
| 23 | +# ****************************************************************************/ |
| 24 | + |
| 25 | +cmake_minimum_required(VERSION 2.8) |
| 26 | + |
| 27 | +set(APP_NAME MyGame) |
| 28 | +project (${APP_NAME}) |
| 29 | + |
| 30 | +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cmake/Modules/") |
| 31 | +include(CocosBuildHelpers) |
| 32 | + |
| 33 | +option(USE_CHIPMUNK "Use chipmunk for physics library" ON) |
| 34 | +option(DEBUG_MODE "Debug or release?" ON) |
| 35 | +option(BUILD_EXTENSIONS "Build extension library" ON) |
| 36 | +option(BUILD_EDITOR_SPINE "Build editor support for spine" ON) |
| 37 | +option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON) |
| 38 | +option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON) |
| 39 | +option(USE_BULLET "Use bullet for physics3d library" ON) |
| 40 | +option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON) |
| 41 | + |
| 42 | + |
| 43 | +if(DEBUG_MODE) |
| 44 | + set(CMAKE_BUILD_TYPE DEBUG) |
| 45 | +else(DEBUG_MODE) |
| 46 | + set(CMAKE_BUILD_TYPE RELEASE) |
| 47 | +endif(DEBUG_MODE) |
| 48 | + |
| 49 | +if(USE_BULLET) |
| 50 | + add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1) |
| 51 | + add_definitions(-DCC_USE_PHYSICS=1) |
| 52 | +endif(USE_BULLET) |
| 53 | + |
| 54 | +set(CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1") |
| 55 | +set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) |
| 56 | + |
| 57 | +if(WIN32) |
| 58 | + ADD_DEFINITIONS (-D_USRDLL -DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32) |
| 59 | + |
| 60 | + if(MSVC) |
| 61 | + ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS |
| 62 | + -D_SCL_SECURE_NO_WARNINGS |
| 63 | + -wd4251 -wd4244 -wd4334 |
| 64 | + -wd4005 -wd4820 -wd4710 |
| 65 | + -wd4514 -wd4056 -wd4996 -wd4099) |
| 66 | + else(MSVC)#MINGW |
| 67 | + |
| 68 | + endif(MSVC) |
| 69 | +elseif(APPLE) |
| 70 | + |
| 71 | + |
| 72 | +else()#Linux |
| 73 | +ADD_DEFINITIONS(-DLINUX -DCC_RESOURCE_FOLDER_LINUX="/") |
| 74 | +endif() |
| 75 | + |
| 76 | + |
| 77 | +if(NOT MSVC)# all gcc |
| 78 | +set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") |
| 79 | +set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) |
| 80 | +set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99") |
| 81 | +set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") |
| 82 | +endif() |
| 83 | + |
| 84 | +if(MINGW) |
| 85 | + add_definitions(-DGLEW_STATIC) |
| 86 | +endif() |
| 87 | + |
| 88 | + |
| 89 | +if(USE_CHIPMUNK) |
| 90 | + message("Using chipmunk ...") |
| 91 | + add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) |
| 92 | +elseif(USE_BOX2D) |
| 93 | + message("Using box2d ...") |
| 94 | + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1) |
| 95 | +else(USE_CHIPMUNK) |
| 96 | + message(FATAL_ERROR "Must choose a physics library.") |
| 97 | +endif(USE_CHIPMUNK) |
| 98 | + |
| 99 | +# architecture |
| 100 | +if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) |
| 101 | +set(ARCH_DIR "64-bit") |
| 102 | +else() |
| 103 | +set(ARCH_DIR "32-bit") |
| 104 | +endif() |
| 105 | + |
| 106 | +if(WIN32) # Win32 |
| 107 | + set(PLATFORM_FOLDER win32) |
| 108 | +elseif(APPLE)# osx or ios |
| 109 | + set(PLATFORM_FOLDER mac) |
| 110 | +else() # Assume Linux |
| 111 | + set(PLATFORM_FOLDER linux) |
| 112 | +endif() |
| 113 | + |
| 114 | +set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external) |
| 115 | + |
| 116 | + |
| 117 | +include_directories( |
| 118 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/ |
| 119 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos |
| 120 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/base |
| 121 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/2d |
| 122 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/ui |
| 123 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/audio/include |
| 124 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/storage |
| 125 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/network |
| 126 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/platform |
| 127 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support |
| 128 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/spine |
| 129 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/cocosbuilder |
| 130 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/cocostudio |
| 131 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/deprecated |
| 132 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/platform |
| 133 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/extensions |
| 134 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external |
| 135 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/chipmunk/include/chipmunk |
| 136 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/spidermonkey/include/${PLATFORM_FOLDER} |
| 137 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/scripting/js-bindings/auto |
| 138 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/scripting/js-bindings/manual |
| 139 | +) |
| 140 | + |
| 141 | +link_directories( |
| 142 | + ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/spidermonkey/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} |
| 143 | +) |
| 144 | + |
| 145 | + |
| 146 | +if(USE_PREBUILT_LIBS) |
| 147 | + include(CocosUsePrebuiltLibs) |
| 148 | +endif() |
| 149 | + |
| 150 | +# GLFW3 used on Mac, Windows and Linux desktop platforms |
| 151 | +if(LINUX OR MACOSX OR WINDOWS) |
| 152 | + cocos_find_package(OpenGL OPENGL REQUIRED) |
| 153 | + |
| 154 | + if(LINUX OR WINDOWS) |
| 155 | + cocos_find_package(GLEW GLEW REQUIRED) |
| 156 | + endif() |
| 157 | + |
| 158 | + cocos_find_package(GLFW3 GLFW3 REQUIRED) |
| 159 | + include_directories(${GLFW3_INCLUDE_DIRS}) |
| 160 | + |
| 161 | + if(LINUX) |
| 162 | + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) |
| 163 | + find_package(Threads REQUIRED) |
| 164 | + set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) |
| 165 | + |
| 166 | + #cocos_find_package(FMODEX FMODEX REQUIRED) |
| 167 | + cocos_find_package(Fontconfig FONTCONFIG REQUIRED) |
| 168 | + cocos_find_package(GTK3 GTK3 REQUIRED) |
| 169 | + endif() |
| 170 | + |
| 171 | + if(WINDOWS) |
| 172 | + cocos_find_package(Vorbis VORBIS REQUIRED) |
| 173 | + cocos_find_package(MPG123 MPG123 REQUIRED) |
| 174 | + cocos_find_package(OpenAL OPENAL REQUIRED) |
| 175 | + # because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>' |
| 176 | + set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES") |
| 177 | + endif() |
| 178 | +endif(LINUX OR MACOSX OR WINDOWS) |
| 179 | + |
| 180 | +# Freetype required on all platforms |
| 181 | +cocos_find_package(Freetype FREETYPE REQUIRED) |
| 182 | + |
| 183 | +# WebP required if used |
| 184 | +if(USE_WEBP) |
| 185 | + cocos_find_package(WebP WEBP REQUIRED) |
| 186 | +endif(USE_WEBP) |
| 187 | + |
| 188 | +# Chipmunk |
| 189 | +if(USE_CHIPMUNK) |
| 190 | + cocos_find_package(Chipmunk CHIPMUNK REQUIRED) |
| 191 | + add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) |
| 192 | + if(IOS OR MACOSX) |
| 193 | + # without this chipmunk will try to use apple defined geometry types, that conflicts with cocos |
| 194 | + add_definitions(-DCP_USE_CGPOINTS=0) |
| 195 | + endif() |
| 196 | +else(USE_CHIPMUNK) |
| 197 | + add_definitions(-DCC_USE_PHYSICS=0) |
| 198 | +endif(USE_CHIPMUNK) |
| 199 | + |
| 200 | +# Box2d (not prebuilded, exists as source) |
| 201 | +if(USE_BOX2D) |
| 202 | + if(USE_PREBUILT_LIBS) |
| 203 | + add_subdirectory(frameworks/cocos2d-x/external/Box2D) |
| 204 | + set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/js-bindings/cocos2d-x/external/box2d/include) |
| 205 | + set(Box2D_LIBRARIES box2d) |
| 206 | + else() |
| 207 | + find_package(Box2D REQUIRED CONFIG) |
| 208 | + # actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake |
| 209 | + set(Box2D_LIBRARIES Box2D) |
| 210 | + endif() |
| 211 | + message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}") |
| 212 | + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1) |
| 213 | +else() |
| 214 | + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0) |
| 215 | +endif(USE_BOX2D) |
| 216 | + |
| 217 | +# Tinyxml2 (not prebuilded, exists as source) |
| 218 | +if(USE_PREBUILT_LIBS) |
| 219 | + add_subdirectory(frameworks/cocos2d-x/external/tinyxml2) |
| 220 | + set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/tinyxml2) |
| 221 | + set(TinyXML2_LIBRARIES tinyxml2) |
| 222 | +else() |
| 223 | + cocos_find_package(TinyXML2 TinyXML2 REQUIRED) |
| 224 | +endif() |
| 225 | +message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") |
| 226 | + |
| 227 | +# libjpeg |
| 228 | +cocos_find_package(JPEG JPEG REQUIRED) |
| 229 | +cocos_find_package(ZLIB ZLIB REQUIRED) |
| 230 | + |
| 231 | +# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip) |
| 232 | +# only msys2 currently provides package for this variant, all other |
| 233 | +# dists have packages from zlib, thats very old for us. |
| 234 | +# moreover our embedded version modified to quick provide |
| 235 | +# functionality needed by cocos. |
| 236 | +if(USE_PREBUILT_LIBS OR NOT MINGW) |
| 237 | + add_subdirectory(frameworks/cocos2d-x/external/unzip) |
| 238 | + set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/unzip) |
| 239 | + set(MINIZIP_LIBRARIES unzip) |
| 240 | + message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") |
| 241 | +else() |
| 242 | + cocos_find_package(MINIZIP MINIZIP REQUIRED) |
| 243 | + # double check that we have needed functions |
| 244 | + include(CheckLibraryExists) |
| 245 | + check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2) |
| 246 | + if(NOT MINIZIP_HAS_GOTOFIRSTFILE2) |
| 247 | + 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") |
| 248 | + endif() |
| 249 | + add_definitions(-DMINIZIP_FROM_SYSTEM) |
| 250 | +endif() |
| 251 | + |
| 252 | +cocos_find_package(PNG PNG REQUIRED) |
| 253 | +cocos_find_package(TIFF TIFF REQUIRED) |
| 254 | +cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED) |
| 255 | +cocos_find_package(CURL CURL REQUIRED) |
| 256 | + |
| 257 | + |
| 258 | +add_subdirectory(frameworks/cocos2d-x/external/flatbuffers) |
| 259 | +set(FLATBUFFERS_INCLUDE_DIRS frameworks/cocos2d-x/external) |
| 260 | +message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}") |
| 261 | + |
| 262 | + |
| 263 | +# build xxhash |
| 264 | +add_subdirectory(frameworks/cocos2d-x/external/xxhash) |
| 265 | +include_directories(frameworks/cocos2d-x/external/xxhash) |
| 266 | + |
| 267 | +#buid recast |
| 268 | +add_subdirectory(frameworks/cocos2d-x/external/recast) |
| 269 | + |
| 270 | +set(GAME_SRC |
| 271 | + frameworks/runtime-src/proj.linux/main.cpp |
| 272 | + frameworks/runtime-src/Classes/AppDelegate.cpp |
| 273 | +) |
| 274 | + |
| 275 | +# cocos2d |
| 276 | +add_subdirectory(frameworks/cocos2d-x/cocos) |
| 277 | + |
| 278 | +#jsbindings library |
| 279 | +add_subdirectory(frameworks/cocos2d-x/cocos/scripting/js-bindings) |
| 280 | + |
| 281 | +# add the executable |
| 282 | +add_executable(${APP_NAME} |
| 283 | + ${GAME_SRC} |
| 284 | +) |
| 285 | + |
| 286 | +target_link_libraries(${APP_NAME} |
| 287 | + jscocos2d |
| 288 | + cocos2d |
| 289 | + recast |
| 290 | +) |
| 291 | + |
| 292 | +if(USE_BULLET) |
| 293 | + add_subdirectory(frameworks/cocos2d-x/external/bullet) |
| 294 | + target_link_libraries(${APP_NAME} bullet) |
| 295 | +endif() |
| 296 | + |
| 297 | +set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin") |
| 298 | + |
| 299 | +set_target_properties(${APP_NAME} PROPERTIES |
| 300 | + RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") |
| 301 | + |
| 302 | +pre_build(${APP_NAME} |
| 303 | + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/script |
| 304 | + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/res |
| 305 | + COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/src |
| 306 | + COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}/*.js |
| 307 | + COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}/*.json |
| 308 | + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res ${APP_BIN_DIR}/res |
| 309 | + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${APP_BIN_DIR}/src |
| 310 | + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/scripting/js-bindings/script ${APP_BIN_DIR}/script |
| 311 | + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/main.js ${APP_BIN_DIR}/main.js |
| 312 | + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/project.json ${APP_BIN_DIR}/project.json |
| 313 | +) |
| 314 | + |
0 commit comments