CMake fix for template projects

This commit is contained in:
Anton Sokolchenko 2014-10-15 16:33:58 +03:00
parent 518b5c2949
commit 41b51168d0
6 changed files with 145 additions and 22 deletions

View File

@ -34,17 +34,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
message(${BUILDING_STRING}) message(${BUILDING_STRING})
option(USE_CHIPMUNK "Use chipmunk for physics library" ON) option(USE_CHIPMUNK "Use chipmunk for physics library" OFF)
option(USE_BOX2D "Use box2d for physics library" OFF) option(USE_BOX2D "Use box2d for physics library" ON)
option(BUILD_STATIC "Build static libraries" ON) option(BUILD_STATIC "Build static libraries" ON)
option(DEBUG_MODE "Debug or release?" ON) option(DEBUG_MODE "Debug or release?" ON)
option(BUILD_EXTENSIONS "Build extension library" ON) option(BUILD_EXTENSIONS "Build extension library" ON)
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON) option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON) option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" OFF)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON) option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" OFF)
option(BUILD_CPP_TESTS "Build TestCpp samples" ON) option(BUILD_CPP_TESTS "Build TestCpp samples" OFF)
option(BUILD_LUA_LIBS "Build lua libraries" ON) 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) if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE DEBUG) set(CMAKE_BUILD_TYPE DEBUG)

View File

@ -44,6 +44,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(SYSTEM_STRING "IOS") set(SYSTEM_STRING "IOS")
else() else()
set(MACOSX TRUE) set(MACOSX TRUE)
set(APPLE TRUE)
set(SYSTEM_STRING "Mac OSX") set(SYSTEM_STRING "Mac OSX")
endif() endif()
endif() endif()

View File

@ -25,7 +25,7 @@
# this CMakeLists is to generate libcocos2d.a # this CMakeLists is to generate libcocos2d.a
cmake_minimum_required(VERSION 2.7) cmake_minimum_required(VERSION 2.8)
if(WINDOWS) if(WINDOWS)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE) ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
@ -77,14 +77,20 @@ set(COCOS_SRC cocos2d.cpp
) )
if(MACOSX OR APPLE) if(MACOSX OR APPLE)
include(FindFreetype REQUIRED) 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}) include_directories(${FREETYPE_INCLUDE_DIRS})
endif() endif()
@ -142,7 +148,6 @@ elseif(LINUX)
set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff freetype curl websockets set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff freetype curl websockets
fontconfig png pthread glfw GLEW GL X11 rt z protobuf ${FMOD_LIB}) fontconfig png pthread glfw GLEW GL X11 rt z protobuf ${FMOD_LIB})
elseif(MACOSX OR APPLE) elseif(MACOSX OR APPLE)
set (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) INCLUDE_DIRECTORIES ( /System/Library/Frameworks )
FIND_LIBRARY(COCOA_LIBRARY Cocoa) FIND_LIBRARY(COCOA_LIBRARY Cocoa)
@ -156,7 +161,7 @@ elseif(MACOSX OR APPLE)
set(PLATFORM_SPECIFIC_LIBS set(PLATFORM_SPECIFIC_LIBS
z jpeg png webp tiff curl glfw3 z jpeg png webp tiff curl glfw3
websockets websockets freetype
${COCOA_LIBRARY} ${COCOA_LIBRARY}
${OPENGL_LIBRARY} ${OPENGL_LIBRARY}
${OPENAL_LIBRARY} ${OPENAL_LIBRARY}

View File

@ -81,7 +81,7 @@ THE SOFTWARE.
#endif #endif
// linux // linux
#if defined(LINUX) #if defined(LINUX) && !defined(__APPLE__)
#undef CC_TARGET_PLATFORM #undef CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM CC_PLATFORM_LINUX #define CC_TARGET_PLATFORM CC_PLATFORM_LINUX
#endif #endif

View File

@ -1,7 +1,5 @@
#include "CustomGUIReader.h" #include "CustomGUIReader.h"
#include "CCLuaEngine.h" #include "CCLuaEngine.h"
#include "base/ObjectFactory.h"
#include "json/document.h"
#include "json/writer.h" #include "json/writer.h"
#include "json/stringbuffer.h" #include "json/stringbuffer.h"

View File

@ -20,13 +20,18 @@ if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_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) elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG}) set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
endif() endif()
# architecture # architecture
@ -36,7 +41,34 @@ else()
set(ARCH_DIR "32-bit") set(ARCH_DIR "32-bit")
endif() 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 set(GAME_SRC
proj.linux/main.cpp proj.linux/main.cpp
Classes/AppDelegate.cpp Classes/AppDelegate.cpp
@ -132,9 +164,61 @@ include_directories(
${COCOS2D_ROOT}/external/linux-specific/fmod/include/${ARCH_DIR} ${COCOS2D_ROOT}/external/linux-specific/fmod/include/${ARCH_DIR}
${COCOS2D_ROOT}/external/xxhash ${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) ADD_DEFINITIONS(-DLINUX)
endif()
if(LINUX)
link_directories( link_directories(
/usr/local/lib /usr/local/lib
${COCOS2D_ROOT}/external/jpeg/prebuilt/linux/${ARCH_DIR} ${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/linux-specific/fmod/prebuilt/${ARCH_DIR}
${COCOS2D_ROOT}/external/chipmunk/prebuilt/linux/${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() endif()
# build for 3rd party libraries # build for 3rd party libraries
if(LINUX) if(LINUX OR APPLE)
add_subdirectory(${COCOS2D_ROOT}/external/Box2D) add_subdirectory(${COCOS2D_ROOT}/external/Box2D)
add_subdirectory(${COCOS2D_ROOT}/external/unzip) add_subdirectory(${COCOS2D_ROOT}/external/unzip)
add_subdirectory(${COCOS2D_ROOT}/external/xxhash) add_subdirectory(${COCOS2D_ROOT}/external/xxhash)
@ -159,8 +275,11 @@ endif()
# libcocos2d # libcocos2d
add_subdirectory(${COCOS2D_ROOT}/cocos) add_subdirectory(${COCOS2D_ROOT}/cocos)
if(GAME_HEADERS)
add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS})
else()
add_executable(${APP_NAME} ${GAME_SRC}) add_executable(${APP_NAME} ${GAME_SRC})
endif()
target_link_libraries(${APP_NAME} cocos2d) target_link_libraries(${APP_NAME} cocos2d)