From 41b51168d0419f04ec2d974eae856cc39e040660 Mon Sep 17 00:00:00 2001 From: Anton Sokolchenko Date: Wed, 15 Oct 2014 16:33:58 +0300 Subject: [PATCH] CMake fix for template projects --- CMakeLists.txt | 12 +- cmake/BuildHelpers.CMakeLists.txt | 1 + cocos/CMakeLists.txt | 23 ++-- cocos/platform/CCPlatformConfig.h | 2 +- .../manual/cocostudio/CustomGUIReader.cpp | 2 - templates/cpp-template-default/CMakeLists.txt | 127 +++++++++++++++++- 6 files changed, 145 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f22763e666..060735979c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,17 +34,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") message(${BUILDING_STRING}) -option(USE_CHIPMUNK "Use chipmunk for physics library" ON) -option(USE_BOX2D "Use box2d for physics library" OFF) +option(USE_CHIPMUNK "Use chipmunk for physics library" OFF) +option(USE_BOX2D "Use box2d for physics library" ON) option(BUILD_STATIC "Build static libraries" 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(BUILD_CPP_TESTS "Build TestCpp samples" ON) +option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" OFF) +option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" OFF) +option(BUILD_CPP_TESTS "Build TestCpp samples" OFF) option(BUILD_LUA_LIBS "Build lua libraries" ON) -option(BUILD_LUA_TESTS "Build TestLua samples" ON) +option(BUILD_LUA_TESTS "Build TestLua samples" OFF) if(DEBUG_MODE) set(CMAKE_BUILD_TYPE DEBUG) diff --git a/cmake/BuildHelpers.CMakeLists.txt b/cmake/BuildHelpers.CMakeLists.txt index 1ebcb2fc6e..1ad543c6d5 100644 --- a/cmake/BuildHelpers.CMakeLists.txt +++ b/cmake/BuildHelpers.CMakeLists.txt @@ -44,6 +44,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(SYSTEM_STRING "IOS") else() set(MACOSX TRUE) + set(APPLE TRUE) set(SYSTEM_STRING "Mac OSX") endif() endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 53be4b483a..e792575153 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -25,7 +25,7 @@ # this CMakeLists is to generate libcocos2d.a -cmake_minimum_required(VERSION 2.7) +cmake_minimum_required(VERSION 2.8) if(WINDOWS) ADD_DEFINITIONS(-DUNICODE -D_UNICODE) @@ -77,14 +77,20 @@ set(COCOS_SRC cocos2d.cpp ) if(MACOSX OR APPLE) - include(FindFreetype REQUIRED) - IF(NOT FREETYPE_FOUND) - FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype freetype.dll PATHS "../external/freetype2/prebuilt/mac" "../external/freetype2/prebuilt/ios" DOC "Freetype includes") - find_path(FREETYPE_INCLUDE_DIRS ft2build.h "../external/freetype2/include/mac" "../external/freetype2/include/mac/freetype" "../external/freetype2/include/ios" "../external/freetype2/include/ios/freetype" DOC "Freetype includes") - ENDIF(NOT FREETYPE_FOUND) - find_package(Freetype) + if(NOT FREETYPE_FOUND) + if(IOS) + FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype PATHS "../external/freetype2/prebuilt/ios" DOC "Freetype includes") + find_path(FREETYPE_INCLUDE_DIRS ft2build.h "../external/freetype2/include/ios" "../external/freetype2/include/ios/freetype" DOC "Freetype includes") + + elseif() + FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype PATHS "../external/freetype2/prebuilt/mac" DOC "Freetype includes") + find_path(FREETYPE_INCLUDE_DIRS ft2build.h "../external/freetype2/include/mac" "../external/freetype2/include/mac/freetype" DOC "Freetype includes") + endif(IOS) + endif(NOT FREETYPE_FOUND) + + find_package(Freetype REQUIRED) include_directories(${FREETYPE_INCLUDE_DIRS}) endif() @@ -142,7 +148,6 @@ elseif(LINUX) set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff freetype curl websockets fontconfig png pthread glfw GLEW GL X11 rt z protobuf ${FMOD_LIB}) elseif(MACOSX OR APPLE) - set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) FIND_LIBRARY(COCOA_LIBRARY Cocoa) @@ -156,7 +161,7 @@ elseif(MACOSX OR APPLE) set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl glfw3 - websockets + websockets freetype ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} diff --git a/cocos/platform/CCPlatformConfig.h b/cocos/platform/CCPlatformConfig.h index 5ca81425b5..dee092326c 100644 --- a/cocos/platform/CCPlatformConfig.h +++ b/cocos/platform/CCPlatformConfig.h @@ -81,7 +81,7 @@ THE SOFTWARE. #endif // linux -#if defined(LINUX) +#if defined(LINUX) && !defined(__APPLE__) #undef CC_TARGET_PLATFORM #define CC_TARGET_PLATFORM CC_PLATFORM_LINUX #endif diff --git a/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp b/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp index fa0bcb1832..bb8d05a1b9 100644 --- a/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp +++ b/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp @@ -1,7 +1,5 @@ #include "CustomGUIReader.h" #include "CCLuaEngine.h" -#include "base/ObjectFactory.h" -#include "json/document.h" #include "json/writer.h" #include "json/stringbuffer.h" diff --git a/templates/cpp-template-default/CMakeLists.txt b/templates/cpp-template-default/CMakeLists.txt index bbc1a303b7..3e32f7883a 100644 --- a/templates/cpp-template-default/CMakeLists.txt +++ b/templates/cpp-template-default/CMakeLists.txt @@ -20,13 +20,18 @@ if (MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS") +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + 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} -fno-exceptions -std=c99") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -std=c++11 -stdlib=libc++ -Wno-deprecated-declarations -Wno-reorder") + elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) 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 -Wno-deprecated-declarations -Wno-reorder") - endif() # architecture @@ -36,7 +41,34 @@ else() set(ARCH_DIR "32-bit") endif() -if( UNIX ) #assume linux +if( APPLE AND IOS ) +include_directories(Classes) +set(GAME_SRC + proj.ios_mac/ios/main.m + proj.ios_mac/ios/RootViewController.mm + proj.ios_mac/ios/AppController.mm + Classes/AppDelegate.cpp + Classes/HelloWorldScene.cpp +) +set(GAME_HEADERS + Classes/AppDelegate.h + Classes/HelloWorldScene.h + proj.ios_mac/ios/RootViewController.h + proj.ios_mac/ios/AppController.h +) +elseif(APPLE) #desktop +include_directories(Classes) +include(Classes/CMakeLists.txt) +set(GAME_SRC + proj.ios_mac/mac/main.cpp + Classes/AppDelegate.cpp + Classes/HelloWorldScene.cpp +) +set(GAME_HEADERS + Classes/AppDelegate.h + Classes/HelloWorldScene.h +) +elseif( UNIX AND NOT APPLE) #assume linux set(GAME_SRC proj.linux/main.cpp Classes/AppDelegate.cpp @@ -132,9 +164,61 @@ include_directories( ${COCOS2D_ROOT}/external/linux-specific/fmod/include/${ARCH_DIR} ${COCOS2D_ROOT}/external/xxhash ) +elseif(APPLE AND IOS) +include_directories( + /usr/local/include/GLFW + /usr/include/GLFW + ${COCOS2D_ROOT} + ${COCOS2D_ROOT}/cocos + ${COCOS2D_ROOT}/cocos/audio/include + ${COCOS2D_ROOT}/cocos/platform + ${COCOS2D_ROOT}/cocos/platform/ios + ${COCOS2D_ROOT}/cocos/editor-support + ${COCOS2D_ROOT}/extensions + ${COCOS2D_ROOT}/external + ${COCOS2D_ROOT}/external/edtaa3func + ${COCOS2D_ROOT}/external/chipmunk/include/chipmunk + ${COCOS2D_ROOT}/external/jpeg/include/ios + ${COCOS2D_ROOT}/external/tiff/include/ios + ${COCOS2D_ROOT}/external/webp/include/ios + ${COCOS2D_ROOT}/external/tinyxml2 + ${COCOS2D_ROOT}/external/unzip + ${COCOS2D_ROOT}/external/freetype2/include/ios + ${COCOS2D_ROOT}/external/websockets/include/ios + ${COCOS2D_ROOT}/external/spidermonkey/include/liniosux + ${COCOS2D_ROOT}/external/xxhash +) +elseif(APPLE) #assumed linux +include_directories( + /usr/local/include/GLFW + /usr/include/GLFW + ${COCOS2D_ROOT} + ${COCOS2D_ROOT}/cocos + ${COCOS2D_ROOT}/cocos/audio/include + ${COCOS2D_ROOT}/cocos/platform + ${COCOS2D_ROOT}/cocos/platform/mac + ${COCOS2D_ROOT}/cocos/editor-support + ${COCOS2D_ROOT}/extensions + ${COCOS2D_ROOT}/external + ${COCOS2D_ROOT}/external/edtaa3func + ${COCOS2D_ROOT}/external/chipmunk/include/chipmunk + ${COCOS2D_ROOT}/external/jpeg/include/mac + ${COCOS2D_ROOT}/external/tiff/include/mac + ${COCOS2D_ROOT}/external/webp/include/mac + ${COCOS2D_ROOT}/external/tinyxml2 + ${COCOS2D_ROOT}/external/unzip + ${COCOS2D_ROOT}/external/freetype2/include/mac + ${COCOS2D_ROOT}/external/websockets/include/mac + ${COCOS2D_ROOT}/external/spidermonkey/include/liniosux + ${COCOS2D_ROOT}/external/xxhash +) +endif() +if(NOT APPLE) ADD_DEFINITIONS(-DLINUX) +endif() +if(LINUX) link_directories( /usr/local/lib ${COCOS2D_ROOT}/external/jpeg/prebuilt/linux/${ARCH_DIR} @@ -146,10 +230,42 @@ link_directories( ${COCOS2D_ROOT}/external/linux-specific/fmod/prebuilt/${ARCH_DIR} ${COCOS2D_ROOT}/external/chipmunk/prebuilt/linux/${ARCH_DIR} ) +elseif(APPLE AND IOS) +link_directories( + /usr/local/lib + ${COCOS2D_ROOT}/external/jpeg/prebuilt/ios + ${COCOS2D_ROOT}/external/tiff/prebuilt/ios + ${COCOS2D_ROOT}/external/webp/prebuilt/ios + ${COCOS2D_ROOT}/external/freetype2/prebuilt/ios + ${COCOS2D_ROOT}/external/websockets/prebuilt/ios + ${COCOS2D_ROOT}/external/chipmunk/prebuilt/ios +) +elseif(APPLE) +if(IOS) +link_directories( +/usr/local/lib + ${COCOS2D_ROOT}/external/jpeg/prebuilt/ios + ${COCOS2D_ROOT}/external/tiff/prebuilt/ios + ${COCOS2D_ROOT}/external/webp/prebuilt/ios + ${COCOS2D_ROOT}/external/freetype2/prebuilt/ios + ${COCOS2D_ROOT}/external/websockets/prebuilt/ios + ${COCOS2D_ROOT}/external/chipmunk/prebuilt/ios +) +else() +link_directories( +/usr/local/lib + ${COCOS2D_ROOT}/external/jpeg/prebuilt/mac + ${COCOS2D_ROOT}/external/tiff/prebuilt/mac + ${COCOS2D_ROOT}/external/webp/prebuilt/mac + ${COCOS2D_ROOT}/external/freetype2/prebuilt/mac + ${COCOS2D_ROOT}/external/websockets/prebuilt/mac + ${COCOS2D_ROOT}/external/chipmunk/prebuilt/mac +) +endif() endif() # build for 3rd party libraries -if(LINUX) +if(LINUX OR APPLE) add_subdirectory(${COCOS2D_ROOT}/external/Box2D) add_subdirectory(${COCOS2D_ROOT}/external/unzip) add_subdirectory(${COCOS2D_ROOT}/external/xxhash) @@ -159,8 +275,11 @@ endif() # libcocos2d add_subdirectory(${COCOS2D_ROOT}/cocos) - +if(GAME_HEADERS) +add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS}) +else() add_executable(${APP_NAME} ${GAME_SRC}) +endif() target_link_libraries(${APP_NAME} cocos2d)