2014-11-29 00:20:02 +08:00
|
|
|
#/****************************************************************************
|
|
|
|
# Copyright (c) 2013-2014 cocos2d-x.org
|
2017-02-14 14:36:57 +08:00
|
|
|
# Copyright (c) 2015-2017 Chukong Technologies Inc.
|
2014-11-29 00:20:02 +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.
|
|
|
|
# ****************************************************************************/
|
|
|
|
cmake_policy(SET CMP0017 NEW)
|
|
|
|
|
2016-03-03 08:51:54 +08:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-01-07 11:34:48 +08:00
|
|
|
set(APP_NAME MyGame)
|
2013-11-08 18:13:24 +08:00
|
|
|
project (${APP_NAME})
|
|
|
|
|
2014-11-29 00:24:48 +08:00
|
|
|
set(COCOS2D_ROOT ${CMAKE_SOURCE_DIR}/cocos2d)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-11-29 00:20:02 +08:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${COCOS2D_ROOT}/cmake/Modules/")
|
|
|
|
include(CocosBuildHelpers)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-11-29 00:20:02 +08:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
else()
|
|
|
|
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
|
|
|
|
endif()
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-05-04 14:02:00 +08:00
|
|
|
|
2014-11-29 00:20:02 +08:00
|
|
|
# Compiler options
|
|
|
|
if(MSVC)
|
2016-08-22 15:50:17 +08:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2017-08-22 15:44:45 +08:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrt /NODEFAULTLIB:libcmt")
|
2016-08-22 15:50:17 +08:00
|
|
|
else()
|
2017-08-22 15:44:45 +08:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt")
|
2016-08-22 15:50:17 +08:00
|
|
|
endif()
|
2014-11-29 00:20:02 +08:00
|
|
|
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
|
|
|
|
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
|
|
|
|
-wd4514 -wd4056 -wd4996 -wd4099)
|
|
|
|
else()
|
2017-08-22 15:44:45 +08:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
ADD_DEFINITIONS(-DCOCOS2D_DEBUG=1)
|
2016-12-20 09:32:51 +08:00
|
|
|
endif()
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "-g -Wall")
|
2014-10-15 21:33:58 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
2015-07-07 03:09:50 +08:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
|
2014-11-29 00:20:02 +08:00
|
|
|
if(CLANG)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
endif()
|
|
|
|
endif(MSVC)
|
2014-10-15 21:33:58 +08:00
|
|
|
|
2017-08-22 15:44:45 +08:00
|
|
|
# libcocos2d
|
|
|
|
set(BUILD_CPP_EMPTY_TEST OFF CACHE BOOL "turn off build cpp-empty-test")
|
|
|
|
set(BUILD_CPP_TESTS OFF CACHE BOOL "turn off build cpp-tests")
|
|
|
|
set(BUILD_LUA_LIBS OFF CACHE BOOL "turn off build lua related targets")
|
|
|
|
set(BUILD_JS_LIBS OFF CACHE BOOL "turn off build js related targets")
|
|
|
|
add_subdirectory(${COCOS2D_ROOT})
|
2016-03-03 08:51:54 +08:00
|
|
|
|
2017-08-22 15:44:45 +08:00
|
|
|
if(ANDROID)
|
|
|
|
set(PLATFORM_SPECIFIC_SRC proj.android/jni/main.cpp)
|
|
|
|
set(RES_PREFIX "/Resources")
|
|
|
|
elseif(WINDOWS)
|
|
|
|
set(PLATFORM_SPECIFIC_SRC proj.win32/main.cpp)
|
2016-03-03 08:51:54 +08:00
|
|
|
set(PLATFORM_SPECIFIC_HEADERS
|
2017-08-22 15:44:45 +08:00
|
|
|
proj.win32/main.h
|
|
|
|
proj.win32/resource.h
|
|
|
|
)
|
|
|
|
set(RES_PREFIX "")
|
|
|
|
elseif(IOS)
|
2016-03-03 08:51:54 +08:00
|
|
|
set(PLATFORM_SPECIFIC_SRC
|
2017-08-22 15:44:45 +08:00
|
|
|
proj.ios_mac/ios/main.m
|
|
|
|
proj.ios_mac/ios/AppController.mm
|
|
|
|
proj.ios_mac/ios/RootViewController.mm
|
|
|
|
)
|
|
|
|
|
|
|
|
elseif(MACOSX OR APPLE)
|
|
|
|
set(PLATFORM_SPECIFIC_SRC proj.ios_mac/mac/main.cpp)
|
|
|
|
|
|
|
|
set(MACOSX_BUNDLE_BUNDLE_NAME "\${PRODUCT_NAME}")
|
|
|
|
set(MACOSX_BUNDLE_INFO_PLIST proj.ios_mac/mac/Info.plist)
|
|
|
|
set(MACOSX_BUNDLE_ICON_FILE Icon)
|
|
|
|
set(MACOSX_BUNDLE_GUI_IDENTIFIER org.cocos2dx.hellocpp)
|
|
|
|
set(MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0)
|
|
|
|
set(MACOSX_BUNDLE_BUNDLE_VERSION 1)
|
|
|
|
set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2017. All rights reserved.")
|
|
|
|
|
|
|
|
file(GLOB_RECURSE RES_FILES Resources/*)
|
|
|
|
cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources)
|
|
|
|
file(GLOB_RECURSE RES_ICON proj.ios_mac/mac/Icon.icns)
|
|
|
|
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.ios_mac/mac)
|
|
|
|
|
|
|
|
list(APPEND PLATFORM_SPECIFIC_SRC ${RES_FILES} ${RES_ICON})
|
|
|
|
|
|
|
|
elseif(LINUX)
|
|
|
|
set(PLATFORM_SPECIFIC_SRC proj.linux/main.cpp)
|
|
|
|
set(RES_PREFIX "/Resources")
|
|
|
|
else()
|
|
|
|
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
|
|
|
|
|
2014-05-04 14:02:00 +08:00
|
|
|
endif()
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-10-15 21:33:58 +08:00
|
|
|
include_directories(
|
2017-08-22 15:44:45 +08:00
|
|
|
/usr/local/include/GLFW
|
|
|
|
/usr/include/GLFW
|
|
|
|
${COCOS2D_ROOT}
|
|
|
|
${COCOS2D_ROOT}/cocos
|
|
|
|
${COCOS2D_ROOT}/external
|
|
|
|
${COCOS2D_ROOT}/cocos/platform
|
|
|
|
${COCOS2D_ROOT}/cocos/audio/include/
|
|
|
|
Classes
|
2015-06-08 01:34:15 +08:00
|
|
|
)
|
2017-08-22 15:44:45 +08:00
|
|
|
if ( WINDOWS )
|
|
|
|
include_directories(
|
|
|
|
${COCOS2D_ROOT}/external/glfw3/include/${PLATFORM_FOLDER}
|
|
|
|
${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/gles/include/OGLES
|
|
|
|
)
|
|
|
|
elseif ( MACOSX OR APPLE )
|
|
|
|
include_directories(
|
|
|
|
${COCOS2D_ROOT}/external/glfw3/include/mac
|
|
|
|
)
|
|
|
|
endif ()
|
2014-08-24 18:52:51 +08:00
|
|
|
|
2014-11-29 00:20:02 +08:00
|
|
|
set(GAME_SRC
|
2017-08-22 15:44:45 +08:00
|
|
|
${PLATFORM_SPECIFIC_SRC}
|
|
|
|
Classes/AppDelegate.cpp
|
|
|
|
Classes/HelloWorldScene.cpp
|
|
|
|
)
|
2014-10-13 16:52:14 +08:00
|
|
|
|
2014-11-29 00:20:02 +08:00
|
|
|
set(GAME_HEADERS
|
2017-08-22 15:44:45 +08:00
|
|
|
${PLATFORM_SPECIFIC_HEADERS}
|
|
|
|
Classes/AppDelegate.h
|
|
|
|
Classes/HelloWorldScene.h
|
|
|
|
)
|
2016-12-20 09:32:51 +08:00
|
|
|
|
2017-08-22 15:44:45 +08:00
|
|
|
# add the executable
|
|
|
|
if(ANDROID)
|
2016-03-03 08:51:54 +08:00
|
|
|
add_library(${APP_NAME} SHARED ${GAME_SRC} ${GAME_HEADERS})
|
2017-08-22 15:44:45 +08:00
|
|
|
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
|
2016-03-03 08:51:54 +08:00
|
|
|
ADD_CUSTOM_COMMAND(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
|
|
|
|
ENDIF()
|
2017-08-22 15:44:45 +08:00
|
|
|
elseif(MSVC)
|
|
|
|
add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS} proj.win32/game.rc)
|
2014-10-15 21:33:58 +08:00
|
|
|
else()
|
2016-03-03 08:51:54 +08:00
|
|
|
add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS})
|
2014-10-15 21:33:58 +08:00
|
|
|
endif()
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-08-24 18:52:51 +08:00
|
|
|
target_link_libraries(${APP_NAME} cocos2d)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
|
|
|
|
2017-08-22 15:44:45 +08:00
|
|
|
if(MSVC)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2017-08-22 15:44:45 +08:00
|
|
|
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${PLATFORM_FOLDER}/$<CONFIG>")
|
|
|
|
|
|
|
|
#get our resources
|
|
|
|
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR})
|
|
|
|
|
|
|
|
# create a list of dlls to copy
|
|
|
|
file(GLOB THIRD_PARTY_DLLS
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/zlib/prebuilt/zlib1.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libogg.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libvorbis.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libvorbisfile.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt/libmpg123.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/OpenalSoft/prebuilt/OpenAL32.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/${PLATFORM_FOLDER}-specific/icon/prebuilt/iconv.dll"
|
|
|
|
"${COCOS2D_ROOT}/external/tiff/prebuilt/${PLATFORM_FOLDER}/libtiff.dll"
|
2014-05-04 14:02:00 +08:00
|
|
|
)
|
2017-08-22 15:44:45 +08:00
|
|
|
|
|
|
|
list(SORT THIRD_PARTY_DLLS)
|
|
|
|
|
|
|
|
# do the copying
|
|
|
|
foreach( file_i ${THIRD_PARTY_DLLS})
|
|
|
|
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${file_i}
|
|
|
|
${APP_BIN_DIR}
|
|
|
|
)
|
|
|
|
endforeach( file_i )
|
|
|
|
|
|
|
|
#Visual Studio Defaults to wrong type
|
|
|
|
set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
|
|
|
|
|
|
|
|
elseif(MACOSX OR APPLE)
|
|
|
|
set_target_properties(${APP_NAME} PROPERTIES
|
|
|
|
MACOSX_BUNDLE 1
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/$<CONFIG>"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/$<CONFIG>"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>"
|
|
|
|
)
|
2016-03-03 08:51:54 +08:00
|
|
|
|
2014-05-04 14:02:00 +08:00
|
|
|
else()
|
2017-08-22 15:44:45 +08:00
|
|
|
|
|
|
|
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
|
|
|
|
|
|
|
|
set_target_properties(${APP_NAME} PROPERTIES
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
|
|
|
|
add_custom_command(TARGET ${APP_NAME} POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $<TARGET_FILE_DIR:${APP_NAME}>${RES_PREFIX}
|
|
|
|
)
|
2013-11-08 18:13:24 +08:00
|
|
|
|
2014-05-29 15:25:58 +08:00
|
|
|
endif()
|