fix js template

This commit is contained in:
minggo 2016-07-27 16:53:17 +08:00
parent 30118aff6b
commit b74900fe70
2 changed files with 79 additions and 251 deletions

View File

@ -50,7 +50,7 @@ macro (BuildModules)
# Box2d (not prebuilded, exists as source)
if(USE_BOX2D)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/Box2D)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/Box2D)
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
set(Box2D_LIBRARIES box2d)
else()
@ -60,13 +60,13 @@ macro (BuildModules)
endif()
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
elseif(BUILD_BOX2D)
add_subdirectory(external/Box2D)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/Box2D)
endif(USE_BOX2D)
# Bullet (not prebuilded, exists as source)
if(USE_BULLET)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/bullet)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_LIBRARIES bullet)
else()
@ -79,7 +79,7 @@ macro (BuildModules)
# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/recast)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
set(RECAST_LIBRARIES recast)
else()
@ -91,7 +91,7 @@ macro (BuildModules)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/tinyxml2)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
set(TinyXML2_LIBRARIES tinyxml2)
else()
@ -111,7 +111,7 @@ macro (BuildModules)
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)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/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}")
@ -133,7 +133,7 @@ macro (BuildModules)
# flatbuffers
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/flatbuffers)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
@ -142,7 +142,7 @@ macro (BuildModules)
# xxhash
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/xxhash)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
else()
@ -150,5 +150,5 @@ macro (BuildModules)
endif()
# libcocos2d.a
add_subdirectory(cocos)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cocos)
endmacro(BuildModules)

View File

@ -1,6 +1,8 @@
#/****************************************************************************
# Copyright (c) 2014 Chukong Technologies Inc.
#
# Copyright (c) 2013 cocos2d-x.org
# Copyright (c) 2014 martell malone
# Copyright (c) 2015 Chukong Technologies Inc.
#
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@ -22,263 +24,95 @@
# THE SOFTWARE.
# ****************************************************************************/
cmake_minimum_required(VERSION 2.8)
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()
set(APP_NAME MyGame)
project (${APP_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cmake/Modules/")
# define some variables
set(COCOS2D_X_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x)
set(RUNTIME_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/runtime-src)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${COCOS2D_X_ROOT}/cmake/Modules/")
set(COCOS_EXTERNAL_DIR ${COCOS2D_X_ROOT}/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)
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_BULLET "Use bullet for physics3d library" ON)
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON)
message(${BUILDING_STRING})
# SelectModule() is a macro to select building modules
include(SelectModule)
SelectModule()
if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE DEBUG)
else(DEBUG_MODE)
set(CMAKE_BUILD_TYPE RELEASE)
endif(DEBUG_MODE)
if(USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
endif(USE_BULLET)
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_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334
-wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
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()
set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external)
# 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}/frameworks/cocos2d-x/
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/base
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/2d
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/ui
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/audio/include
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/storage
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/network
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/platform
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/spine
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/cocosbuilder
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/editor-support/cocostudio
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/deprecated
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/platform
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/extensions
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/chipmunk/include/chipmunk
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/spidermonkey/include/${PLATFORM_FOLDER}
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/scripting/js-bindings/auto
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/cocos/scripting/js-bindings/manual
${COCOS2D_X_ROOT}
${COCOS2D_X_ROOT}/cocos
${COCOS2D_X_ROOT}/deprecated
${COCOS2D_X_ROOT}/cocos/platform
${COCOS2D_X_ROOT}/extensions
${COCOS2D_X_ROOT}/external
${COCOS2D_X_ROOT}/external/spidermonkey/include/${PLATFORM_FOLDER}
${COCOS2D_X_ROOT}/cocos/editor-support
)
link_directories(
${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/spidermonkey/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
)
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)
set(PREV_CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CURRENT_SOURCE_DIR ${COCOS2D_X_ROOT})
include(BuildModules)
BuildModules()
set(CMAKE_CURRENT_SOURCE_DIR ${PREV_CMAKE_CURRENT_SOURCE_DIR})
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)
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)
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)
add_subdirectory(frameworks/cocos2d-x/external/Box2D)
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)
if(WIN32)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS)
add_subdirectory(frameworks/cocos2d-x/external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/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)
add_subdirectory(frameworks/cocos2d-x/external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x/external/unzip)
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)
set(GAME_SRC
${RUNTIME_SRC_ROOT}/proj.linux/main.cpp
${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp
)
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)
# jsbinding library
add_subdirectory(${COCOS2D_X_ROOT}/cocos/scripting/js-bindings)
add_subdirectory(frameworks/cocos2d-x/external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS frameworks/cocos2d-x/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
# build xxhash
add_subdirectory(frameworks/cocos2d-x/external/xxhash)
include_directories(frameworks/cocos2d-x/external/xxhash)
#buid recast
add_subdirectory(frameworks/cocos2d-x/external/recast)
set(GAME_SRC
frameworks/runtime-src/proj.linux/main.cpp
frameworks/runtime-src/Classes/AppDelegate.cpp
)
# cocos2d
add_subdirectory(frameworks/cocos2d-x/cocos)
#jsbindings library
add_subdirectory(frameworks/cocos2d-x/cocos/scripting/js-bindings)
# add the executable
add_executable(${APP_NAME}
${GAME_SRC}
)
@ -286,14 +120,8 @@ add_executable(${APP_NAME}
target_link_libraries(${APP_NAME}
jscocos2d
cocos2d
recast
)
if(USE_BULLET)
add_subdirectory(frameworks/cocos2d-x/external/bullet)
target_link_libraries(${APP_NAME} bullet)
endif()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
set_target_properties(${APP_NAME} PROPERTIES