From ddce662ec3866377f8cd9d7ef35f867bb697dc3a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 02:58:16 +0300 Subject: [PATCH 01/39] Unify usage of prebuilt libraries in cmake builds. * introduce config variable USE_PREBUILT_LIBS (default: ON). When OFF, cmake will not use prebuilt libs, only try find system installed libraries. * FindGLFW3.cmake now search our prebuilt library (if USE_PREBULT_LIBS) * FindFreetype.cmake also This and next changes should simplify our CMakeLists.txt files and USE_PREBUILT_LIBS config allow external package developers to integrate cocos to their packaging system. --- CMakeLists.txt | 16 ++- cmake/Modules/FindFreetype.cmake | 172 +++++++++++++++++++++++++++++++ cmake/Modules/FindGLFW3.cmake | 20 ++++ cocos/CMakeLists.txt | 33 ++---- 4 files changed, 205 insertions(+), 36 deletions(-) create mode 100644 cmake/Modules/FindFreetype.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 212ba9f946..5348423839 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ option(BUILD_CPP_TESTS "Build TestCpp samples" ON) option(BUILD_LUA_LIBS "Build lua libraries" ON) option(BUILD_LUA_TESTS "Build TestLua samples" ON) +option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON) + if(DEBUG_MODE) set(CMAKE_BUILD_TYPE DEBUG) else(DEBUG_MODE) @@ -160,15 +162,17 @@ include_directories( # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - list(APPEND CMAKE_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER}) - list(APPEND CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER_ARCH}) find_package(GLFW3 REQUIRED) - message( STATUS "GLFW3 dirs: ${GLFW3_INCLUDE_DIRS}") + message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) endif(LINUX OR MACOSX OR WINDOWS) +# Freetype required on all platforms +find_package(Freetype REQUIRED) +message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") +include_directories(${FREETYPE_INCLUDE_DIRS}) if(NOT MINGW) @@ -181,16 +185,11 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 ) -#todo: fix location of freetype includes for linux android on cocos prebuilt repo -#i.e we should not need to include an extra dir of /freetype2 - link_directories( ${PLATFORM_LINK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} @@ -198,7 +197,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake new file mode 100644 index 0000000000..1bf1dc8830 --- /dev/null +++ b/cmake/Modules/FindFreetype.cmake @@ -0,0 +1,172 @@ +#.rst: +# FindFreetype +# ------------ +# +# Locate FreeType library +# +# This module defines +# +# :: +# +# FREETYPE_LIBRARIES, the library to link against +# FREETYPE_FOUND, if false, do not try to link to FREETYPE +# FREETYPE_INCLUDE_DIRS, where to find headers. +# FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8) +# This is the concatenation of the paths: +# FREETYPE_INCLUDE_DIR_ft2build +# FREETYPE_INCLUDE_DIR_freetype2 +# +# +# +# $FREETYPE_DIR is an environment variable that would correspond to the +# ./configure --prefix=$FREETYPE_DIR used in building FREETYPE. + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Created by Eric Wing. +# Modifications by Alexander Neundorf. +# This file has been renamed to "FindFreetype.cmake" instead of the correct +# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex. + +# Try find freetype for our arch in external folder +#todo: fix location of freetype includes for linux android on cocos prebuilt repo +#i.e we should not need to include an extra dir of /freetype2 + +if(USE_PREBUILT_LIBS) + find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 + NO_DEFAULT_PATH + ) + find_library(FREETYPE_LIBRARY + NAMES freetype libfreetype freetype219 freetype250 + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT FREETYPE_INCLUDE_DIR_ft2build OR NOT FREETYPE_INCLUDE_DIR_freetype2 OR NOT FREETYPE_LIBRARY) + unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) + unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) + unset(FREETYPE_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +# Ugh, FreeType seems to use some #include trickery which +# makes this harder than it should be. It looks like they +# put ft2build.h in a common/easier-to-find location which +# then contains a #include to a more specific header in a +# more specific location (#include ). +# Then from there, they need to set a bunch of #define's +# so you can do something like: +# #include FT_FREETYPE_H +# Unfortunately, using CMake's mechanisms like include_directories() +# wants explicit full paths and this trickery doesn't work too well. +# I'm going to attempt to cut out the middleman and hope +# everything still works. +find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h + HINTS + ENV FREETYPE_DIR + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + PATH_SUFFIXES include/freetype2 include +) + +find_path(FREETYPE_INCLUDE_DIR_freetype2 + NAMES + freetype/config/ftheader.h + config/ftheader.h + HINTS + ENV FREETYPE_DIR + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + PATH_SUFFIXES include/freetype2 include +) + +find_library(FREETYPE_LIBRARY + NAMES freetype libfreetype freetype219 + HINTS + ENV FREETYPE_DIR + PATH_SUFFIXES lib + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] +) + +# set the user variables +if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) + set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}") + list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS) +endif() +set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}") + +if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") +elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") +endif() + +if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) + file(STRINGS "${FREETYPE_H}" freetype_version_str + REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$") + + unset(FREETYPE_VERSION_STRING) + foreach(VPART MAJOR MINOR PATCH) + foreach(VLINE ${freetype_version_str}) + if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}") + string(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1" + FREETYPE_VERSION_PART "${VLINE}") + if(FREETYPE_VERSION_STRING) + set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}") + else() + set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}") + endif() + unset(FREETYPE_VERSION_PART) + endif() + endforeach() + endforeach() +endif() + + +# handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype + REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS + VERSION_VAR FREETYPE_VERSION_STRING) + +mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) diff --git a/cmake/Modules/FindGLFW3.cmake b/cmake/Modules/FindGLFW3.cmake index 07799b25cc..654b4eb9e7 100644 --- a/cmake/Modules/FindGLFW3.cmake +++ b/cmake/Modules/FindGLFW3.cmake @@ -27,6 +27,26 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +# Try find glfw for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(GLFW3_INCLUDE_DIR glfw3.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_library(GLFW3_LIBRARY + NAMES glfw3 libglfw3 lgfw + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT GLFW3_INCLUDE_DIR OR NOT GLFW3_LIBRARY) + unset(GLFW3_INCLUDE_DIR CACHE) + unset(GLFW3_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(GLFW3_INCLUDE_DIR glfw3.h HINTS ENV GLFW3_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 16aad5f9ed..f5e7104603 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,27 +81,7 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(MACOSX OR APPLE) - include(FindFreetype REQUIRED) - - 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() - if(MINGW) - find_package(Freetype REQUIRED) find_package(WebP REQUIRED) find_package(Protobuf REQUIRED) #find_package(MiniZip REQUIRED) @@ -113,11 +93,10 @@ if(MINGW) message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") message( STATUS "WEBP dirs: ${WEBP_INCLUDE_DIRS}") - message( STATUS "FREETYPE dirs: ${FREETYPE_INCLUDE_DIRS}") message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${FREETYPE_INCLUDE_DIRS} ${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -145,11 +124,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv freetype bz2) + set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets freetype250 glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff freetype curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -164,7 +143,7 @@ elseif(MACOSX OR APPLE) set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl - websockets freetype + websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -186,7 +165,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) set_target_properties(cocos2d PROPERTIES From 53d23ce5f3bb3ec6310e6225b48c0e5ed7f6d461 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 03:11:46 +0300 Subject: [PATCH 02/39] Unify WebP usage. --- CMakeLists.txt | 7 +++++-- cmake/Modules/FindWebP.cmake | 20 ++++++++++++++++++++ cocos/CMakeLists.txt | 14 ++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5348423839..0c65a2f757 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,11 @@ find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") include_directories(${FREETYPE_INCLUDE_DIRS}) +# WebP required on all platforms +find_package(WebP REQUIRED) +message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") +include_directories(${WEBP_INCLUDE_DIRS}) + if(NOT MINGW) include_directories( @@ -184,7 +189,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src @@ -195,7 +199,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index 4b716f55b8..e885ffeb6d 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -27,6 +27,26 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +# Try find WebP for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(WEBP_INCLUDE_DIR decode.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_library(WEBP_LIBRARY + NAMES webp libwebp + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT WEBP_INCLUDE_DIR OR NOT WEBP_LIBRARY) + unset(WEBP_INCLUDE_DIR CACHE) + unset(WEBP_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(WEBP_INCLUDE_DIR decode.h HINTS ENV WEBP_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index f5e7104603..d332b45471 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -82,7 +82,6 @@ set(COCOS_SRC cocos2d.cpp ) if(MINGW) - find_package(WebP REQUIRED) find_package(Protobuf REQUIRED) #find_package(MiniZip REQUIRED) #${MINIZIP_INCLUDE_DIR} @@ -92,11 +91,10 @@ if(MINGW) find_package(Chipmunk REQUIRED) message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "WEBP dirs: ${WEBP_INCLUDE_DIRS}") message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -124,11 +122,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS z jpeg png tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS jpeg tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -142,7 +140,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z jpeg png webp tiff curl + z jpeg png tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -165,7 +163,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${WEBP_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) set_target_properties(cocos2d PROPERTIES From aaff42d6a9bb96bedbeacf14b605f723256397ef Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 11:31:10 +0300 Subject: [PATCH 03/39] Fix WebP usage. * Introduce config variable USE_WEBP (ON by default, but disabled for unsupported archs WINRT and WP8) * Set CC_USE_WEBP define according to USE_WEBP variable * add WebP include directories to search patch only for libcocos compilation (it not used in public headers) --- CMakeLists.txt | 11 +++++++++-- cocos/CMakeLists.txt | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c65a2f757..552ecf35ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,8 +34,14 @@ include(CocosBuildHelpers) message(${BUILDING_STRING}) +set(USE_WEBP_DEFAULT ON) +if(WINRT OR WP8) + set(USE_WEBP_DEFAULT OFF) +endif() + option(USE_CHIPMUNK "Use chipmunk for physics library" ON) option(USE_BOX2D "Use box2d for physics library" OFF) +option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT}) option(BUILD_STATIC "Build static libraries" ON) option(DEBUG_MODE "Debug or release?" ON) option(BUILD_EXTENSIONS "Build extension library" ON) @@ -174,10 +180,11 @@ find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") include_directories(${FREETYPE_INCLUDE_DIRS}) -# WebP required on all platforms +# WebP required if used +if(USE_WEBP) find_package(WebP REQUIRED) message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") -include_directories(${WEBP_INCLUDE_DIRS}) +endif() if(NOT MINGW) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index d332b45471..b4a597bc4f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -163,7 +163,15 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${WEBP_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) + +if(USE_WEBP) + add_definitions(-DCC_USE_WEBP=1) + include_directories(${WEBP_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${WEBP_LIBRARIES}) +else() + add_definitions(-DCC_USE_WEBP=0) +endif() set_target_properties(cocos2d PROPERTIES From eb0159b2b752e9b79362ed62e0d8c6169d3c3e89 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 13:17:23 +0300 Subject: [PATCH 04/39] Unify usage of chipmunk library * cmake/Modules/FindChipmunk.cmake now can find prebuilt chipmunk libs * follow USE_CHIPMUNK variable (although at the moment cocos can't build without chipmunk) * come cleanups and formatting --- CMakeLists.txt | 16 +++++++++------- cmake/Modules/FindChipmunk.cmake | 23 +++++++++++++++++++++++ cocos/CMakeLists.txt | 12 +++++++----- extensions/CMakeLists.txt | 13 ------------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 552ecf35ec..bdbff7c1af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,11 +168,9 @@ include_directories( # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - find_package(GLFW3 REQUIRED) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) - endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms @@ -182,16 +180,21 @@ include_directories(${FREETYPE_INCLUDE_DIRS}) # WebP required if used if(USE_WEBP) -find_package(WebP REQUIRED) -message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") -endif() + find_package(WebP REQUIRED) + message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") +endif(USE_WEBP) + +if(USE_CHIPMUNK) + find_package(Chipmunk REQUIRED) + message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") + add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +endif(USE_CHIPMUNK) if(NOT MINGW) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 - ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} @@ -208,7 +211,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index 31fc02f489..b194f7ed7f 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -27,6 +27,29 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +if(USE_PREBUILT_LIBS) + find_path(CHIPMUNK_INCLUDE_DIR chipmunk.h + PATH_SUFFIXES + include/chipmunk + include + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + NO_DEFAULT_PATH + ) + find_library(CHIPMUNK_LIBRARY + NAMES chipmunk libchipmunk + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT CHIPMUNK_INCLUDE_DIR OR NOT CHIPMUNK_LIBRARY) + unset(CHIPMUNK_INCLUDE_DIR CACHE) + unset(CHIPMUNK_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(CHIPMUNK_INCLUDE_DIR chipmunk.h HINTS ENV CHIPMUNK_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index b4a597bc4f..0a31f3552c 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -88,13 +88,10 @@ if(MINGW) find_package(ZLIB REQUIRED) - find_package(Chipmunk REQUIRED) - message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${ZLIB_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -163,7 +160,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) @@ -173,6 +170,11 @@ else() add_definitions(-DCC_USE_WEBP=0) endif() +if(USE_CHIPMUNK) + include_directories(${CHIPMUNK_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) +endif() + set_target_properties(cocos2d PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index fd212cba4e..5a2ef4f2a9 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -2,19 +2,6 @@ if(WINDOWS AND NOT BUILD_STATIC) ADD_DEFINITIONS (-D_USREXDLL) endif() -if(WINDOWS) - -# set(PLATFORM_EXTENSIONS_SRC -# ../extensions/proj.win32/Win32InputBox.cpp -# ) - -elseif(MACOSX) - -else() -# set(PLATFORM_EXTENSIONS_SRC -# ../../extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp) -endif() - include_directories( ../../extensions ) From b6dc5244b81d5c74d14041c9c7e67cf3ba53da62 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 13:38:10 +0300 Subject: [PATCH 05/39] Try to fix building without chipmunk, by define CC_USE_PHYSICS=0, but lua bindings still fail. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdbff7c1af..aa39a4fbc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,8 @@ if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +else(USE_CHIPMUNK) + add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) if(NOT MINGW) From 60e5803698c0c2343d60c7bfb5640e5bb2b1b151 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 14:41:19 +0300 Subject: [PATCH 06/39] Improve FindFreetype.cmake for Mac --- cmake/Modules/FindFreetype.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 1bf1dc8830..43188c1562 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -85,6 +85,10 @@ find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h HINTS ENV FREETYPE_DIR PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 @@ -102,6 +106,10 @@ find_path(FREETYPE_INCLUDE_DIR_freetype2 HINTS ENV FREETYPE_DIR PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 @@ -118,6 +126,10 @@ find_library(FREETYPE_LIBRARY ENV FREETYPE_DIR PATH_SUFFIXES lib PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 From 27ef26270cf1570324346cf3a3b828807def66cc Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 14:43:50 +0300 Subject: [PATCH 07/39] Unify TinyXML2 usage. * should be included as simple "tinyxml2.h", but on some files was "tinyxml2/tinyxml2.h", replace this. * Add cmake/Modules/FindTinyXML2.cmake * As tinyxml2 for now has not prebuilt, instead sources included, add their as subdirectory if USE_PREBUILT_LIBS --- CMakeLists.txt | 15 +++- cmake/Modules/FindTinyXML2.cmake | 75 +++++++++++++++++++ cocos/CMakeLists.txt | 3 +- cocos/base/CCUserDefault-android.cpp | 2 +- .../ActionTimeline/CCActionTimelineCache.cpp | 2 +- .../cocostudio/ActionTimeline/CSLoader.cpp | 2 +- .../cocostudio/CCSGUIReader.cpp | 2 +- .../ButtonReader/ButtonReader.cpp | 2 +- .../CheckBoxReader/CheckBoxReader.cpp | 2 +- .../ImageViewReader/ImageViewReader.cpp | 2 +- .../LayoutReader/LayoutReader.cpp | 2 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../LoadingBarReader/LoadingBarReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 2 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../SliderReader/SliderReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 2 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 2 +- .../cocostudio/WidgetReader/WidgetReader.cpp | 2 +- 21 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 cmake/Modules/FindTinyXML2.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index aa39a4fbc5..49cad2ffd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,6 +184,7 @@ if(USE_WEBP) message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") endif(USE_WEBP) +# Chipmunk if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") @@ -192,11 +193,19 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) +# Tinyxml2 +if(USE_PREBUILT_LIBS) + add_subdirectory(external/tinyxml2) + set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) + set(TinyXML2_LIBRARIES tinyxml2) +else() + find_package(TinyXML2) +endif() +message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - - ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} @@ -208,7 +217,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} @@ -226,7 +234,6 @@ if(LINUX OR APPLE) add_subdirectory(external/Box2D) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) -add_subdirectory(external/tinyxml2) add_subdirectory(external/protobuf-lite) endif() diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake new file mode 100644 index 0000000000..694cf2bbac --- /dev/null +++ b/cmake/Modules/FindTinyXML2.cmake @@ -0,0 +1,75 @@ +#.rst: +# FindTinyXML2 +# ------------ +# +# Locate tinyxml2 library +# +# This module defines +# +# :: +# +# TINYXML2_LIBRARIES, the library to link against +# TINYXML2_FOUND, if false, do not try to link to FREETYPE +# TINYXML2_INCLUDE_DIRS, where to find headers. +# + +# Try find glfw for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(TinyXML2_INCLUDE_DIR tinyxml2.h + PATH_SUFFIXES + include/tinyxml2 + include + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + NO_DEFAULT_PATH + ) + find_library(TinyXML2_LIBRARY + NAMES tinyxml2 libtinyxml2 + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT TinyXML2_INCLUDE_DIR OR NOT TinyXML2_LIBRARY) + unset(TinyXML2_INCLUDE_DIR CACHE) + unset(TinyXML2_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +find_path(TinyXML2_INCLUDE_DIR tinyxml2.h + HINTS ENV TinyXML2_DIR + PATH_SUFFIXES include/tinyxml2 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(TinyXML2_LIBRARY + NAMES tinyxml2 libtinyxml2 + HINTS ENV TinyXML2_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +set(TinyXML2_INCLUDE_DIRS "${TinyXML2_INCLUDE_DIR}") +set(TinyXML2_LIBRARIES "${TinyXML2_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TinyXML2_LIBRARIES TinyXML2_INCLUDE_DIRS) + +mark_as_advanced(TinyXML2_INCLUDE_DIRS TinyXML2_LIBRARIES TinyXML2_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 0a31f3552c..9b39181336 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -160,7 +160,8 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +include_directories(${TinyXML2_INCLUDE_DIRS}) +target_link_libraries(cocos2d box2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) diff --git a/cocos/base/CCUserDefault-android.cpp b/cocos/base/CCUserDefault-android.cpp index c6bc9f9a57..98035c338b 100644 --- a/cocos/base/CCUserDefault-android.cpp +++ b/cocos/base/CCUserDefault-android.cpp @@ -40,7 +40,7 @@ THE SOFTWARE. #ifdef KEEP_COMPATABILITY #include "platform/CCFileUtils.h" -#include "../tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #endif using namespace std; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index cb38bab2fd..a058cd8313 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -32,7 +32,7 @@ THE SOFTWARE. #include "2d/CCSpriteFrame.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 206847d592..8e0f9e3955 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -30,7 +30,7 @@ #include "cocostudio/CocoStudio.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 44fb5bd676..99da2e667f 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -42,7 +42,7 @@ THE SOFTWARE. #include "cocostudio/CocoLoader.h" #include "ui/CocosGUI.h" #include "CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" using namespace cocos2d; using namespace cocos2d::ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 25e09aed32..6112a97509 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIButton.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 5dcf84ada5..4a510b6f19 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -4,7 +4,7 @@ #include "ui/UICheckBox.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index f6b00ba76c..13d50f62b1 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIImageView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 12a48d6dbc..d24b9734bf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -7,7 +7,7 @@ #include "ui/UIPageView.h" #include "ui/UIListView.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index e14384d714..38c3a5a810 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIListView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 63455c819b..250cc41ae5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -4,7 +4,7 @@ #include "ui/UILoadingBar.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index 26ed01b1f6..c2579c0580 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -5,7 +5,7 @@ #include "ui/UILayout.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index f6294757f1..63853255c4 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIScrollView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index dba744e43f..e26eff0450 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -4,7 +4,7 @@ #include "ui/UISlider.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index 3bf7b446e4..a0e4c57ccf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextAtlas.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 81c5a2a4f8..dba1177092 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextBMFont.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 85115bf89d..ee71cf4f6a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextField.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 0c08af624a..1919016c53 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIText.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 757df9e31a..f3ea901303 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -4,7 +4,7 @@ #include "cocostudio/CocoLoader.h" #include "ui/UIButton.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include "../ActionTimeline/CCActionTimeline.h" USING_NS_CC; From 2863b95c613ca9205f2a8b3a69688f229d5f662c Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 17:07:46 +0300 Subject: [PATCH 08/39] Make FindTinyXML2.cmake use included macroses from same directory, as other our Find*.cmake modules --- cmake/Modules/FindTinyXML2.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index 694cf2bbac..e1e8917a9a 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -69,7 +69,7 @@ find_library(TinyXML2_LIBRARY set(TinyXML2_INCLUDE_DIRS "${TinyXML2_INCLUDE_DIR}") set(TinyXML2_LIBRARIES "${TinyXML2_LIBRARY}") -include(FindPackageHandleStandardArgs) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TinyXML2_LIBRARIES TinyXML2_INCLUDE_DIRS) mark_as_advanced(TinyXML2_INCLUDE_DIRS TinyXML2_LIBRARIES TinyXML2_LIBRARY) From 673fdc461de95709bcc17fab67879fbb6f3a63ac Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 17:46:13 +0300 Subject: [PATCH 09/39] Unify Box2D usage and finding (not compilable, may be fix that later...) --- CMakeLists.txt | 18 +++++++++++++++--- cocos/CMakeLists.txt | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49cad2ffd0..88854dd37a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,21 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) +# Box2d +if(USE_BOX2D) + if(USE_PREBUILT_LIBS) + add_subdirectory(external/Box2D) + set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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) +endif(USE_BOX2D) + # Tinyxml2 if(USE_PREBUILT_LIBS) add_subdirectory(external/tinyxml2) @@ -206,7 +221,6 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} @@ -221,7 +235,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} ) @@ -231,7 +244,6 @@ endif() # build for 3rd party libraries if(LINUX OR APPLE) -add_subdirectory(external/Box2D) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) add_subdirectory(external/protobuf-lite) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 9b39181336..c251be5e8b 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -161,7 +161,7 @@ if(LINUX OR MACOSX OR WINDOWS) endif() include_directories(${TinyXML2_INCLUDE_DIRS}) -target_link_libraries(cocos2d box2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) @@ -176,6 +176,11 @@ if(USE_CHIPMUNK) target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) endif() +if(USE_BOX2D) + include_directories(${Box2D_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${Box2D_LIBRARIES}) +endif() + set_target_properties(cocos2d PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" From a3b414f0d5116d7232b6146934013fe6c5bdeea4 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:13:25 +0300 Subject: [PATCH 10/39] Use COCOS_EXTERNAL_DIR in Find*.cmake modules --- CMakeLists.txt | 2 ++ cmake/Modules/FindChipmunk.cmake | 7 +++---- cmake/Modules/FindFreetype.cmake | 13 ++++++------- cmake/Modules/FindGLFW3.cmake | 9 ++++----- cmake/Modules/FindTinyXML2.cmake | 7 +++---- cmake/Modules/FindWebP.cmake | 13 +++++++------ 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88854dd37a..af2395f8db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,8 @@ else() set (BUILD_TYPE SHARED) endif() +set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external) + # Some macro definitions if(WINDOWS) diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index b194f7ed7f..b94834c338 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -32,15 +32,14 @@ if(USE_PREBUILT_LIBS) PATH_SUFFIXES include/chipmunk include - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + PATHS ${COCOS_EXTERNAL_DIR}/chipmunk NO_DEFAULT_PATH ) - find_library(CHIPMUNK_LIBRARY - NAMES chipmunk libchipmunk + find_library(CHIPMUNK_LIBRARY NAMES chipmunk libchipmunk PATH_SUFFIXES prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} prebuilt/${PLATFORM_FOLDER} - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + PATHS ${COCOS_EXTERNAL_DIR}/chipmunk NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 43188c1562..e4cee08134 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -45,20 +45,19 @@ if(USE_PREBUILT_LIBS) find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 + ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER}/freetype2 NO_DEFAULT_PATH ) - find_library(FREETYPE_LIBRARY - NAMES freetype libfreetype freetype219 freetype250 + find_library(FREETYPE_LIBRARY NAMES freetype libfreetype freetype219 freetype250 PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindGLFW3.cmake b/cmake/Modules/FindGLFW3.cmake index 654b4eb9e7..5080a71857 100644 --- a/cmake/Modules/FindGLFW3.cmake +++ b/cmake/Modules/FindGLFW3.cmake @@ -30,14 +30,13 @@ # Try find glfw for our arch in external folder if(USE_PREBUILT_LIBS) find_path(GLFW3_INCLUDE_DIR glfw3.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/glfw3/include/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) - find_library(GLFW3_LIBRARY - NAMES glfw3 libglfw3 lgfw + find_library(GLFW3_LIBRARY NAMES glfw3 libglfw3 lgfw PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${COCOS_EXTERNAL_DIR}/glfw3/prebuilt/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index e1e8917a9a..484c66535e 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -19,15 +19,14 @@ if(USE_PREBUILT_LIBS) PATH_SUFFIXES include/tinyxml2 include - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + PATHS ${COCOS_EXTERNAL_DIR}/tinyxml2 NO_DEFAULT_PATH ) - find_library(TinyXML2_LIBRARY - NAMES tinyxml2 libtinyxml2 + find_library(TinyXML2_LIBRARY NAMES tinyxml2 libtinyxml2 PATH_SUFFIXES prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} prebuilt/${PLATFORM_FOLDER} - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + PATHS ${COCOS_EXTERNAL_DIR}/tinyxml2 NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index e885ffeb6d..8d93dec9f4 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -30,14 +30,15 @@ # Try find WebP for our arch in external folder if(USE_PREBUILT_LIBS) find_path(WEBP_INCLUDE_DIR decode.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/webp NO_DEFAULT_PATH ) - find_library(WEBP_LIBRARY - NAMES webp libwebp - PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER} + find_library(WEBP_LIBRARY NAMES webp libwebp + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/webp NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) From 210d8ec985414b9f82ed539897278a611b233972 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:16:01 +0300 Subject: [PATCH 11/39] Compile Box2D tests only if library used in cocos. --- CMakeLists.txt | 4 +++- tests/cpp-tests/CMakeLists.txt | 20 ++++++++++++++------ tests/cpp-tests/Classes/controller.cpp | 2 ++ tests/cpp-tests/Classes/tests.h | 2 ++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af2395f8db..9627e55ce5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,7 +207,9 @@ if(USE_BOX2D) set(Box2D_LIBRARIES Box2D) endif() message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}") - add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION) + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1) +else() + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0) endif(USE_BOX2D) # Tinyxml2 diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index dac761970a..b470f4f2d6 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -27,11 +27,6 @@ set(TESTS_SRC Classes/ActionsProgressTest/ActionsProgressTest.cpp Classes/ActionsTest/ActionsTest.cpp Classes/BillBoardTest/BillBoardTest.cpp - Classes/Box2DTest/Box2dTest.cpp - Classes/Box2DTestBed/Box2dView.cpp - Classes/Box2DTestBed/GLES-Render.cpp - Classes/Box2DTestBed/Test.cpp - Classes/Box2DTestBed/TestEntries.cpp Classes/BugsTest/Bug-1159.cpp Classes/BugsTest/Bug-1174.cpp Classes/BugsTest/Bug-350.cpp @@ -203,6 +198,20 @@ set(TESTS_SRC ${PLATFORM_SRC} ) +if(USE_CHIPMUNK) + include_directories(${CHIPMUNK_INCLUDE_DIRS}) +endif() + +if(USE_BOX2D) + list(APPEND TESTS_SRC + Classes/Box2DTest/Box2dTest.cpp + Classes/Box2DTestBed/Box2dView.cpp + Classes/Box2DTestBed/GLES-Render.cpp + Classes/Box2DTestBed/Test.cpp + Classes/Box2DTestBed/TestEntries.cpp + ) +endif() + if(LINUX) set(EXTENDED_TESTS_SRC ) @@ -229,7 +238,6 @@ endif() include_directories( Classes - ${CMAKE_SOURCE_DIR}/external/chipmunk/include/chipmunk ${CMAKE_SOURCE_DIR}/cocos/editor-support ) diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index c6776c7797..4748f6d2ec 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -42,8 +42,10 @@ Controller g_aTestNames[] = { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) { "Audio - NewAudioEngine", []() { return new AudioEngineTestScene(); } }, #endif +#if CC_ENABLE_BOX2D_INTEGRATION { "Box2d - Basic", []() { return new Box2DTestScene(); } }, { "Box2d - TestBed", []() { return new Box2dTestBedScene(); } }, +#endif { "Bugs", []() { return new BugsTestScene(); } }, { "Chipmunk", []() { return new ChipmunkAccelTouchTestScene(); } }, { "Click and Move", [](){return new ClickAndMoveTestScene(); } }, diff --git a/tests/cpp-tests/Classes/tests.h b/tests/cpp-tests/Classes/tests.h index ce6f29c882..78db79616e 100644 --- a/tests/cpp-tests/Classes/tests.h +++ b/tests/cpp-tests/Classes/tests.h @@ -30,8 +30,10 @@ #include "SpriteTest/SpriteTest.h" #include "SchedulerTest/SchedulerTest.h" #include "RenderTextureTest/RenderTextureTest.h" +#if CC_ENABLE_BOX2D_INTEGRATION #include "Box2DTest/Box2dTest.h" #include "Box2DTestBed/Box2dView.h" +#endif #include "EffectsAdvancedTest/EffectsAdvancedTest.h" #include "InputTest/MouseTest.h" #include "PerformanceTest/PerformanceTest.h" From 9334f0b5696d33e469304350178ab998601d2373 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:16:39 +0300 Subject: [PATCH 12/39] Add custom FindJPEG.cmake module. --- CMakeLists.txt | 6 ++-- cmake/Modules/FindJPEG.cmake | 69 ++++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 11 +++--- 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 cmake/Modules/FindJPEG.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9627e55ce5..ecedd608c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,10 +222,13 @@ else() endif() message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") +# libjpeg +find_package(JPEG REQUIRED) +message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} @@ -235,7 +238,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindJPEG.cmake b/cmake/Modules/FindJPEG.cmake new file mode 100644 index 0000000000..1fbb90328e --- /dev/null +++ b/cmake/Modules/FindJPEG.cmake @@ -0,0 +1,69 @@ +#.rst: +# FindJPEG +# -------- +# +# Find JPEG +# +# Find the native JPEG includes and library This module defines +# +# :: +# +# JPEG_INCLUDE_DIRS, where to find jpeglib.h, etc. +# JPEG_LIBRARIES, the libraries needed to use JPEG. +# JPEG_FOUND, If false, do not try to use JPEG. +# +# also defined, but not for general use are +# +# :: +# +# JPEG_LIBRARY, where to find the JPEG library. + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(USE_PREBUILT_LIBS) + find_path(JPEG_INCLUDE_DIR jpeglib.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/jpeg + NO_DEFAULT_PATH + ) + find_library(JPEG_LIBRARY NAMES jpeg + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/jpeg + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT JPEG_INCLUDE_DIR OR NOT JPEG_LIBRARY) + unset(JPEG_INCLUDE_DIR CACHE) + unset(JPEG_LIBRARY CACHE) + endif() +endif() + +find_path(JPEG_INCLUDE_DIR jpeglib.h) + +set(JPEG_NAMES ${JPEG_NAMES} jpeg) +find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES} ) + +# handle the QUIETLY and REQUIRED arguments and set JPEG_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR) + +if(JPEG_FOUND) + set(JPEG_INCLUDE_DIRS ${JPEG_INCLUDE_DIR}) + set(JPEG_LIBRARIES ${JPEG_LIBRARY}) +endif() + +mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIRS ) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c251be5e8b..231bbd953f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS z png tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z jpeg png tiff curl + z png tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -163,6 +163,9 @@ endif() include_directories(${TinyXML2_INCLUDE_DIRS}) target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +include_directories(${JPEG_INCLUDE_DIRS}) +target_link_libraries(cocos2d ${JPEG_LIBRARIES}) + if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) include_directories(${WEBP_INCLUDE_DIRS}) From d9337cdbd3756c6f4128ffa3c0403c523ea3b5b5 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 00:21:11 +0300 Subject: [PATCH 13/39] Find libpng and zlib unified way. --- CMakeLists.txt | 8 +- cmake/Modules/FindPNG.cmake | 178 ++++++++++++++++++ cmake/Modules/FindZLIB.cmake | 124 ++++++++++++ .../Modules/SelectLibraryConfigurations.cmake | 81 ++++++++ cocos/CMakeLists.txt | 30 ++- 5 files changed, 410 insertions(+), 11 deletions(-) create mode 100644 cmake/Modules/FindPNG.cmake create mode 100644 cmake/Modules/FindZLIB.cmake create mode 100644 cmake/Modules/SelectLibraryConfigurations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ecedd608c4..f5bdaedc9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,10 +226,15 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") +find_package(ZLIB REQUIRED) +message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") + +find_package(PNG REQUIRED) +message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} @@ -239,7 +244,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindPNG.cmake b/cmake/Modules/FindPNG.cmake new file mode 100644 index 0000000000..53cd8385da --- /dev/null +++ b/cmake/Modules/FindPNG.cmake @@ -0,0 +1,178 @@ +#.rst: +# FindPNG +# ------- +# +# Find the native PNG includes and library +# +# +# +# This module searches libpng, the library for working with PNG images. +# +# It defines the following variables +# +# :: +# +# PNG_INCLUDE_DIRS, where to find png.h, etc. +# PNG_LIBRARIES, the libraries to link against to use PNG. +# PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files. +# PNG_FOUND, If false, do not try to use PNG. +# PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8) +# +# Also defined, but not for general use are +# +# :: +# +# PNG_LIBRARY, where to find the PNG library. +# +# For backward compatiblity the variable PNG_INCLUDE_DIR is also set. +# It has the same value as PNG_INCLUDE_DIRS. +# +# Since PNG depends on the ZLib compression library, none of the above +# will be defined unless ZLib can be found. + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(PNG_FIND_QUIETLY) + set(_FIND_ZLIB_ARG QUIET) +endif() +find_package(ZLIB ${_FIND_ZLIB_ARG}) + +if(USE_PREBUILT_LIBS) + find_path(PNG_PNG_INCLUDE_DIR png.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/png NO_DEFAULT_PATH + ) + find_library(PNG_LIBRARY NAMES png libpng + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/png NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT PNG_PNG_INCLUDE_DIR OR NOT PNG_LIBRARY) + unset(PNG_PNG_INCLUDE_DIR CACHE) + unset(PNG_LIBRARY CACHE) + endif() +endif() + +if(ZLIB_FOUND) + find_path(PNG_PNG_INCLUDE_DIR png.h + HINTS ENV PNG_DIR + PATH_SUFFIXES include/libpng include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + + list(APPEND PNG_NAMES png libpng) + unset(PNG_NAMES_DEBUG) + set(_PNG_VERSION_SUFFIXES 17 16 15 14 12) + if (PNG_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\..*)?$") + string(REGEX REPLACE + "^([0-9]+)\\.([0-9]+).*" "\\1\\2" + _PNG_VERSION_SUFFIX_MIN "${PNG_FIND_VERSION}") + if (PNG_FIND_VERSION_EXACT) + set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN}) + else () + string(REGEX REPLACE + "${_PNG_VERSION_SUFFIX_MIN}.*" "${_PNG_VERSION_SUFFIX_MIN}" + _PNG_VERSION_SUFFIXES "${_PNG_VERSION_SUFFIXES}") + endif () + unset(_PNG_VERSION_SUFFIX_MIN) + endif () + foreach(v IN LISTS _PNG_VERSION_SUFFIXES) + list(APPEND PNG_NAMES png${v} libpng${v}) + list(APPEND PNG_NAMES_DEBUG png${v}d libpng${v}d) + endforeach() + unset(_PNG_VERSION_SUFFIXES) + # For compatiblity with versions prior to this multi-config search, honor + # any PNG_LIBRARY that is already specified and skip the search. + if(NOT PNG_LIBRARY) + find_library(PNG_LIBRARY_RELEASE + NAMES ${PNG_NAMES} + HINTS ENV PNG_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + find_library(PNG_LIBRARY_DEBUG + NAMES ${PNG_NAMES_DEBUG} + HINTS ENV PNG_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + select_library_configurations(PNG) + mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG) + endif() + unset(PNG_NAMES) + unset(PNG_NAMES_DEBUG) + + # Set by select_library_configurations(), but we want the one from + # find_package_handle_standard_args() below. + unset(PNG_FOUND) + + if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR) + # png.h includes zlib.h. Sigh. + set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) + set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity + set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY}) + + if (CYGWIN) + if(BUILD_SHARED_LIBS) + # No need to define PNG_USE_DLL here, because it's default for Cygwin. + else() + set (PNG_DEFINITIONS -DPNG_STATIC) + endif() + endif () + + endif () + + if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h") + file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"") + + string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}") + unset(png_version_str) + endif () +endif() + +# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(PNG + REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR + VERSION_VAR PNG_VERSION_STRING) + +mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY ) diff --git a/cmake/Modules/FindZLIB.cmake b/cmake/Modules/FindZLIB.cmake new file mode 100644 index 0000000000..0e287adc96 --- /dev/null +++ b/cmake/Modules/FindZLIB.cmake @@ -0,0 +1,124 @@ +#.rst: +# FindZLIB +# -------- +# +# Find zlib +# +# Find the native ZLIB includes and library. Once done this will define +# +# :: +# +# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. +# ZLIB_LIBRARIES - List of libraries when using zlib. +# ZLIB_FOUND - True if zlib found. +# +# +# +# :: +# +# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) +# ZLIB_VERSION_MAJOR - The major version of zlib +# ZLIB_VERSION_MINOR - The minor version of zlib +# ZLIB_VERSION_PATCH - The patch version of zlib +# ZLIB_VERSION_TWEAK - The tweak version of zlib +# +# +# +# The following variable are provided for backward compatibility +# +# :: +# +# ZLIB_MAJOR_VERSION - The major version of zlib +# ZLIB_MINOR_VERSION - The minor version of zlib +# ZLIB_PATCH_VERSION - The patch version of zlib +# +# +# +# An includer may set ZLIB_ROOT to a zlib installation root to tell this +# module where to look. + +#============================================================================= +# Copyright 2001-2011 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) + +if(USE_PREBUILT_LIBS) + set(search PATHS ${COCOS_EXTERNAL_DIR}/zlib ${COCOS_EXTERNAL_DIR}/${ARCH_DIR}-specific/zlib NO_DEFAULT_PATH) + find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${search} PATH_SUFFIXES include/${PLATFORM_FOLDER} include) + find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${search} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + prebuilt + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) + unset(ZLIB_INCLUDE_DIR CACHE) + unset(ZLIB_LIBRARY CACHE) + endif() +endif() + +set(_ZLIB_SEARCHES) + +# Search ZLIB_ROOT first if it is set. +if(ZLIB_ROOT) + set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH) + list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT) +endif() + +# Normal search. +set(_ZLIB_SEARCH_NORMAL + PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" + "$ENV{PROGRAMFILES}/zlib" + ) +list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL) + +# Try each search configuration. +foreach(search ${_ZLIB_SEARCHES}) + find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include) + find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib) +endforeach() + +mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) + +if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") + file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") + + string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") + + # only append a TWEAK version if it exists: + set(ZLIB_VERSION_TWEAK "") + if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") + set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") + endif() + + set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") + set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") + set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") +endif() + +# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR + VERSION_VAR ZLIB_VERSION_STRING) + +if(ZLIB_FOUND) + set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) +endif() + diff --git a/cmake/Modules/SelectLibraryConfigurations.cmake b/cmake/Modules/SelectLibraryConfigurations.cmake new file mode 100644 index 0000000000..d7108562b1 --- /dev/null +++ b/cmake/Modules/SelectLibraryConfigurations.cmake @@ -0,0 +1,81 @@ +#.rst: +# SelectLibraryConfigurations +# --------------------------- +# +# +# +# select_library_configurations( basename ) +# +# This macro takes a library base name as an argument, and will choose +# good values for basename_LIBRARY, basename_LIBRARIES, +# basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what +# has been found and set. If only basename_LIBRARY_RELEASE is defined, +# basename_LIBRARY will be set to the release value, and +# basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND. +# If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will +# take the debug value, and basename_LIBRARY_RELEASE will be set to +# basename_LIBRARY_RELEASE-NOTFOUND. +# +# If the generator supports configuration types, then basename_LIBRARY +# and basename_LIBRARIES will be set with debug and optimized flags +# specifying the library to be used for the given configuration. If no +# build type has been set or the generator in use does not support +# configuration types, then basename_LIBRARY and basename_LIBRARIES will +# take only the release value, or the debug value if the release one is +# not set. + +#============================================================================= +# Copyright 2009 Will Dicharry +# Copyright 2005-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro( select_library_configurations basename ) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) ) + # if the generator supports configuration types or CMAKE_BUILD_TYPE + # is set, then set optimized and debug options. + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 231bbd953f..5668d25ea0 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z png tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z png tiff curl + tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -150,7 +150,7 @@ elseif(MACOSX OR APPLE) ) elseif(ANDROID) - set(PLATFORM_SPECIFIC_LIBS GLESv2 log z android) + set(PLATFORM_SPECIFIC_LIBS GLESv2 log android) else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() @@ -160,11 +160,23 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -include_directories(${TinyXML2_INCLUDE_DIRS}) -target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +add_definitions(${PNG_DEFINITIONS}) -include_directories(${JPEG_INCLUDE_DIRS}) -target_link_libraries(cocos2d ${JPEG_LIBRARIES}) +include_directories( + ${ZLIB_INCLUDE_DIRS} + ${JPEG_INCLUDE_DIRS} + ${PNG_INCLUDE_DIRS} + ${TinyXML2_INCLUDE_DIRS} + ) +target_link_libraries(cocos2d + protobuf unzip xxhash + ${ZLIB_LIBRARIES} + ${JPEG_LIBRARIES} + ${PNG_LIBRARIES} + ${TinyXML2_LIBRARIES} + ${FREETYPE_LIBRARIES} + ${PLATFORM_SPECIFIC_LIBS} + ) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) From 1c2fa8714e2f2c2cfd4468360b62fe53a338a2f7 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 12:19:19 +0300 Subject: [PATCH 14/39] Fix building with system installed chipmunk on Mac. We should define CP_USE_CGPOINTS=0, or chipmunk will try use apple defined geometry types that conflicts with cocos types. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5bdaedc9e..ebf9f59c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,10 @@ if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") 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) From 1d629dfe7dd8257f0c192cc247628f0c6ceb065a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 12:47:59 +0300 Subject: [PATCH 15/39] Find libtiff --- CMakeLists.txt | 5 +- cmake/Modules/FindTIFF.cmake | 106 +++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 10 ++-- 3 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 cmake/Modules/FindTIFF.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ebf9f59c2c..3b8d9b358e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,10 +236,12 @@ message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") find_package(PNG REQUIRED) message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") +find_package(TIFF REQUIRED) +message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src @@ -247,7 +249,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindTIFF.cmake b/cmake/Modules/FindTIFF.cmake new file mode 100644 index 0000000000..d9b5954c2e --- /dev/null +++ b/cmake/Modules/FindTIFF.cmake @@ -0,0 +1,106 @@ +#.rst: +# FindTIFF +# -------- +# +# Find TIFF library +# +# Find the native TIFF includes and library This module defines +# +# :: +# +# TIFF_INCLUDE_DIR, where to find tiff.h, etc. +# TIFF_LIBRARIES, libraries to link against to use TIFF. +# TIFF_FOUND, If false, do not try to use TIFF. +# +# also defined, but not for general use are +# +# :: +# +# TIFF_LIBRARY, where to find the TIFF library. + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3) + +if(USE_PREBUILT_LIBS) + find_path(TIFF_INCLUDE_DIR tiff.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/tiff NO_DEFAULT_PATH + ) + find_library(TIFF_LIBRARY NAMES ${TIFF_NAMES} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/tiff NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT TIFF_INCLUDE_DIR OR NOT TIFF_LIBRARY) + unset(TIFF_INCLUDE_DIR CACHE) + unset(TIFF_LIBRARY CACHE) + endif() +endif() + +find_path(TIFF_INCLUDE_DIR tiff.h + HINTS ENV TIFF_DIR + PATH_SUFFIXES include/libtiff include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(TIFF_LIBRARY + NAMES ${TIFF_NAMES} + HINTS ENV TIFF_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + +if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") + file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str + REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*") + + string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" + "\\1" TIFF_VERSION_STRING "${tiff_version_str}") + unset(tiff_version_str) +endif() + +set(TIFF_INCLUDE_DIRS ${TIFF_INCLUDE_DIR}) + +# handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF + REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIRS + VERSION_VAR TIFF_VERSION_STRING + ) + +if(TIFF_FOUND) + set( TIFF_LIBRARIES ${TIFF_LIBRARY} ) +endif() + +mark_as_advanced(TIFF_INCLUDE_DIRS TIFF_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 5668d25ea0..2b02f0f9d4 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS libcurl_imp libwebsockets glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - tiff curl + curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -166,6 +166,7 @@ include_directories( ${ZLIB_INCLUDE_DIRS} ${JPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} + ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} ) target_link_libraries(cocos2d @@ -173,6 +174,7 @@ target_link_libraries(cocos2d ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} + ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} From c7bff5ea9e1efb15266fbbdbae94071db99f0769 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 13:22:54 +0300 Subject: [PATCH 16/39] Find libwebsockets in unified way --- CMakeLists.txt | 3 ++ cmake/Modules/FindWEBSOCKETS.cmake | 68 ++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 ++-- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 cmake/Modules/FindWEBSOCKETS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b8d9b358e..0a5c3f88ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,9 @@ message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") find_package(TIFF REQUIRED) message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") +find_package(WEBSOCKETS REQUIRED) +message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( diff --git a/cmake/Modules/FindWEBSOCKETS.cmake b/cmake/Modules/FindWEBSOCKETS.cmake new file mode 100644 index 0000000000..aab748a5e0 --- /dev/null +++ b/cmake/Modules/FindWEBSOCKETS.cmake @@ -0,0 +1,68 @@ +#.rst: +# FindWEBSOCKETS +# -------- +# +# Find websockets library +# +# :: +# +# WEBSOCKETS_INCLUDE_DIRS, where to find libwebsockets.h. +# WEBSOCKETS_LIBRARIES, the libraries needed to use WEBSOCKETS. +# WEBSOCKETS_FOUND, If false, do not try to use WEBSOCKETS. +# + +if(USE_PREBUILT_LIBS) + find_path(WEBSOCKETS_INCLUDE_DIR libwebsockets.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/websockets + NO_DEFAULT_PATH + ) + find_library(WEBSOCKETS_LIBRARY NAMES websockets libwebsockets + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/websockets + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT WEBSOCKETS_INCLUDE_DIR OR NOT WEBSOCKETS_LIBRARY) + unset(WEBSOCKETS_INCLUDE_DIR CACHE) + unset(WEBSOCKETS_LIBRARY CACHE) + endif() +endif() + +find_path(WEBSOCKETS_INCLUDE_DIR libwebsockets.h + HINTS ENV WEBSOCKETS_DIR + PATH_SUFFIXES include/websockets include/libwebsockets include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(WEBSOCKETS_LIBRARY NAMES websockets libwebsockets + HINTS ENV WEBSOCKETS_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + +set(WEBSOCKETS_INCLUDE_DIRS ${WEBSOCKETS_INCLUDE_DIR}) +set(WEBSOCKETS_LIBRARIES ${WEBSOCKETS_LIBRARY}) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(WEBSOCKETS DEFAULT_MSG WEBSOCKETS_LIBRARIES WEBSOCKETS_INCLUDE_DIRS) + +mark_as_advanced(WEBSOCKETS_LIBRARIES WEBSOCKETS_INCLUDE_DIRS) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2b02f0f9d4..eb08750767 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS curl glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libcurl_imp libwebsockets glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS libcurl_imp glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS curl ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -138,7 +138,6 @@ elseif(MACOSX OR APPLE) set(PLATFORM_SPECIFIC_LIBS curl - websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -168,6 +167,7 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} + ${WEBSOCKETS_INCLUDE_DIRS} ) target_link_libraries(cocos2d protobuf unzip xxhash @@ -176,6 +176,7 @@ target_link_libraries(cocos2d ${PNG_LIBRARIES} ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} + ${WEBSOCKETS_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) From 33786678eb50ccad62408c18c4dcd020762d072e Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 13:55:42 +0300 Subject: [PATCH 17/39] Add finding curl. Fix some leftovers from websockets. --- CMakeLists.txt | 8 ++- cmake/Modules/FindCURL.cmake | 98 ++++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 ++-- cocos/network/HttpClient.cpp | 4 +- 4 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 cmake/Modules/FindCURL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a5c3f88ca..7c1b9cc4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,19 +242,17 @@ message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") find_package(WEBSOCKETS REQUIRED) message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") +find_package(CURL REQUIRED) +message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src ) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} - ) diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake new file mode 100644 index 0000000000..543eafc2f5 --- /dev/null +++ b/cmake/Modules/FindCURL.cmake @@ -0,0 +1,98 @@ +#.rst: +# FindCURL +# -------- +# +# Find curl +# +# Find the native CURL headers and libraries. +# +# :: +# +# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc. +# CURL_LIBRARIES - List of libraries when using curl. +# CURL_FOUND - True if curl found. +# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8) + +#============================================================================= +# Copyright 2006-2009 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(CURL_LIBRARY_NAMES + curl +# Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static +# Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl + ) + +if(USE_PREBUILT_LIBS) + find_path(CURL_INCLUDE_DIR curl/curl.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/curl + NO_DEFAULT_PATH + ) + find_library(CURL_LIBRARY NAMES ${CURL_LIBRARY_NAMES} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/curl + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT CURL_INCLUDE_DIR OR NOT CURL_LIBRARY) + unset(CURL_INCLUDE_DIR CACHE) + unset(CURL_LIBRARY CACHE) + endif() +endif() + +# Look for the header file. +find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) +mark_as_advanced(CURL_INCLUDE_DIR) + +# Look for the library (sorted from most current/relevant entry to least). +find_library(CURL_LIBRARY NAMES + curl + # Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static + # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl +) +mark_as_advanced(CURL_LIBRARY) + +if(CURL_INCLUDE_DIR) + foreach(_curl_version_header curlver.h curl.h) + if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + unset(curl_version_str) + break() + endif() + endforeach() +endif() + +# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) + +if(CURL_FOUND) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) +endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index eb08750767..7da332a7e2 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS curl glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libcurl_imp glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS curl ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,6 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - curl ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -167,6 +166,7 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} ${WEBSOCKETS_INCLUDE_DIRS} ) target_link_libraries(cocos2d @@ -177,6 +177,7 @@ target_link_libraries(cocos2d ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} ${WEBSOCKETS_LIBRARIES} + ${CURL_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/cocos/network/HttpClient.cpp b/cocos/network/HttpClient.cpp index 9bcd92df1c..88e4478665 100644 --- a/cocos/network/HttpClient.cpp +++ b/cocos/network/HttpClient.cpp @@ -32,12 +32,12 @@ #include +#include + #include "base/CCVector.h" #include "base/CCDirector.h" #include "base/CCScheduler.h" -#include "curl/curl.h" - #include "platform/CCFileUtils.h" NS_CC_BEGIN From d224dc0ce75027ebef3c8e8dab8dc94d50d5b850 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 14:12:29 +0300 Subject: [PATCH 18/39] Remove incorrect includes. No sure about to remove comment, because it important, but work in this direction in progress now, so I remove it also. --- CMakeLists.txt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c1b9cc4bf..b251a90307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,20 +154,6 @@ elseif(NOT MINGW) set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) endif() - -# NB -# we need to return these to libraries to their official state rather than -# having our custom cocos2d namespace so that we may use system versions if -# the platform provides them. It is very important that this -# is done before we make prebuilt versions of these two libs - -include_directories( - - ${CMAKE_CURRENT_SOURCE_DIR}/../external/unzip - ${CMAKE_CURRENT_SOURCE_DIR}/../external/xxhash - -) - # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(GLFW3 REQUIRED) From 039005ef131ed7d64c42c56ddd84297ba47e8af1 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 15:29:24 +0300 Subject: [PATCH 19/39] Unify protobuf finding and usage. But disable finding until bug with protobuf versions will be resolved. --- CMakeLists.txt | 32 +++++++++++++++++++++----------- cocos/CMakeLists.txt | 23 ++++++----------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b251a90307..9b8ed7bc02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,7 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) -# Box2d +# Box2d (not prebuilded, exists as source) if(USE_BOX2D) if(USE_PREBUILT_LIBS) add_subdirectory(external/Box2D) @@ -202,7 +202,7 @@ else() add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0) endif(USE_BOX2D) -# Tinyxml2 +# Tinyxml2 (not prebuilded, exists as source) if(USE_PREBUILT_LIBS) add_subdirectory(external/tinyxml2) set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) @@ -231,16 +231,27 @@ message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") find_package(CURL REQUIRED) message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") +# protobuf-lite (not prebuilded, exists as source) +# TODO: for now we can't use upstream protobuf because these files: +# cocos/editor-support/cocostudio/CSParseBinary.pb.h +# cocos/editor-support/cocostudio/CSParseBinary.pb.cc +# was generated by concrete version of protobuf compiler +# and source file not provided. So these files can be +# compiled only with our in-source version of protobuf-lite +## if(USE_PREBUILT_LIBS) + add_subdirectory(external/protobuf-lite) + set(PROTOBUF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) + set(PROTOBUF_LITE_LIBRARIES protobuf) +## else() +## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## endif() +message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") +message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") + + if(NOT MINGW) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src - ) - - link_directories( - ${PLATFORM_LINK_DIR} - ) - + link_directories(${PLATFORM_LINK_DIR}) endif() @@ -248,7 +259,6 @@ endif() if(LINUX OR APPLE) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) -add_subdirectory(external/protobuf-lite) endif() # libcocos2d.a diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 7da332a7e2..2ff9e03d61 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,26 +81,13 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(MINGW) - find_package(Protobuf REQUIRED) - #find_package(MiniZip REQUIRED) - #${MINIZIP_INCLUDE_DIR} - - find_package(ZLIB REQUIRED) - - message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - - include_directories(${ZLIB_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) - -else() +if(NOT MINGW) #todo: provide prebuild versions of minizip for android ios mac and msvc #done: prebuilt version for mingw-w64 (linux distros should have them also) # check for opensuse the buildbot system arch and ubuntu - include_directories( - ../external/unzip) + include_directories( ../external/unzip ) endif() @@ -166,11 +153,12 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} ${WEBSOCKETS_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} + ${PROTOBUF_INCLUDE_DIRS} ) target_link_libraries(cocos2d - protobuf unzip xxhash + unzip xxhash ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} @@ -178,6 +166,7 @@ target_link_libraries(cocos2d ${TinyXML2_LIBRARIES} ${WEBSOCKETS_LIBRARIES} ${CURL_LIBRARIES} + ${PROTOBUF_LITE_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) From f8f37b7bf504bed1693ce47a6000e21a9941561b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 19:09:59 +0300 Subject: [PATCH 20/39] Fix comments and formatting in FindTinyXML2.cmake --- cmake/Modules/FindTinyXML2.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index 484c66535e..7f155bfbea 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -9,11 +9,11 @@ # :: # # TINYXML2_LIBRARIES, the library to link against -# TINYXML2_FOUND, if false, do not try to link to FREETYPE +# TINYXML2_FOUND, if false, do not try to link to tinyxml2 # TINYXML2_INCLUDE_DIRS, where to find headers. # -# Try find glfw for our arch in external folder +# Try find tinyxml for our arch in external folder if(USE_PREBUILT_LIBS) find_path(TinyXML2_INCLUDE_DIR tinyxml2.h PATH_SUFFIXES From e3a0e089ba2c98dfca11b27f10b31b6999a8ba1a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 19:10:45 +0300 Subject: [PATCH 21/39] Add FindFMODEX.cmake and use it on linux to find FMOD Ex library --- CMakeLists.txt | 20 +++------- cmake/Modules/FindFMODEX.cmake | 72 ++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 +---- 3 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 cmake/Modules/FindFMODEX.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b8ed7bc02..fe92223631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,19 +141,17 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -# Specific Link Directories if(LINUX) - set(PLATFORM_LINK_DIR - /usr/local/lib - ${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/fmod/prebuilt/${ARCH_DIR} - ) - set(PLATFORM_FOLDER_ARCH - ${PLATFORM_FOLDER}/${ARCH_DIR} - ) + set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}/${ARCH_DIR}) elseif(NOT MINGW) set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) endif() +if(LINUX) + find_package(FMODEX REQUIRED) + message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") +endif() + # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(GLFW3 REQUIRED) @@ -249,12 +247,6 @@ message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") -if(NOT MINGW) - - link_directories(${PLATFORM_LINK_DIR}) - -endif() - # build for 3rd party libraries if(LINUX OR APPLE) add_subdirectory(external/unzip) diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake new file mode 100644 index 0000000000..7f68ce2d31 --- /dev/null +++ b/cmake/Modules/FindFMODEX.cmake @@ -0,0 +1,72 @@ +#.rst: +# FindFMODEX +# ------------ +# +# Locate FMOD Ex library +# +# This module defines +# +# :: +# +# FMODEX_LIBRARIES, the library to link against +# FMODEX_FOUND, if false, do not try to link to fmodex +# FMODEX_INCLUDE_DIRS, where to find headers. +# + +# Try find fmodex for our arch in external folder +set(_FMOD_COCOS_PATHS + ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/fmod + ${COCOS_EXTERNAL_DIR}/fmod + ) +if(USE_PREBUILT_LIBS) + find_path(FMODEX_INCLUDE_DIR fmod.h + PATH_SUFFIXES include/${ARCH_DIR} include + PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH + ) + find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 + PATH_SUFFIXES prebuilt/${ARCH_DIR} prebuilt + PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT FMODEX_INCLUDE_DIR OR NOT FMODEX_LIBRARY) + unset(FMODEX_INCLUDE_DIR CACHE) + unset(FMODEX_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +find_path(FMODEX_INCLUDE_DIR fmod.h + HINTS ENV FMODEX_DIR + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 + HINTS ENV FMODEX_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +set(FMODEX_INCLUDE_DIRS "${FMODEX_INCLUDE_DIR}") +set(FMODEX_LIBRARIES "${FMODEX_LIBRARY}") + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(FMODEX DEFAULT_MSG FMODEX_LIBRARIES FMODEX_INCLUDE_DIRS) + +mark_as_advanced(FMODEX_INCLUDE_DIR FMODEX_LIBRARY FMODEX_INCLUDE_DIRS FMODEX_LIBRARIES) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2ff9e03d61..052923d5b2 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -99,18 +99,13 @@ endif() add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(FMOD_LIB "fmodex64") -elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(FMOD_LIB "fmodex") -endif() - if(MINGW) set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) elseif(WINDOWS) set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + include_directories(${FMODEX_INCLUDE_DIRS}) + set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From f8c56ebbf911bda89237b6ada781201c18f15456 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 20:00:51 +0300 Subject: [PATCH 22/39] Fix finding fmodex on ArchLinux --- cmake/Modules/FindFMODEX.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake index 7f68ce2d31..d1318e6c03 100644 --- a/cmake/Modules/FindFMODEX.cmake +++ b/cmake/Modules/FindFMODEX.cmake @@ -36,7 +36,7 @@ endif(USE_PREBUILT_LIBS) find_path(FMODEX_INCLUDE_DIR fmod.h HINTS ENV FMODEX_DIR - PATH_SUFFIXES include + PATH_SUFFIXES include/fmodex include PATHS ~/Library/Frameworks /Library/Frameworks From 5dabf5719c93709bb3479d99725e014183e8aead Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 20:08:54 +0300 Subject: [PATCH 23/39] Fix webp searching --- cmake/Modules/FindWebP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index 8d93dec9f4..5c1d378d0b 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -64,7 +64,7 @@ FIND_PATH(WEBP_INCLUDE_DIR decode.h ) FIND_LIBRARY(WEBP_LIBRARY - NAMES WEBP libWEBP + NAMES webp libwebp HINTS ENV WEBP_DIR PATH_SUFFIXES lib From b7521dcbae10311153326b433dcc849eae36bd91 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 21:14:00 +0300 Subject: [PATCH 24/39] Remove unused variables. --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe92223631..8bc628b681 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,12 +141,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -if(LINUX) - set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}/${ARCH_DIR}) -elseif(NOT MINGW) - set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) -endif() - if(LINUX) find_package(FMODEX REQUIRED) message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") From 1e8aeb7fd2766c8a8809a7fa3ca43ca0808299ea Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 22:41:37 +0300 Subject: [PATCH 25/39] Minizip 1. Add cmake module for finding minizip in system 2. Check that system installed minizip recent enough for us 3. As right minizip exists only for MSYS2 (mingw), use our embedded version on all other platforms 4. Correctly include minizip as if it is found from system (make it compatible to current build system, so by default all should stay same) 5. Remove one unused include of unzip.h --- CMakeLists.txt | 22 +++++++- cmake/Modules/FindMINIZIP.cmake | 51 +++++++++++++++++++ cocos/CMakeLists.txt | 14 ++--- cocos/base/ZipUtils.cpp | 7 ++- cocos/platform/CCFileUtils.cpp | 6 ++- cocos/platform/apple/CCFileUtils-apple.mm | 2 - extensions/assets-manager/AssetsManager.cpp | 4 ++ extensions/assets-manager/AssetsManagerEx.cpp | 4 ++ 8 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 cmake/Modules/FindMINIZIP.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc628b681..8c950ec8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,27 @@ message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") +# 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(external/unzip) + set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip) + set(MINIZIP_LIBRARIES unzip) +else() + find_package(MINIZIP REQUIRED) + # double check that we have needed functions + include(CheckLibaryExists) + 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) +endif() +message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") + find_package(PNG REQUIRED) message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") @@ -243,7 +264,6 @@ message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") # build for 3rd party libraries if(LINUX OR APPLE) -add_subdirectory(external/unzip) add_subdirectory(external/xxhash) endif() diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake new file mode 100644 index 0000000000..2d4e83cda7 --- /dev/null +++ b/cmake/Modules/FindMINIZIP.cmake @@ -0,0 +1,51 @@ +#.rst: +# FindMINIZIP +# ------------ +# +# Locate minizip library (from zlib package) +# +# This module defines +# +# :: +# +# MINIZIP_LIBRARIES, the library to link against +# MINIZIP_FOUND, if false, do not try to link to fmodex +# MINIZIP_INCLUDE_DIRS, where to find headers. +# + +find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h + HINTS ENV MINIZIP_DIR + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(MINIZIP_LIBRARY NAMES miniunzip libminiunzip + HINTS ENV MINIZIP_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +set(MINIZIP_INCLUDE_DIRS "${MINIZIP_INCLUDE_DIR}") +set(MINIZIP_LIBRARIES "${MINIZIP_LIBRARY}") + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(MINIZIP DEFAULT_MSG MINIZIP_LIBRARIES MINIZIP_INCLUDE_DIRS) + +mark_as_advanced(MINIZIP_INCLUDE_DIR MINIZIP_LIBRARY) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 052923d5b2..8d6489cdd9 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,16 +81,6 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(NOT MINGW) - - #todo: provide prebuild versions of minizip for android ios mac and msvc - #done: prebuilt version for mingw-w64 (linux distros should have them also) - # check for opensuse the buildbot system arch and ubuntu - - include_directories( ../external/unzip ) - -endif() - #todo: provide prebuild versions of the xx libs for all platforms include_directories( ../external/xxhash @@ -144,6 +134,7 @@ add_definitions(${PNG_DEFINITIONS}) include_directories( ${ZLIB_INCLUDE_DIRS} + ${MINIZIP_INCLUDE_DIRS} ${JPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} @@ -153,8 +144,9 @@ include_directories( ${PROTOBUF_INCLUDE_DIRS} ) target_link_libraries(cocos2d - unzip xxhash + xxhash ${ZLIB_LIBRARIES} + ${MINIZIP_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} ${TIFF_LIBRARIES} diff --git a/cocos/base/ZipUtils.cpp b/cocos/base/ZipUtils.cpp index eb2938dc22..2110643d41 100644 --- a/cocos/base/ZipUtils.cpp +++ b/cocos/base/ZipUtils.cpp @@ -24,7 +24,12 @@ ****************************************************************************/ // FIXME: hack, must be included before ziputils +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif + #include "base/ZipUtils.h" #include @@ -37,7 +42,7 @@ #include // FIXME: Other platforms should use upstream minizip like mingw-w64 -#ifdef __MINGW32__ +#ifdef MINIZIP_FROM_SYSTEM #define unzGoToFirstFile64(A,B,C,D) unzGoToFirstFile2(A,B,C,D, NULL, 0, NULL, 0) #define unzGoToNextFile64(A,B,C,D) unzGoToNextFile2(A,B,C,D, NULL, 0, NULL, 0) #endif diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 1d17d4fca8..e0243183fc 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -34,7 +34,11 @@ THE SOFTWARE. #include "base/ccUtils.h" #include "tinyxml2.h" +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif #include #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) @@ -653,7 +657,7 @@ unsigned char* FileUtils::getFileDataFromZip(const std::string& zipFilePath, con CC_BREAK_IF(!file); // FIXME: Other platforms should use upstream minizip like mingw-w64 - #ifdef __MINGW32__ + #ifdef MINIZIP_FROM_SYSTEM int ret = unzLocateFile(file, filename.c_str(), NULL); #else int ret = unzLocateFile(file, filename.c_str(), 1); diff --git a/cocos/platform/apple/CCFileUtils-apple.mm b/cocos/platform/apple/CCFileUtils-apple.mm index ae81af2b7e..5ebd81f730 100644 --- a/cocos/platform/apple/CCFileUtils-apple.mm +++ b/cocos/platform/apple/CCFileUtils-apple.mm @@ -35,8 +35,6 @@ THE SOFTWARE. #include "deprecated/CCDictionary.h" #include "platform/CCFileUtils.h" #include "platform/CCSAXParser.h" -#include "unzip.h" - NS_CC_BEGIN diff --git a/extensions/assets-manager/AssetsManager.cpp b/extensions/assets-manager/AssetsManager.cpp index d3f57bb3e4..cfdc61fae1 100644 --- a/extensions/assets-manager/AssetsManager.cpp +++ b/extensions/assets-manager/AssetsManager.cpp @@ -41,7 +41,11 @@ #include "base/CCUserDefault.h" #include "platform/CCFileUtils.h" +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif using namespace cocos2d; using namespace std; diff --git a/extensions/assets-manager/AssetsManagerEx.cpp b/extensions/assets-manager/AssetsManagerEx.cpp index c772f9eb14..95d46b029f 100644 --- a/extensions/assets-manager/AssetsManagerEx.cpp +++ b/extensions/assets-manager/AssetsManagerEx.cpp @@ -30,7 +30,11 @@ #include #include +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif using namespace cocos2d; using namespace std; From b5266e95bfdab62b5bd6bdf6ef394159c3cf3bf3 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Mon, 17 Nov 2014 01:42:04 +0300 Subject: [PATCH 26/39] mingw fixes, now project builds with mingw64 and -DUSE_PREBUILT_LIBS=NO (some additional libs hardcoded still) --- CMakeLists.txt | 2 +- cmake/Modules/FindMINIZIP.cmake | 2 +- cocos/CMakeLists.txt | 4 +-- cocos/audio/CMakeLists.txt | 5 ++- cocos/scripting/lua-bindings/CMakeLists.txt | 36 ++++++++++++--------- tests/cpp-empty-test/CMakeLists.txt | 25 +++++--------- tests/cpp-tests/CMakeLists.txt | 17 ++++------ tests/lua-empty-test/project/CMakeLists.txt | 25 ++++++-------- tests/lua-tests/project/CMakeLists.txt | 23 ++++++------- 9 files changed, 62 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c950ec8e6..950500bd44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,7 @@ if(USE_PREBUILT_LIBS OR NOT MINGW) else() find_package(MINIZIP REQUIRED) # double check that we have needed functions - include(CheckLibaryExists) + 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") diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake index 2d4e83cda7..1a00d88fdf 100644 --- a/cmake/Modules/FindMINIZIP.cmake +++ b/cmake/Modules/FindMINIZIP.cmake @@ -27,7 +27,7 @@ find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h /opt ) -find_library(MINIZIP_LIBRARY NAMES miniunzip libminiunzip +find_library(MINIZIP_LIBRARY NAMES minizip libminizip HINTS ENV MINIZIP_DIR PATH_SUFFIXES lib PATHS diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 8d6489cdd9..c8a4e3b11b 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -90,9 +90,9 @@ set(COCOS_SRC cocos2d.cpp add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) if(MINGW) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 winmm mpg123 iconv bz2 ogg vorbis vorbisfile OpenAL32) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libwinmm libiconv) elseif(LINUX) include_directories(${FMODEX_INCLUDE_DIRS}) set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) diff --git a/cocos/audio/CMakeLists.txt b/cocos/audio/CMakeLists.txt index c2e12f8769..38669fd30b 100644 --- a/cocos/audio/CMakeLists.txt +++ b/cocos/audio/CMakeLists.txt @@ -7,7 +7,10 @@ if(WINDOWS) set(COCOS_AUDIO_PLATFORM_SRC audio/win32/SimpleAudioEngine.cpp audio/win32/MciPlayer.cpp - audio/win32/MciPlayer.h + audio/win32/MciPlayer.h + audio/win32/AudioEngine-win32.cpp + audio/win32/AudioCache.cpp + audio/win32/AudioPlayer.cpp ) elseif(LINUX) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 3becd4f99f..61998d6c1a 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -32,25 +32,29 @@ file(GLOB lua_cocos2d_source_files "${cocos_root}/external/xxtea/xxtea.cpp" ) -# luasockets are needed in Linux too, -# but Linux have them disabled for some reason -if(MACOSX) - set(lua_cocos2d_source_files - ${lua_cocos2d_source_files} - ${cocos_root}/external/lua/luasocket/auxiliar.c - ${cocos_root}/external/lua/luasocket/buffer.c - ${cocos_root}/external/lua/luasocket/except.c - ${cocos_root}/external/lua/luasocket/inet.c - ${cocos_root}/external/lua/luasocket/io.c +list(APPEND lua_cocos2d_source_files ${cocos_root}/external/lua/luasocket/luasocket.c - ${cocos_root}/external/lua/luasocket/luasocket_scripts.c - ${cocos_root}/external/lua/luasocket/mime.c - ${cocos_root}/external/lua/luasocket/options.c - ${cocos_root}/external/lua/luasocket/select.c - ${cocos_root}/external/lua/luasocket/serial.c - ${cocos_root}/external/lua/luasocket/tcp.c ${cocos_root}/external/lua/luasocket/timeout.c + ${cocos_root}/external/lua/luasocket/buffer.c + ${cocos_root}/external/lua/luasocket/io.c + ${cocos_root}/external/lua/luasocket/auxiliar.c + ${cocos_root}/external/lua/luasocket/options.c + ${cocos_root}/external/lua/luasocket/inet.c + ${cocos_root}/external/lua/luasocket/except.c + ${cocos_root}/external/lua/luasocket/select.c + ${cocos_root}/external/lua/luasocket/tcp.c ${cocos_root}/external/lua/luasocket/udp.c + ${cocos_root}/external/lua/luasocket/mime.c + ${cocos_root}/external/lua/luasocket/luasocket_scripts.c + ) + +if(WINDOWS) + list(APPEND lua_cocos2d_source_files + ${cocos_root}/external/lua/luasocket/wsocket.c + ) +elseif(UNIX) + list(APPEND lua_cocos2d_source_files + ${cocos_root}/external/lua/luasocket/serial.c ${cocos_root}/external/lua/luasocket/unix.c ${cocos_root}/external/lua/luasocket/usocket.c ) diff --git a/tests/cpp-empty-test/CMakeLists.txt b/tests/cpp-empty-test/CMakeLists.txt index 0fde5bb6bd..fa3f9ab5c9 100644 --- a/tests/cpp-empty-test/CMakeLists.txt +++ b/tests/cpp-empty-test/CMakeLists.txt @@ -1,15 +1,11 @@ set(APP_NAME cpp-empty-test) if(ANDROID) - set(PLATFORM_SRC - proj.android/jni/hellocpp/main.cpp - ) - + set(PLATFORM_SRC proj.android/jni/hellocpp/main.cpp) + set(RES_PREFIX "/Resources") elseif(WINDOWS) - set(PLATFORM_SRC - proj.win32/main.cpp - ) - + set(PLATFORM_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(IOS) set(PLATFORM_SRC proj.ios/main.m @@ -18,19 +14,15 @@ elseif(IOS) ) elseif(MACOSX OR APPLE) - set(PLATFORM_SRC - proj.mac/main.cpp - ) + set(PLATFORM_SRC proj.mac/main.cpp) file(GLOB_RECURSE RES_FILES Resources/*) cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources) list(APPEND PLATFORM_SRC ${RES_FILES}) elseif(LINUX) - set(PLATFORM_SRC - proj.linux/main.cpp - ) - + set(PLATFORM_SRC proj.linux/main.cpp) + set(RES_PREFIX "/Resources") else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) @@ -83,8 +75,7 @@ else() set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") add_custom_command(TARGET ${APP_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove_directory $/Resources - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $${RES_PREFIX} ) endif() diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index b470f4f2d6..6dd51fdcd2 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -1,22 +1,18 @@ set(APP_NAME cpp-tests) if(WIN32) - set(PLATFORM_SRC - proj.win32/main.cpp - ) + set(PLATFORM_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(MACOSX) - set(PLATFORM_SRC - proj.mac/main.cpp - ) + set(PLATFORM_SRC proj.mac/main.cpp) file(GLOB_RECURSE RES_FILES Resources/*) cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources) list(APPEND PLATFORM_SRC ${RES_FILES}) elseif(LINUX) - set(PLATFORM_SRC - proj.linux/main.cpp - ) + set(PLATFORM_SRC proj.linux/main.cpp) + set(RES_PREFIX "/Resources") else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() @@ -263,8 +259,7 @@ else() set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") pre_build(${APP_NAME} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}${RES_PREFIX} ) endif() diff --git a/tests/lua-empty-test/project/CMakeLists.txt b/tests/lua-empty-test/project/CMakeLists.txt index 362fe2df48..399d645dec 100644 --- a/tests/lua-empty-test/project/CMakeLists.txt +++ b/tests/lua-empty-test/project/CMakeLists.txt @@ -1,19 +1,15 @@ set(APP_NAME lua-empty-test) -set(SAMPLE_SRC - Classes/AppDelegate.cpp -) +set(SAMPLE_SRC Classes/AppDelegate.cpp) if(LINUX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.linux/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.linux/main.cpp) + set(RES_PREFIX "/Resources") +elseif(WINDOWS) + list(APPEND SAMPLE_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(MACOSX OR APPLE) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.mac/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.mac/main.cpp) file(GLOB_RECURSE APP_RESOURCES ../res/*) cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res) @@ -50,10 +46,9 @@ else() set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") pre_build(${APP_NAME} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}/Resources/res - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}/Resources/src - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos ) endif() diff --git a/tests/lua-tests/project/CMakeLists.txt b/tests/lua-tests/project/CMakeLists.txt index 96fb6b6b87..75858d3c42 100644 --- a/tests/lua-tests/project/CMakeLists.txt +++ b/tests/lua-tests/project/CMakeLists.txt @@ -7,15 +7,13 @@ set(SAMPLE_SRC ) if(LINUX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.linux/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.linux/main.cpp) + set(RES_PREFIX "/Resources") +elseif(WINDOWS) + list(APPEND SAMPLE_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(MACOSX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.ios_mac/mac/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.ios_mac/mac/main.cpp) file(GLOB_RECURSE APP_RESOURCES ../res/*) cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res) @@ -55,11 +53,10 @@ else() set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") pre_build(${APP_NAME} - COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}/Resources/res - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}/Resources/src - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}/Resources/res + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res ) endif() From 731e982b2e1054383ec25567d24352cc2a924364 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Mon, 17 Nov 2014 23:44:16 +0300 Subject: [PATCH 27/39] Find OpenGL, GLEW and winmm library, improve finding of curl (use pkg-config first, this teoretically can find also dependant libs). --- CMakeLists.txt | 18 +++++++-- cmake/Modules/FindCURL.cmake | 74 ++++++++++++++++++++---------------- cocos/CMakeLists.txt | 28 +++++++++----- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 950500bd44..dea1862991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,10 +112,8 @@ else() endif() if(MINGW) - add_definitions(-DGLEW_STATIC) + #add_definitions(-DGLEW_STATIC) add_definitions(-D__SSIZE_T) - set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lws2_32") - set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lws2_32") if(CLANG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions ") @@ -148,9 +146,23 @@ endif() # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) + find_package(OpenGL REQUIRED) + set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) # fix inconsistency + message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") + + if(LINUX OR WINDOWS) + find_package(GLEW REQUIRED) + message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") + endif() + find_package(GLFW3 REQUIRED) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) + + if(WINDOWS) + find_library(WINMM_LIBRARIES winmm) + message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") + endif() endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake index 543eafc2f5..4d3068737e 100644 --- a/cmake/Modules/FindCURL.cmake +++ b/cmake/Modules/FindCURL.cmake @@ -57,42 +57,50 @@ if(USE_PREBUILT_LIBS) endif() endif() -# Look for the header file. -find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) -mark_as_advanced(CURL_INCLUDE_DIR) +find_package(PkgConfig) +if(PKG_CONFIG_FOUND) + pkg_search_module(CURL QUIET libcurl) +endif() -# Look for the library (sorted from most current/relevant entry to least). -find_library(CURL_LIBRARY NAMES - curl - # Windows MSVC prebuilts: - curllib - libcurl_imp - curllib_static - # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): - libcurl -) -mark_as_advanced(CURL_LIBRARY) +if(NOT CURL_FOUND) -if(CURL_INCLUDE_DIR) - foreach(_curl_version_header curlver.h curl.h) - if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") - file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + # Look for the header file. + find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) + mark_as_advanced(CURL_INCLUDE_DIR) - string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") - unset(curl_version_str) - break() + # Look for the library (sorted from most current/relevant entry to least). + find_library(CURL_LIBRARY NAMES + curl + # Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static + # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl + ) + mark_as_advanced(CURL_LIBRARY) + + if(CURL_INCLUDE_DIR) + foreach(_curl_version_header curlver.h curl.h) + if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + unset(curl_version_str) + break() + endif() + endforeach() endif() - endforeach() + + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) + + if(CURL_FOUND) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) + endif() + endif() -# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if -# all listed variables are TRUE -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL - REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR - VERSION_VAR CURL_VERSION_STRING) - -if(CURL_FOUND) - set(CURL_LIBRARIES ${CURL_LIBRARY}) - set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) -endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c8a4e3b11b..2399bedf23 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -89,13 +89,22 @@ set(COCOS_SRC cocos2d.cpp add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) -if(MINGW) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 winmm mpg123 iconv bz2 ogg vorbis vorbisfile OpenAL32) -elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libwinmm libiconv) +set(PLATFORM_SPECIFIC_LIBS) +if(WINDOWS) + foreach(_pkg OPENGL GLEW GLFW3 WINMM) + include_directories(${${_pkg}_INCLUDE_DIRS}) + list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + endforeach() + if(MINGW) + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 mpg123 bz2 ogg vorbis vorbisfile OpenAL32) + endif() elseif(LINUX) + foreach(_pkg OPENGL GLEW GLFW3 FMODEX) + include_directories(${${_pkg}_INCLUDE_DIRS}) + list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + endforeach() include_directories(${FMODEX_INCLUDE_DIRS}) - set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) + list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -125,11 +134,6 @@ else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() -# Add GLFW3 for desktop platforms -if(LINUX OR MACOSX OR WINDOWS) - list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) -endif() - add_definitions(${PNG_DEFINITIONS}) include_directories( @@ -158,6 +162,10 @@ target_link_libraries(cocos2d ${PLATFORM_SPECIFIC_LIBS} ) +if(CURL_LIBRARY_DIRS) + link_directories(${CURL_LIBRARY_DIRS}) +endif() + if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) include_directories(${WEBP_INCLUDE_DIRS}) From 95e005d785bc96162b233dc0243c2c354c62709b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 01:46:41 +0300 Subject: [PATCH 28/39] Find vorbis, mpg123 and OpenAL libs in unified way. Test another way to customize our prebuilt paths... Cleanups. --- CMakeLists.txt | 25 +++++++++++++++++++++++++ cmake/Modules/FindMPG123.cmake | 17 +++++++++++++++++ cmake/Modules/FindOgg.cmake | 20 ++++++++++++++++++++ cmake/Modules/FindVorbis.cmake | 29 +++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 7 ++----- 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 cmake/Modules/FindMPG123.cmake create mode 100644 cmake/Modules/FindOgg.cmake create mode 100644 cmake/Modules/FindVorbis.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dea1862991..8b6b1ea23a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,6 +162,31 @@ if(LINUX OR MACOSX OR WINDOWS) if(WINDOWS) find_library(WINMM_LIBRARIES winmm) message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") + + if(USE_PREBUILT_LIBS) + set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) + list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) + list(APPEND CMAKE_LIBRARY_PATH ${VORBIS_PREBUILT_ROOT}/prebuilt) + endif() + find_package(Vorbis REQUIRED) + message(STATUS "Vorbis include dirs: ${VORBIS_INCLUDE_DIRS}") + + if(USE_PREBUILT_LIBS) + list(APPEND CMAKE_INCLUDE_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/include) + list(APPEND CMAKE_LIBRARY_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt) + endif() + find_package(MPG123 REQUIRED) + message(STATUS "MPG123 include dirs: ${MPG123_INCLUDE_DIRS}") + + if(USE_PREBUILT_LIBS) + set(OPENAL_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OpenalSoft) + list(APPEND CMAKE_INCLUDE_PATH ${OPENAL_PREBUILT_ROOT}) + list(APPEND CMAKE_LIBRARY_PATH ${OPENAL_PREBUILT_ROOT}/prebuilt) + endif() + find_package(OpenAL REQUIRED) + set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) + set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) diff --git a/cmake/Modules/FindMPG123.cmake b/cmake/Modules/FindMPG123.cmake new file mode 100644 index 0000000000..61e450a2c2 --- /dev/null +++ b/cmake/Modules/FindMPG123.cmake @@ -0,0 +1,17 @@ +# - Find mpg123 +# Find the native mpg123 includes and libraries +# +# MPG123_INCLUDE_DIRS - where to find mpg123.h, etc. +# MPG123_LIBRARIES - List of libraries when using mpg123. +# MPG123_FOUND - True if mpg123 found. + +find_path(MPG123_INCLUDE_DIR mpg123.h) +find_library(MPG123_LIBRARY NAMES mpg123 libmpg123) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MPG123 DEFAULT_MSG MPG123_INCLUDE_DIR MPG123_LIBRARY) + +set(MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR}) +set(MPG123_LIBRARIES ${MPG123_LIBRARY}) + +mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY) diff --git a/cmake/Modules/FindOgg.cmake b/cmake/Modules/FindOgg.cmake new file mode 100644 index 0000000000..a3c06d2546 --- /dev/null +++ b/cmake/Modules/FindOgg.cmake @@ -0,0 +1,20 @@ +# - Find ogg +# Find the native ogg includes and libraries +# +# OGG_INCLUDE_DIRS - where to find ogg.h, etc. +# OGG_LIBRARIES - List of libraries when using ogg. +# OGG_FOUND - True if ogg found. + +find_path(OGG_INCLUDE_DIR ogg/ogg.h) +# MSVC built ogg may be named ogg_static. +# The provided project files name the library with the lib prefix. +find_library(OGG_LIBRARY NAMES ogg ogg_static libogg libogg_static) +# Handle the QUIETLY and REQUIRED arguments and set OGG_FOUND +# to TRUE if all listed variables are TRUE. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OGG DEFAULT_MSG OGG_INCLUDE_DIR OGG_LIBRARY) + +set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR}) +set(OGG_LIBRARIES ${OGG_LIBRARY}) + +mark_as_advanced(OGG_INCLUDE_DIR OGG_LIBRARY) diff --git a/cmake/Modules/FindVorbis.cmake b/cmake/Modules/FindVorbis.cmake new file mode 100644 index 0000000000..163dda6fa6 --- /dev/null +++ b/cmake/Modules/FindVorbis.cmake @@ -0,0 +1,29 @@ +# - Find vorbis +# Find the native vorbis includes and libraries +# +# VORBIS_INCLUDE_DIRS - where to find vorbis.h, etc. +# VORBIS_LIBRARIES - List of libraries when using vorbis(file). +# VORBIS_FOUND - True if vorbis found. + +find_package(Ogg) +if(OGG_FOUND) + find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h) + # MSVC built vorbis may be named vorbis_static + # The provided project files name the library with the lib prefix. + find_library(VORBIS_LIBRARY NAMES vorbis vorbis_static libvorbis libvorbis_static) + find_library(VORBISFILE_LIBRARY NAMES vorbisfile vorbisfile_static libvorbisfile libvorbisfile_static) + # Handle the QUIETLY and REQUIRED arguments and set VORBIS_FOUND + # to TRUE if all listed variables are TRUE. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(VORBIS DEFAULT_MSG VORBIS_INCLUDE_DIR VORBIS_LIBRARY VORBISFILE_LIBRARY) +endif(OGG_FOUND) + +if(VORBIS_FOUND) + set(VORBIS_INCLUDE_DIRS ${VORBIS_INCLUDE_DIR}) + set(VORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) +else(VORBIS_FOUND) + set(VORBIS_INCLUDE_DIRS) + set(VORBIS_LIBRARIES) +endif(VORBIS_FOUND) + +mark_as_advanced(VORBIS_INCLUDE_DIR VORBIS_LIBRARY VORBISFILE_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2399bedf23..1c956c18a0 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -91,19 +91,16 @@ add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) - foreach(_pkg OPENGL GLEW GLFW3 WINMM) + foreach(_pkg OPENGL GLEW GLFW3 WINMM VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - if(MINGW) - list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 mpg123 bz2 ogg vorbis vorbisfile OpenAL32) - endif() + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 bz2) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - include_directories(${FMODEX_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From 28d7279cb03671ce51de6a0e373efedfa511115b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 10:06:45 +0300 Subject: [PATCH 29/39] remove unnneded includes and declarations --- cocos/audio/CMakeLists.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/cocos/audio/CMakeLists.txt b/cocos/audio/CMakeLists.txt index 38669fd30b..27437db0d4 100644 --- a/cocos/audio/CMakeLists.txt +++ b/cocos/audio/CMakeLists.txt @@ -21,8 +21,6 @@ elseif(LINUX) audio/linux/AudioPlayer.h ) - include_directories( ../external/linux-specific/fmod/include/${ARCH_DIR} ) - elseif(MACOSX) # split it in _C and non C # because C files needs to be compiled with C compiler and not C++ @@ -48,16 +46,3 @@ elseif(MACOSX) endif() list(APPEND COCOS_AUDIO_SRC ${COCOS_AUDIO_PLATFORM_SRC}) - -if(LINUX) - if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - set(FMOD_LIB "fmodex64") - else() - set(FMOD_LIB "fmodex") - endif() - set(AUDIO_LIB ${FMOD_LIB}) -elseif(WINDOWS) - set(AUDIO_LIB Winmm) -endif() - -include_directories( audio/include ) From d200bdcca082713359543697194ba2432c62c7da Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 10:07:11 +0300 Subject: [PATCH 30/39] fix Winmm linking --- CMakeLists.txt | 3 --- cocos/CMakeLists.txt | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6b1ea23a..5c69f902eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,9 +160,6 @@ if(LINUX OR MACOSX OR WINDOWS) include_directories(${GLFW3_INCLUDE_DIRS}) if(WINDOWS) - find_library(WINMM_LIBRARIES winmm) - message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") - if(USE_PREBUILT_LIBS) set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 1c956c18a0..e186bbb441 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -46,6 +46,7 @@ include(deprecated/CMakeLists.txt) include(ui/CMakeLists.txt) include(network/CMakeLists.txt) include(audio/CMakeLists.txt) +include_directories(audio/include) include(storage/CMakeLists.txt) if(BUILD_EDITOR_COCOSBUILDER) @@ -91,11 +92,11 @@ add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) - foreach(_pkg OPENGL GLEW GLFW3 WINMM VORBIS MPG123 OPENAL) + foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 bz2) + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) include_directories(${${_pkg}_INCLUDE_DIRS}) From ba2f74e76c48eb9e0b9e0d81822dbe46aa4eb4c5 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 17:27:43 +0300 Subject: [PATCH 31/39] Fix OpenAL include paths, cmake search include paths for case, when openal includes as "#include " --- CMakeLists.txt | 2 ++ cocos/CMakeLists.txt | 3 +++ cocos/audio/openal/OpenALDecoder.h | 4 ++++ cocos/audio/openal/SimpleAudioEngineOpenAL.cpp | 6 ++++++ cocos/audio/win32/AudioCache.h | 6 +++++- cocos/audio/win32/AudioPlayer.h | 6 +++++- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c69f902eb..6187200ad6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,8 @@ if(LINUX OR MACOSX OR WINDOWS) find_package(OpenAL REQUIRED) set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + # because FindOpenAL.cmake set include dir for '#include ' for portability (not for '#include ' + set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES") message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index e186bbb441..cc8755988d 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -95,6 +95,9 @@ if(WINDOWS) foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + if(${_pkg}_DEFINITIONS) + add_definitions(${${_pkg}_DEFINITIONS}) + endif() endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) diff --git a/cocos/audio/openal/OpenALDecoder.h b/cocos/audio/openal/OpenALDecoder.h index aa4d00499b..b97a96be55 100644 --- a/cocos/audio/openal/OpenALDecoder.h +++ b/cocos/audio/openal/OpenALDecoder.h @@ -4,7 +4,11 @@ #include #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else #include +#endif #include "cocos2d.h" #if CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN diff --git a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp index 31872e5ec7..16d95c1412 100644 --- a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp +++ b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp @@ -30,9 +30,15 @@ THE SOFTWARE. #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#include +#include +#else #include #include #include +#endif #include "OpenALDecoder.h" #ifdef ENABLE_MPG123 diff --git a/cocos/audio/win32/AudioCache.h b/cocos/audio/win32/AudioCache.h index 6f7c8bb984..9d27d7abd8 100644 --- a/cocos/audio/win32/AudioCache.h +++ b/cocos/audio/win32/AudioCache.h @@ -31,8 +31,12 @@ #include #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else +#include +#endif #include "CCPlatformMacros.h" -#include "AL/al.h" #define QUEUEBUFFER_NUM 3 #define QUEUEBUFFER_TIME_STEP 0.1f diff --git a/cocos/audio/win32/AudioPlayer.h b/cocos/audio/win32/AudioPlayer.h index 8ae2019e6a..7c20ff3701 100644 --- a/cocos/audio/win32/AudioPlayer.h +++ b/cocos/audio/win32/AudioPlayer.h @@ -31,7 +31,11 @@ #include #include #include -#include "AL/al.h" +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else +#include +#endif #include "CCPlatformMacros.h" NS_CC_BEGIN From b0a6cf1182075ae5b5733a7899cd77bbe90ffb4f Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 17:48:54 +0300 Subject: [PATCH 32/39] Use standard cmake control variable to control static or dynamic build BUILD_SHARED_LIBS --- CMakeLists.txt | 14 ++++---------- cocos/3d/CMakeLists.txt | 2 +- cocos/CMakeLists.txt | 6 +----- cocos/editor-support/cocostudio/CMakeLists.txt | 2 +- cocos/ui/CMakeLists.txt | 2 +- extensions/CMakeLists.txt | 2 +- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6187200ad6..48c23796f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ endif() option(USE_CHIPMUNK "Use chipmunk for physics library" ON) option(USE_BOX2D "Use box2d for physics library" OFF) option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT}) -option(BUILD_STATIC "Build static libraries" ON) +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(DEBUG_MODE "Debug or release?" ON) option(BUILD_EXTENSIONS "Build extension library" ON) option(BUILD_EDITOR_SPINE "Build editor support for spine" ON) @@ -78,21 +78,15 @@ else() endif() endif(MSVC) -if(BUILD_STATIC) - set (BUILD_TYPE STATIC) -else() - set (BUILD_TYPE SHARED) -endif() - set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external) # Some macro definitions if(WINDOWS) - if(BUILD_STATIC) - ADD_DEFINITIONS (-DCC_STATIC) - else() + 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) diff --git a/cocos/3d/CMakeLists.txt b/cocos/3d/CMakeLists.txt index ce58d57fbb..0e35a5a63e 100644 --- a/cocos/3d/CMakeLists.txt +++ b/cocos/3d/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USE3DDLL) endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index cc8755988d..edd6ea4c6f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -31,10 +31,6 @@ if(WINDOWS) ADD_DEFINITIONS(-DUNICODE -D_UNICODE) endif() -if(WINDOWS AND NOT BUILD_STATIC) - ADD_DEFINITIONS (-D_USRDLL) -endif() - include(2d/CMakeLists.txt) include(3d/CMakeLists.txt) include(platform/CMakeLists.txt) @@ -88,7 +84,7 @@ set(COCOS_SRC cocos2d.cpp ../external/xxtea) -add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) +add_library(cocos2d ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 6dd775e1fd..51a34f89a6 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USRSTUDIODLL) endif() diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index 696a83295a..42f2cde9a8 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USEGUIDLL) endif() diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 5a2ef4f2a9..17f7b95a95 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USREXDLL) endif() From fe25c860cb240c3d353de7b9005b97e0fee3a0a2 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 00:27:25 +0300 Subject: [PATCH 33/39] Fixes for freetype, protobuf and more unifications. Also it case of static library in some find* modules we try to use pkg-config first, it is chance to get dependency info --- CMakeLists.txt | 6 +-- cmake/Modules/CocosBuildHelpers.cmake | 68 +++++++++++++++++++++++++++ cmake/Modules/FindFreetype.cmake | 10 +++- cmake/Modules/FindMINIZIP.cmake | 9 ++++ cocos/CMakeLists.txt | 52 ++++---------------- 5 files changed, 98 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48c23796f5..5960f16f94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,6 @@ endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") -include_directories(${FREETYPE_INCLUDE_DIRS}) # WebP required if used if(USE_WEBP) @@ -283,13 +282,14 @@ message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") # compiled only with our in-source version of protobuf-lite ## if(USE_PREBUILT_LIBS) add_subdirectory(external/protobuf-lite) - set(PROTOBUF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) + set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) set(PROTOBUF_LITE_LIBRARIES protobuf) ## else() ## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) ## endif() message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") -message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") +message(STATUS "Protobuf include dirs: ${PROTOBUF_LITE_INCLUDE_DIRS}") # build for 3rd party libraries diff --git a/cmake/Modules/CocosBuildHelpers.cmake b/cmake/Modules/CocosBuildHelpers.cmake index c90ed82c08..2cd2aea9d1 100644 --- a/cmake/Modules/CocosBuildHelpers.cmake +++ b/cmake/Modules/CocosBuildHelpers.cmake @@ -36,6 +36,74 @@ function(cocos_mark_resources) endforeach() endfunction() +# cocos_use_pkg(pkg) function. +# This function applies standard package variables (after find_package(pkg) call) to current scope +# Recognized variables: _INCLUDE_DIRS, _LIBRARIES, _LIBRARY_DIRS +# Also if BUILD_SHARED_LIBS variable off, it is try to use _STATIC_* vars before +function(cocos_use_pkg target pkg) + set(prefix ${pkg}) + if(NOT BUILD_SHARED_LIBS) + set(prefix_static ${pkg}_STATIC) + else() + set(prefix_static) + endif() + + set(_include_dirs) + if(prefix_static AND ${prefix_static}_INCLUDE_DIRS) + set(_include_dirs ${${prefix_static}_INCLUDE_DIRS}) + endif() + if(NOT _include_dirs) + set(_include_dirs ${${prefix}_INCLUDE_DIRS}) + endif() + if(NOT _include_dirs) + # backward compat with old package-find scripts + set(_include_dirs ${${prefix}_INCLUDE_DIR}) + endif() + if(_include_dirs) + include_directories(${_include_dirs}) + message(STATUS "${pkg} add to include_dirs: ${_include_dirs}") + endif() + + set(_library_dirs) + if(prefix_static AND ${prefix_static}_LIBRARY_DIRS) + set(_library_dirs ${${prefix_static}_LIBRARY_DIRS}) + endif() + if(NOT _library_dirs) + set(_library_dirs ${${prefix}_LIBRARY_DIRS}) + endif() + if(_library_dirs) + link_directories(${_library_dirs}) + message(STATUS "${pkg} add to link_dirs: ${_library_dirs}") + endif() + + set(_libs) + if(prefix_static AND ${prefix_static}_LIBRARIES) + set(_libs ${${prefix_static}_LIBRARIES}) + endif() + if(NOT _libs) + set(_libs ${${prefix}_LIBRARIES}) + endif() + if(NOT _libs) + set(_libs ${${prefix}_LIBRARY}) + endif() + if(_libs) + target_link_libraries(${target} ${_libs}) + message(STATUS "${pkg} libs added to '${target}': ${_libs}") + endif() + + set(_defs) + if(prefix_static AND ${prefix_static}_CFLAGS_OTHER) + set(_defs ${${prefix_static}_CFLAGS_OTHER}) + endif() + if(NOT _defs) + set(_defs ${${prefix}_DEFINITIONS}) + endif() + if(_defs) + add_definitions(${_defs}) + message(STATUS "${pkg} add definitions: ${_defs}") + endif() +endfunction() + #cmake has some strange defaults, this should help us a lot #Please use them everywhere diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index e4cee08134..e6ef8874f5 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -68,6 +68,11 @@ if(USE_PREBUILT_LIBS) endif() endif(USE_PREBUILT_LIBS) +# Try pkg-config first (because it provided deps info) +find_package(PkgConfig) +pkg_search_module(FREETYPE freetype2) +if(NOT FREETYPE_FOUND) + # Ugh, FreeType seems to use some #include trickery which # makes this harder than it should be. It looks like they # put ft2build.h in a common/easier-to-find location which @@ -172,12 +177,15 @@ if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) endforeach() endif() +set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype - REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS + REQUIRED_VARS FREETYPE_LIBRARIES FREETYPE_INCLUDE_DIRS VERSION_VAR FREETYPE_VERSION_STRING) +endif(NOT FREETYPE_FOUND) + mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake index 1a00d88fdf..93efa3595d 100644 --- a/cmake/Modules/FindMINIZIP.cmake +++ b/cmake/Modules/FindMINIZIP.cmake @@ -13,6 +13,15 @@ # MINIZIP_INCLUDE_DIRS, where to find headers. # +# Try pkg-config first +if(NOT MINIZIP_LIBRARY AND NOT MINIZIP_INCLUDE_DIR) + find_package(PkgConfig) + pkg_search_module(MINIZIP minizip) + if(MINIZIP_FOUND) + return() + endif() +endif() + find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h HINTS ENV MINIZIP_DIR PATH_SUFFIXES include diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index edd6ea4c6f..9a358459f1 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -89,17 +89,12 @@ add_library(cocos2d ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) - include_directories(${${_pkg}_INCLUDE_DIRS}) - list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) - if(${_pkg}_DEFINITIONS) - add_definitions(${${_pkg}_DEFINITIONS}) - endif() + cocos_use_pkg(cocos2d ${_pkg}) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) - include_directories(${${_pkg}_INCLUDE_DIRS}) - list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + cocos_use_pkg(cocos2d ${_pkg}) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) @@ -131,54 +126,25 @@ else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() -add_definitions(${PNG_DEFINITIONS}) +foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL PROTOBUF_LITE) + cocos_use_pkg(cocos2d ${pkg}) +endforeach() -include_directories( - ${ZLIB_INCLUDE_DIRS} - ${MINIZIP_INCLUDE_DIRS} - ${JPEG_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${TIFF_INCLUDE_DIRS} - ${TinyXML2_INCLUDE_DIRS} - ${WEBSOCKETS_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} - ${PROTOBUF_INCLUDE_DIRS} - ) -target_link_libraries(cocos2d - xxhash - ${ZLIB_LIBRARIES} - ${MINIZIP_LIBRARIES} - ${JPEG_LIBRARIES} - ${PNG_LIBRARIES} - ${TIFF_LIBRARIES} - ${TinyXML2_LIBRARIES} - ${WEBSOCKETS_LIBRARIES} - ${CURL_LIBRARIES} - ${PROTOBUF_LITE_LIBRARIES} - ${FREETYPE_LIBRARIES} - ${PLATFORM_SPECIFIC_LIBS} - ) - -if(CURL_LIBRARY_DIRS) - link_directories(${CURL_LIBRARY_DIRS}) -endif() +target_link_libraries(cocos2d xxhash ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) - include_directories(${WEBP_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${WEBP_LIBRARIES}) + cocos_use_pkg(cocos2d WEBP) else() add_definitions(-DCC_USE_WEBP=0) endif() if(USE_CHIPMUNK) - include_directories(${CHIPMUNK_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) + cocos_use_pkg(cocos2d CHIPMUNK) endif() if(USE_BOX2D) - include_directories(${Box2D_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${Box2D_LIBRARIES}) + cocos_use_pkg(cocos2d Box2D) endif() set_target_properties(cocos2d From 2bf77c10e8782baac0282b1f521242a43df42585 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 03:28:41 +0300 Subject: [PATCH 34/39] Fix build on mingw again, disable USE_PREBUILT_LIBS with mingw (mingw can not link this libs). Eliminate some Find* modules, we can tune prebuilts without modify their code. --- CMakeLists.txt | 25 +++- cmake/Modules/FindFreetype.cmake | 12 +- cmake/Modules/FindZLIB.cmake | 124 -------------------- cocos/scripting/lua-bindings/CMakeLists.txt | 21 ++-- tests/lua-tests/project/CMakeLists.txt | 4 +- 5 files changed, 45 insertions(+), 141 deletions(-) delete mode 100644 cmake/Modules/FindZLIB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5960f16f94..eac42e7063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,12 @@ message(${BUILDING_STRING}) set(USE_WEBP_DEFAULT ON) if(WINRT OR WP8) - set(USE_WEBP_DEFAULT OFF) + set(USE_WEBP_DEFAULT OFF) +endif() + +set(USE_PREBUILT_LIBS_DEFAULT ON) +if(MINGW) + set(USE_PREBUILT_LIBS_DEFAULT OFF) endif() option(USE_CHIPMUNK "Use chipmunk for physics library" ON) @@ -51,8 +56,11 @@ option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON) option(BUILD_CPP_TESTS "Build TestCpp samples" ON) option(BUILD_LUA_LIBS "Build lua libraries" ON) option(BUILD_LUA_TESTS "Build TestLua samples" ON) +option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT}) -option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON) +if(USE_PREBUILT_LIBS AND MINGW) + message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.") +endif() if(DEBUG_MODE) set(CMAKE_BUILD_TYPE DEBUG) @@ -89,7 +97,7 @@ if(WINDOWS) ADD_DEFINITIONS (-DCC_STATIC) endif() - ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32) + ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32) set(PLATFORM_FOLDER win32) elseif(MACOSX OR APPLE) ADD_DEFINITIONS (-DCC_TARGET_OS_MAC) @@ -145,6 +153,10 @@ if(LINUX OR MACOSX OR WINDOWS) message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") if(LINUX OR WINDOWS) + if(USE_PREBUILT_LIBS AND WINDOWS) + set(GLEW_INCLUDE_DIR ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/include/OGLES) + set(GLEW_LIBRARY ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.lib) + endif() find_package(GLEW REQUIRED) message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") endif() @@ -237,6 +249,13 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") +if(USE_PREBUILT_LIBS) + set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) + #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) + #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) + set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) + set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) +endif() find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index e6ef8874f5..0fe3f3f5b2 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -61,7 +61,11 @@ if(USE_PREBUILT_LIBS) NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT FREETYPE_INCLUDE_DIR_ft2build OR NOT FREETYPE_INCLUDE_DIR_freetype2 OR NOT FREETYPE_LIBRARY) + if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_LIBRARY) + set(FREETYPE_FOUND 1) + set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}) + set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) + else() unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) unset(FREETYPE_LIBRARY CACHE) @@ -69,8 +73,10 @@ if(USE_PREBUILT_LIBS) endif(USE_PREBUILT_LIBS) # Try pkg-config first (because it provided deps info) -find_package(PkgConfig) -pkg_search_module(FREETYPE freetype2) +if(NOT FREETYPE_FOUND) + find_package(PkgConfig) + pkg_search_module(FREETYPE freetype2) +endif() if(NOT FREETYPE_FOUND) # Ugh, FreeType seems to use some #include trickery which diff --git a/cmake/Modules/FindZLIB.cmake b/cmake/Modules/FindZLIB.cmake deleted file mode 100644 index 0e287adc96..0000000000 --- a/cmake/Modules/FindZLIB.cmake +++ /dev/null @@ -1,124 +0,0 @@ -#.rst: -# FindZLIB -# -------- -# -# Find zlib -# -# Find the native ZLIB includes and library. Once done this will define -# -# :: -# -# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. -# ZLIB_LIBRARIES - List of libraries when using zlib. -# ZLIB_FOUND - True if zlib found. -# -# -# -# :: -# -# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) -# ZLIB_VERSION_MAJOR - The major version of zlib -# ZLIB_VERSION_MINOR - The minor version of zlib -# ZLIB_VERSION_PATCH - The patch version of zlib -# ZLIB_VERSION_TWEAK - The tweak version of zlib -# -# -# -# The following variable are provided for backward compatibility -# -# :: -# -# ZLIB_MAJOR_VERSION - The major version of zlib -# ZLIB_MINOR_VERSION - The minor version of zlib -# ZLIB_PATCH_VERSION - The patch version of zlib -# -# -# -# An includer may set ZLIB_ROOT to a zlib installation root to tell this -# module where to look. - -#============================================================================= -# Copyright 2001-2011 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) - -if(USE_PREBUILT_LIBS) - set(search PATHS ${COCOS_EXTERNAL_DIR}/zlib ${COCOS_EXTERNAL_DIR}/${ARCH_DIR}-specific/zlib NO_DEFAULT_PATH) - find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${search} PATH_SUFFIXES include/${PLATFORM_FOLDER} include) - find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${search} - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - prebuilt - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) - unset(ZLIB_INCLUDE_DIR CACHE) - unset(ZLIB_LIBRARY CACHE) - endif() -endif() - -set(_ZLIB_SEARCHES) - -# Search ZLIB_ROOT first if it is set. -if(ZLIB_ROOT) - set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH) - list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT) -endif() - -# Normal search. -set(_ZLIB_SEARCH_NORMAL - PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" - "$ENV{PROGRAMFILES}/zlib" - ) -list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL) - -# Try each search configuration. -foreach(search ${_ZLIB_SEARCHES}) - find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include) - find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib) -endforeach() - -mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) - -if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") - file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") - - string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") - string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") - string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") - set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") - - # only append a TWEAK version if it exists: - set(ZLIB_VERSION_TWEAK "") - if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") - set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") - set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") - endif() - - set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") - set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") - set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") -endif() - -# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if -# all listed variables are TRUE -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR - VERSION_VAR ZLIB_VERSION_STRING) - -if(ZLIB_FOUND) - set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) - set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) -endif() - diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 61998d6c1a..0b1cf50ca8 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -1,4 +1,8 @@ -set(cocos_root ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set(cocos_root ${Cocos2d-X_SOURCE_DIR}) + +if(WINDOWS) + add_definitions(-DLUASOCKET_INET_ATON -DLUASOCKET_INET_PTON) +endif() include_directories( ${cocos_root}/external/lua/tolua @@ -17,13 +21,12 @@ include_directories( ${cocos_root}/cocos/editor-support ${cocos_root}/cocos/platform ${cocos_root}/cocos/audio/include - ${CMAKE_CURRENT_SOURCE_DIR}/manual - ${CMAKE_CURRENT_SOURCE_DIR}/manual/extension - ${CMAKE_CURRENT_SOURCE_DIR}/manual/cocostudio - ${CMAKE_CURRENT_SOURCE_DIR}/manual/ui - ${CMAKE_CURRENT_SOURCE_DIR}/ui - ${CMAKE_CURRENT_SOURCE_DIR}/manual/cocos2d - ${CMAKE_CURRENT_SOURCE_DIR}/auto + manual + manual/extension + manual/cocostudio + manual/ui + manual/cocos2d + auto ) file(GLOB lua_cocos2d_source_files @@ -120,7 +123,7 @@ endif() set(lua_bindings_files ${lua_cocos2d_source_files} ${lua_bindings_manual_files} ${lua_bindings_auto_files}) -add_library(luacocos2d STATIC ${lua_bindings_files}) +add_library(luacocos2d ${lua_bindings_files}) target_link_libraries(luacocos2d cocos2d) set_target_properties(luacocos2d PROPERTIES diff --git a/tests/lua-tests/project/CMakeLists.txt b/tests/lua-tests/project/CMakeLists.txt index 75858d3c42..404e5d2ea9 100644 --- a/tests/lua-tests/project/CMakeLists.txt +++ b/tests/lua-tests/project/CMakeLists.txt @@ -54,8 +54,8 @@ else() pre_build(${APP_NAME} COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/Resources/src + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res ) From 98db27e9293c89c1a810c2d987cc1317a8b69e7f Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 10:57:18 +0300 Subject: [PATCH 35/39] cmake linux fixes: FindFontconfig, find appropriate threads libs --- CMakeLists.txt | 29 +++++++++++++++++++---------- cmake/Modules/FindFontconfig.cmake | 17 +++++++++++++++++ cocos/CMakeLists.txt | 3 +-- 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 cmake/Modules/FindFontconfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eac42e7063..9ac85ce73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,11 +141,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -if(LINUX) - find_package(FMODEX REQUIRED) - message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") -endif() - # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(OpenGL REQUIRED) @@ -165,6 +160,18 @@ if(LINUX OR MACOSX OR WINDOWS) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) + if(LINUX) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + find_package(Threads REQUIRED) + set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + + find_package(FMODEX REQUIRED) + message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") + + find_package(Fontconfig REQUIRED) + message(STATUS "Fontconfig include dirs: ${FONTCONFIG_INCLUDE_DIRS}") + endif() + if(WINDOWS) if(USE_PREBUILT_LIBS) set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) @@ -250,11 +257,13 @@ find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") if(USE_PREBUILT_LIBS) - set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) - #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) - #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) - set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) - set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) + if(WINDOWS) + set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) + #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) + #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) + set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) + set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) + endif() endif() find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") diff --git a/cmake/Modules/FindFontconfig.cmake b/cmake/Modules/FindFontconfig.cmake new file mode 100644 index 0000000000..d5da113c49 --- /dev/null +++ b/cmake/Modules/FindFontconfig.cmake @@ -0,0 +1,17 @@ +# FindFontconfig +# -------------- +# +# Locate Fontconfig library +# + +if(NOT FONTCONFIG_FOUND) + find_package(PkgConfig) + pkg_search_module(FONTCONFIG fontconfig) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Fontconfig + REQUIRED_VARS FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIRS + VERSION_VAR FONTCONFIG_VERSION + ) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 9a358459f1..c200fbe710 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -93,10 +93,9 @@ if(WINDOWS) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) - foreach(_pkg OPENGL GLEW GLFW3 FMODEX) + foreach(_pkg OPENGL GLEW GLFW3 FMODEX FONTCONFIG THREADS) cocos_use_pkg(cocos2d ${_pkg}) endforeach() - list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From 499c670a9b5560832ffdfbac2100c39881fd024c Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 12:05:15 +0300 Subject: [PATCH 36/39] Move prebuilt libraries config to distinct file. Now build system looks more maintanable. I test with mac, going to test with other platforms. * All prebuilt libs config moved to cmake/Modules/CocosUsePrebuiltLibs.cmake * Wrap plain find_package to our cocos_find_package. It will not try to call find_package if USE_PREBUILT_LIBS and _FOUND set to true. * Other small fixes. --- CMakeLists.txt | 100 ++++---------- cmake/Modules/CocosBuildHelpers.cmake | 17 +++ cmake/Modules/CocosUsePrebuiltLibs.cmake | 167 +++++++++++++++++++++++ cmake/Modules/FindCURL.cmake | 20 --- cmake/Modules/FindChipmunk.cmake | 22 --- cmake/Modules/FindFMODEX.cmake | 21 --- cmake/Modules/FindFreetype.cmake | 29 ---- cocos/CMakeLists.txt | 2 + 8 files changed, 211 insertions(+), 167 deletions(-) create mode 100644 cmake/Modules/CocosUsePrebuiltLibs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ac85ce73f..7160321934 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,23 +141,19 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) +if(USE_PREBUILT_LIBS) + include(CocosUsePrebuiltLibs) +endif() + # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - find_package(OpenGL REQUIRED) - set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) # fix inconsistency - message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") + cocos_find_package(OpenGL OPENGL REQUIRED) if(LINUX OR WINDOWS) - if(USE_PREBUILT_LIBS AND WINDOWS) - set(GLEW_INCLUDE_DIR ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/include/OGLES) - set(GLEW_LIBRARY ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.lib) - endif() - find_package(GLEW REQUIRED) - message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") + cocos_find_package(GLEW GLEW REQUIRED) endif() - find_package(GLFW3 REQUIRED) - message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") + cocos_find_package(GLFW3 GLFW3 REQUIRED) include_directories(${GLFW3_INCLUDE_DIRS}) if(LINUX) @@ -165,57 +161,30 @@ if(LINUX OR MACOSX OR WINDOWS) find_package(Threads REQUIRED) set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) - find_package(FMODEX REQUIRED) - message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") - - find_package(Fontconfig REQUIRED) - message(STATUS "Fontconfig include dirs: ${FONTCONFIG_INCLUDE_DIRS}") + cocos_find_package(FMODEX FMODEX REQUIRED) + cocos_find_package(Fontconfig FONTCONFIG REQUIRED) endif() if(WINDOWS) - if(USE_PREBUILT_LIBS) - set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) - list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) - list(APPEND CMAKE_LIBRARY_PATH ${VORBIS_PREBUILT_ROOT}/prebuilt) - endif() - find_package(Vorbis REQUIRED) - message(STATUS "Vorbis include dirs: ${VORBIS_INCLUDE_DIRS}") - - if(USE_PREBUILT_LIBS) - list(APPEND CMAKE_INCLUDE_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/include) - list(APPEND CMAKE_LIBRARY_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt) - endif() - find_package(MPG123 REQUIRED) - message(STATUS "MPG123 include dirs: ${MPG123_INCLUDE_DIRS}") - - if(USE_PREBUILT_LIBS) - set(OPENAL_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OpenalSoft) - list(APPEND CMAKE_INCLUDE_PATH ${OPENAL_PREBUILT_ROOT}) - list(APPEND CMAKE_LIBRARY_PATH ${OPENAL_PREBUILT_ROOT}/prebuilt) - endif() - find_package(OpenAL REQUIRED) - set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) - set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + 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 ' for portability (not for '#include ' set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES") - message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms -find_package(Freetype REQUIRED) -message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") +cocos_find_package(Freetype FREETYPE REQUIRED) # WebP required if used if(USE_WEBP) - find_package(WebP REQUIRED) - message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") + cocos_find_package(WebP WEBP REQUIRED) endif(USE_WEBP) # Chipmunk if(USE_CHIPMUNK) - find_package(Chipmunk REQUIRED) - message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") + 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 @@ -248,25 +217,13 @@ if(USE_PREBUILT_LIBS) set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) set(TinyXML2_LIBRARIES tinyxml2) else() - find_package(TinyXML2) + cocos_find_package(TinyXML2 TinyXML2 REQUIRED) endif() message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") # libjpeg -find_package(JPEG REQUIRED) -message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") - -if(USE_PREBUILT_LIBS) - if(WINDOWS) - set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) - #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) - #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) - set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) - set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) - endif() -endif() -find_package(ZLIB REQUIRED) -message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") +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 @@ -277,8 +234,9 @@ if(USE_PREBUILT_LIBS OR NOT MINGW) add_subdirectory(external/unzip) set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip) set(MINIZIP_LIBRARIES unzip) + message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") else() - find_package(MINIZIP REQUIRED) + cocos_find_package(MINIZIP MINIZIP REQUIRED) # double check that we have needed functions include(CheckLibraryExists) check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2) @@ -287,19 +245,11 @@ else() endif() add_definitions(-DMINIZIP_FROM_SYSTEM) endif() -message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") -find_package(PNG REQUIRED) -message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") - -find_package(TIFF REQUIRED) -message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") - -find_package(WEBSOCKETS REQUIRED) -message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") - -find_package(CURL REQUIRED) -message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") +cocos_find_package(PNG PNG REQUIRED) +cocos_find_package(TIFF TIFF REQUIRED) +cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED) +cocos_find_package(CURL CURL REQUIRED) # protobuf-lite (not prebuilded, exists as source) # TODO: for now we can't use upstream protobuf because these files: @@ -313,7 +263,7 @@ message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) set(PROTOBUF_LITE_LIBRARIES protobuf) ## else() -## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## cocos_find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) ## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) ## endif() message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") diff --git a/cmake/Modules/CocosBuildHelpers.cmake b/cmake/Modules/CocosBuildHelpers.cmake index 2cd2aea9d1..07a8e79f1b 100644 --- a/cmake/Modules/CocosBuildHelpers.cmake +++ b/cmake/Modules/CocosBuildHelpers.cmake @@ -36,6 +36,23 @@ function(cocos_mark_resources) endforeach() endfunction() +# cocos_find_package(pkg args...) +# works same as find_package, but do additional care to properly find +# prebuilt libs for cocos +macro(cocos_find_package pkg_name pkg_prefix) + if(NOT USE_PREBUILT_LIBS OR NOT ${pkg_prefix}_FOUND) + find_package(${pkg_name} ${ARGN}) + endif() + if(NOT ${pkg_prefix}_INCLUDE_DIRS AND ${pkg_prefix}_INCLUDE_DIR) + set(${pkg_prefix}_INCLUDE_DIRS ${${pkg_prefix}_INCLUDE_DIR}) + endif() + if(NOT ${pkg_prefix}_LIBRARIES AND ${pkg_prefix}_LIBRARY) + set(${pkg_prefix}_LIBRARIES ${${pkg_prefix}_LIBRARY}) + endif() + + message(STATUS "${pkg_name} include dirs: ${${pkg_prefix}_INCLUDE_DIRS}") +endmacro() + # cocos_use_pkg(pkg) function. # This function applies standard package variables (after find_package(pkg) call) to current scope # Recognized variables: _INCLUDE_DIRS, _LIBRARIES, _LIBRARY_DIRS diff --git a/cmake/Modules/CocosUsePrebuiltLibs.cmake b/cmake/Modules/CocosUsePrebuiltLibs.cmake new file mode 100644 index 0000000000..1ad3b93899 --- /dev/null +++ b/cmake/Modules/CocosUsePrebuiltLibs.cmake @@ -0,0 +1,167 @@ +# CocosUsePrebuiltLibs - sets external libs variables to link with + +# START CONFIG + +set(_chipmunk_inc chipmunk.h) +set(_chipmunk_inc_paths chipmunk) +set(_chipmunk_libs chipmunk libchipmunk) + +set(_curl_inc curl/curl.h) +set(_curl_libs crypto ssl libeay32 ssleay32 curl libcurl_imp libcurl) + +set(_freetype2_prefix FREETYPE) +set(_freetype2_inc ft2build.h freetype/freetype.h) +set(_freetype2_inc_paths freetype2) +set(_freetype2_libs freetype freetype250) + +set(_jpeg_inc jpeglib.h) +set(_jpeg_libs jpeg libjpeg) + +set(_png_inc png.h) +set(_png_libs png libpng) + +set(_tiff_inc tiff.h) +set(_tiff_libs tiff libtiff) + +set(_webp_inc decode.h) +set(_webp_libs webp libwebp) + +set(_websockets_inc libwebsockets.h) +set(_websockets_libs websockets libwebsockets) + +set(_glfw3_inc glfw3.h) +set(_glfw3_libs glfw3 libglfw3) + +set(_sqlite3_inc sqlite3.h) +set(_sqlite3_libs sqlite3) + +set(_gles_prefix GLEW) +set(_gles_inc glew.h) +set(_gles_inc_paths OGLES) +set(_gles_libs glew32) + +set(_icon_prefix ICONV) +set(_icon_inc iconv.h) +set(_icon_libs libiconv) + +set(_MP3Decoder_prefix MPG123) +set(_MP3Decoder_inc mpg123.h) +set(_MP3Decoder_libs libmpg123) + +set(_OggDecoder_prefix VORBIS) +set(_OggDecoder_inc ogg/ogg.h) +set(_OggDecoder_libs libogg libvorbis libvorbisfile) + +set(_OpenalSoft_prefix OPENAL) +set(_OpenalSoft_inc al.h) +set(_OpenalSoft_inc_paths AL) +set(_OpenalSoft_libs OpenAL32) + +set(_zlib_inc zlib.h) +set(_zlib_libs libzlib) + +set(_fmod_inc fmod.h) +set(_fmod_libs fmodex fmodexL) + +set(all_prebuilt_libs + chipmunk + curl + freetype2 + jpeg + png + tiff + webp + websockets +) + + +if(MACOSX) + list(APPEND all_prebuilt_libs glfw3) +endif() + +# We use MSVC instead of WINDOWS because it can be mingw that can't use our prebuilt libs +if(MSVC) + list(APPEND all_prebuilt_libs glfw3 sqlite3 gles icon MP3Decoder OggDecoder OpenalSoft zlib) +endif() + +if(LINUX) + list(APPEND all_prebuilt_libs fmod) +endif() + +# END CONFIG + +foreach(_lib ${all_prebuilt_libs}) + if(_${_lib}_prefix) + set(_prefix ${_${_lib}_prefix}) + else() + # auto-prefix is uppercased name + string(TOUPPER ${_lib} _prefix) + endif() + + set(roots + ${COCOS_EXTERNAL_DIR}/${_lib} + ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/${_lib} + ) + foreach(_root ${roots}) + if(EXISTS ${_root}) + set(include_dir_candidates + ${_root}/include + ${_root}/include/${ARCH_DIR} + ${_root}/include/${PLATFORM_FOLDER} + ${_root}/include/${PLATFORM_FOLDER}/${ARCH_DIR} + ) + set(include_dirs) + foreach(_dir ${include_dir_candidates}) + if(EXISTS ${_dir}) + # find all include paths + if(_${_lib}_inc_paths) + set(_suffixes ${_${_lib}_inc_paths}) + else() + set(_suffixes include) + endif() + foreach(_inc_name ${_${_lib}_inc}) + unset(_inc_tmp CACHE) + find_path(_inc_tmp ${_inc_name} PATH_SUFFIXES ${_suffixes} PATHS ${_dir} NO_DEFAULT_PATH) + if(_inc_tmp) + list(APPEND include_dirs ${_inc_tmp}) + endif() + endforeach() + endif(EXISTS ${_dir}) + endforeach() + if(include_dirs) + set(${_prefix}_INCLUDE_DIRS ${include_dirs} CACHE PATH "Path to includes for ${_prefix}" FORCE) + endif() + #message(STATUS "${_lib} ${_prefix}_INCLUDE_DIRS: ${${_prefix}_INCLUDE_DIRS}") + + set(lib_dir_candidates + ${_root}/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${_root}/prebuilt/${PLATFORM_FOLDER} + ${_root}/prebuilt/${PLATFORM_FOLDER}/release-lib + ${_root}/prebuilt/${ARCH_DIR} + ${_root}/libraries/${PLATFORM_FOLDER} + ${_root}/prebuilt + ) + set(libs) + foreach(_dir ${lib_dir_candidates}) + if(EXISTS ${_dir}) + # find all libs + foreach(_lib_name ${_${_lib}_libs}) + unset(_lib_tmp CACHE) + find_library(_lib_tmp ${_lib_name} PATHS ${_dir} NO_DEFAULT_PATH) + if(_lib_tmp) + list(APPEND libs ${_lib_tmp}) + endif() + endforeach() + endif(EXISTS ${_dir}) + endforeach() + if(libs) + set(${_prefix}_LIBRARIES ${libs} CACHE STRING "Libraries to link for ${_prefix}" FORCE) + endif() + + if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS) + set(${_prefix}_FOUND YES) + endif() + + endif(EXISTS ${_root}) + endforeach() +endforeach() diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake index 4d3068737e..e286d78712 100644 --- a/cmake/Modules/FindCURL.cmake +++ b/cmake/Modules/FindCURL.cmake @@ -37,26 +37,6 @@ set(CURL_LIBRARY_NAMES libcurl ) -if(USE_PREBUILT_LIBS) - find_path(CURL_INCLUDE_DIR curl/curl.h - PATH_SUFFIXES include/${PLATFORM_FOLDER} include - PATHS ${COCOS_EXTERNAL_DIR}/curl - NO_DEFAULT_PATH - ) - find_library(CURL_LIBRARY NAMES ${CURL_LIBRARY_NAMES} - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - PATHS ${COCOS_EXTERNAL_DIR}/curl - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT CURL_INCLUDE_DIR OR NOT CURL_LIBRARY) - unset(CURL_INCLUDE_DIR CACHE) - unset(CURL_LIBRARY CACHE) - endif() -endif() - find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_search_module(CURL QUIET libcurl) diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index b94834c338..31fc02f489 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -27,28 +27,6 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -if(USE_PREBUILT_LIBS) - find_path(CHIPMUNK_INCLUDE_DIR chipmunk.h - PATH_SUFFIXES - include/chipmunk - include - PATHS ${COCOS_EXTERNAL_DIR}/chipmunk - NO_DEFAULT_PATH - ) - find_library(CHIPMUNK_LIBRARY NAMES chipmunk libchipmunk - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - PATHS ${COCOS_EXTERNAL_DIR}/chipmunk - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT CHIPMUNK_INCLUDE_DIR OR NOT CHIPMUNK_LIBRARY) - unset(CHIPMUNK_INCLUDE_DIR CACHE) - unset(CHIPMUNK_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - FIND_PATH(CHIPMUNK_INCLUDE_DIR chipmunk.h HINTS ENV CHIPMUNK_DIR diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake index d1318e6c03..54e4d4a800 100644 --- a/cmake/Modules/FindFMODEX.cmake +++ b/cmake/Modules/FindFMODEX.cmake @@ -13,27 +13,6 @@ # FMODEX_INCLUDE_DIRS, where to find headers. # -# Try find fmodex for our arch in external folder -set(_FMOD_COCOS_PATHS - ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/fmod - ${COCOS_EXTERNAL_DIR}/fmod - ) -if(USE_PREBUILT_LIBS) - find_path(FMODEX_INCLUDE_DIR fmod.h - PATH_SUFFIXES include/${ARCH_DIR} include - PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH - ) - find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 - PATH_SUFFIXES prebuilt/${ARCH_DIR} prebuilt - PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT FMODEX_INCLUDE_DIR OR NOT FMODEX_LIBRARY) - unset(FMODEX_INCLUDE_DIR CACHE) - unset(FMODEX_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - find_path(FMODEX_INCLUDE_DIR fmod.h HINTS ENV FMODEX_DIR PATH_SUFFIXES include/fmodex include diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 0fe3f3f5b2..7935a93790 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -43,35 +43,6 @@ #todo: fix location of freetype includes for linux android on cocos prebuilt repo #i.e we should not need to include an extra dir of /freetype2 -if(USE_PREBUILT_LIBS) - find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h - PATHS ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} - NO_DEFAULT_PATH - ) - find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h - PATHS - ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} - ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER}/freetype2 - NO_DEFAULT_PATH - ) - find_library(FREETYPE_LIBRARY NAMES freetype libfreetype freetype219 freetype250 - PATHS - ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER} - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_LIBRARY) - set(FREETYPE_FOUND 1) - set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}) - set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) - else() - unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) - unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) - unset(FREETYPE_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - # Try pkg-config first (because it provided deps info) if(NOT FREETYPE_FOUND) find_package(PkgConfig) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c200fbe710..4eda8daac8 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -97,6 +97,8 @@ elseif(LINUX) cocos_use_pkg(cocos2d ${_pkg}) endforeach() elseif(MACOSX OR APPLE) + cocos_use_pkg(cocos2d GLFW3) + INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) FIND_LIBRARY(COCOA_LIBRARY Cocoa) From 012a1524060ccaf86d9a888d61f0f40c293320d1 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 13:49:59 +0300 Subject: [PATCH 37/39] Fix build of luasocket on linux --- cocos/scripting/lua-bindings/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 0b1cf50ca8..5b00b863c9 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -56,6 +56,7 @@ if(WINDOWS) ${cocos_root}/external/lua/luasocket/wsocket.c ) elseif(UNIX) + add_definitions(-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE) list(APPEND lua_cocos2d_source_files ${cocos_root}/external/lua/luasocket/serial.c ${cocos_root}/external/lua/luasocket/unix.c From 8c331649dcf73aef73acac13dd5f011bff323051 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 13:50:55 +0300 Subject: [PATCH 38/39] fix finding prebuilt fmod on linux --- cmake/Modules/CocosUsePrebuiltLibs.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/CocosUsePrebuiltLibs.cmake b/cmake/Modules/CocosUsePrebuiltLibs.cmake index 1ad3b93899..15344102f3 100644 --- a/cmake/Modules/CocosUsePrebuiltLibs.cmake +++ b/cmake/Modules/CocosUsePrebuiltLibs.cmake @@ -60,8 +60,9 @@ set(_OpenalSoft_libs OpenAL32) set(_zlib_inc zlib.h) set(_zlib_libs libzlib) +set(_fmod_prefix FMODEX) set(_fmod_inc fmod.h) -set(_fmod_libs fmodex fmodexL) +set(_fmod_libs fmodex fmodex64 fmodexL fmodexL64) set(all_prebuilt_libs chipmunk @@ -157,6 +158,7 @@ foreach(_lib ${all_prebuilt_libs}) if(libs) set(${_prefix}_LIBRARIES ${libs} CACHE STRING "Libraries to link for ${_prefix}" FORCE) endif() + #message(STATUS "${_lib} ${_prefix}_LIBRARIES: ${${_prefix}_LIBRARIES}") if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS) set(${_prefix}_FOUND YES) From e91140b40936070b24063c9e03f4a1214ba32d98 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 22:22:56 +0300 Subject: [PATCH 39/39] Oops, restore tools/cocos2d-console to f1a8f35036b9cc85061d91447bce8e35439b43a1 (while merging with upstream v3 I fetched some strange commit for that module) --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 36153464b9..f1a8f35036 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 36153464b943d179a8d21ab294030c91c6e18ace +Subproject commit f1a8f35036b9cc85061d91447bce8e35439b43a1