Various CMake improvements

- Added c++_shared (LLVM) to Android toolchain options. Fixed AndroidNdkGdb.cmake.
- Fixed includes when not using prebuilt libs. Added option to use sources in external when not using prebuilt libs.
- Added option in CMake to be able build Box2D without using it as physics library in cocos2d-x (similar to what is done in the Visual Studio solution).
This commit is contained in:
Adrien de Sentenac 2015-10-22 19:12:37 -04:00
parent fd3b6d4706
commit dac9be5016
18 changed files with 75 additions and 30 deletions

View File

@ -76,6 +76,11 @@ SelectModule()
include(SetCompilerOptions)
SetCompilerOptions()
if (CMAKE_FIND_ROOT_PATH AND USE_PREBUILT_LIBS)
# Adds cocos2d-x external folder to the list of valid include/library paths when cross-compiling and using prebuilds
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${COCOS_EXTERNAL_DIR})
endif ()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cocos
@ -84,6 +89,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/extensions
${CMAKE_CURRENT_SOURCE_DIR}/external
)
if(USE_PREBUILT_LIBS)
include(CocosUsePrebuiltLibs)
endif()

View File

@ -43,7 +43,7 @@
# also create a mininal NDK skeleton so ndk-gdb finds the paths
#
# the optional parameter defines the path to the android project.
# uses PROJECT_SOURCE_DIR by default.
# uses PROJECT_BINARY_DIR by default.
macro(android_ndk_gdb_enable)
if(ANDROID)
# create custom target that depends on the real target so it gets executed afterwards
@ -52,7 +52,7 @@ macro(android_ndk_gdb_enable)
if(${ARGC})
set(ANDROID_PROJECT_DIR ${ARGV0})
else()
set(ANDROID_PROJECT_DIR ${PROJECT_SOURCE_DIR})
set(ANDROID_PROJECT_DIR ${PROJECT_BINARY_DIR})
endif()
set(NDK_GDB_SOLIB_PATH ${ANDROID_PROJECT_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/)
@ -75,6 +75,7 @@ macro(android_ndk_gdb_enable)
# 3. copy gdbserver executable
file(COPY ${ANDROID_NDK}/prebuilt/android-${ANDROID_ARCH_NAME}/gdbserver/gdbserver DESTINATION ${LIBRARY_OUTPUT_PATH})
file(RENAME ${LIBRARY_OUTPUT_PATH}/gdbserver ${LIBRARY_OUTPUT_PATH}/gdbserver.so)
endif()
endmacro()
@ -82,15 +83,13 @@ endmacro()
# copies the debug version to NDK_GDB_SOLIB_PATH then strips symbols of original
macro(android_ndk_gdb_debuggable TARGET_NAME)
if(ANDROID)
get_property(TARGET_LOCATION TARGET ${TARGET_NAME} PROPERTY LOCATION)
# create custom target that depends on the real target so it gets executed afterwards
add_dependencies(NDK_GDB ${TARGET_NAME})
# 4. copy lib to obj
add_custom_command(TARGET NDK_GDB POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TARGET_LOCATION} ${NDK_GDB_SOLIB_PATH})
add_custom_command(TARGET NDK_GDB POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH})
# 5. strip symbols
add_custom_command(TARGET NDK_GDB POST_BUILD COMMAND ${CMAKE_STRIP} ${TARGET_LOCATION})
add_custom_command(TARGET NDK_GDB POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${TARGET_NAME}>)
endif()
endmacro()

View File

@ -48,7 +48,7 @@ macro (BuildModules)
# Box2d (not prebuilded, exists as source)
if(USE_BOX2D)
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/Box2D)
set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include)
set(Box2D_LIBRARIES box2d)
@ -58,11 +58,13 @@ macro (BuildModules)
set(Box2D_LIBRARIES Box2D)
endif()
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
elseif(BUILD_BOX2D)
add_subdirectory(external/Box2D)
endif(USE_BOX2D)
# Bullet (not prebuilded, exists as source)
if(USE_BULLET)
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/bullet)
set(BULLET_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet)
set(BULLET_LIBRARIES bullet)
@ -75,7 +77,7 @@ macro (BuildModules)
# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/recast)
set(RECAST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/recast)
set(RECAST_LIBRARIES recast)
@ -87,7 +89,7 @@ macro (BuildModules)
endif(USE_RECAST)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2)
set(TinyXML2_LIBRARIES tinyxml2)
@ -129,7 +131,7 @@ macro (BuildModules)
cocos_find_package(CURL CURL REQUIRED)
# flatbuffers
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
@ -138,7 +140,7 @@ macro (BuildModules)
endif()
# xxhash
if(USE_PREBUILT_LIBS)
if(USE_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(external/xxhash)
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)

View File

@ -128,7 +128,6 @@ foreach(_lib ${all_prebuilt_libs})
endif()
foreach(_inc_name ${_${_lib}_inc})
unset(_inc_tmp CACHE)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
find_path(_inc_tmp ${_inc_name} PATH_SUFFIXES ${_suffixes} PATHS ${_dir} NO_DEFAULT_PATH)
if(_inc_tmp)
list(APPEND include_dirs ${_inc_tmp})
@ -156,7 +155,6 @@ foreach(_lib ${all_prebuilt_libs})
# find all libs
foreach(_lib_name ${_${_lib}_libs})
unset(_lib_tmp CACHE)
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
find_library(_lib_tmp ${_lib_name} PATHS ${_dir} NO_DEFAULT_PATH)
if(_lib_tmp)
list(APPEND libs ${_lib_tmp})

View File

@ -36,6 +36,7 @@ macro (SelectModule)
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
option(BUILD_BOX2D "Build box2d external without using it for physics library" OFF)
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
option(BUILD_CPP_EMPTY_TEST "Build TestCpp samples" ${BUILD_CPP_EMPTY_TEST_DEFAULT})
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
@ -43,6 +44,7 @@ macro (SelectModule)
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
option(BUILD_JS_TESTS "Build TestJS samples" ${BUILD_JS_TESTS_DEFAULT})
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
option(USE_SOURCES_EXTERNAL "Use sources in external directory (automatically ON when USE_PREBUILT_LIBS is ON)" OFF)
if(USE_PREBUILT_LIBS AND MINGW)
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")

View File

@ -97,7 +97,7 @@ macro (SetCompilerOptions)
endif()
endif()
if (MINGW OR NOT USE_PREBUILT_LIBS)
if (MINGW AND NOT USE_PREBUILT_LIBS)
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()

View File

@ -154,6 +154,10 @@
# Implies -frtti -fno-exceptions.
# Available for NDK r7b and newer.
# Silently degrades to gnustl_static if not available.
# c++_shared -> Use the LLVM libc++ runtime as a shared library.
# Implies -std=c++11.
# Available for NDK r7b and newer.
# Is not available for standalone toolchain.
#
# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on
# chosen runtime. If disabled, then the user is responsible for settings
@ -833,7 +837,7 @@ set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and
mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES )
if( BUILD_WITH_ANDROID_NDK )
if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$")
if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared|c\\+\\+_shared)$")
message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\".
The possible values are:
none -> Do not configure the runtime.
@ -845,6 +849,7 @@ The possible values are:
stlport_shared -> Use the STLport runtime as a shared library.
gnustl_static -> (default) Use the GNU STL as a static library.
gnustl_shared -> Use the GNU STL as a shared library.
c++_shared -> Use the LLVM libc++ as a shared library.
" )
endif()
elseif( BUILD_WITH_STANDALONE_TOOLCHAIN )
@ -891,7 +896,6 @@ See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc80
" )
endif()
# setup paths and STL for standalone toolchain
if( BUILD_WITH_STANDALONE_TOOLCHAIN )
set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" )
@ -1026,6 +1030,24 @@ if( BUILD_WITH_ANDROID_NDK )
else()
set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" )
endif()
elseif( ANDROID_STL MATCHES "c\\+\\+_shared" )
set( ANDROID_EXCEPTIONS ON )
set( ANDROID_RTTI ON )
set( ANDROID_CXX_ROOT "${ANDROID_NDK}/sources/cxx-stl/" )
set( ANDROID_LLVM_ROOT "${ANDROID_CXX_ROOT}/llvm-libc++" )
if( X86 )
set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/gabi++/include" )
else()
set( ANDROID_ABI_INCLUDE_DIRS "${ANDROID_CXX_ROOT}/llvm-libc++abi/libcxxabi/include" )
endif()
set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources" "${ANDROID_LLVM_ROOT}/libcxx/include" "${ANDROID_ABI_INCLUDE_DIRS}" )
# android support files
include_directories ( SYSTEM ${ANDROID_NDK}/sources/android/support/include )
if( EXISTS "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so" )
set( __libstl "${ANDROID_LLVM_ROOT}/libs/${ANDROID_NDK_ABI_NAME}/libc++_shared.so" )
else()
message( "c++ shared library doesn't exist" )
endif()
else()
message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" )
endif()
@ -1448,7 +1470,7 @@ if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES )
endif()
# global includes and link directories
include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} )
include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" "${ANDROID_SYSROOT}/usr/include/machine" ${ANDROID_STL_INCLUDE_DIRS} )
get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning
link_directories( "${__android_install_path}" )
@ -1628,7 +1650,7 @@ endif()
# Variables controlling behavior or set by cmake toolchain:
# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64"
# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version)
# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
# ANDROID_STL : c++_shared/gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none
# ANDROID_FORBID_SYGWIN : ON/OFF
# ANDROID_NO_UNDEFINED : ON/OFF
# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version)

View File

@ -88,12 +88,22 @@ set(COCOS_SRC cocos2d.cpp
add_library(cocos2dInternal ${COCOS_SRC})
set_target_properties(cocos2dInternal
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
VERSION "${COCOS2D_X_VERSION}"
)
set(PLATFORM_SPECIFIC_LIBS)
if(WINDOWS)
foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL)
cocos_use_pkg(cocos2dInternal ${_pkg})
endforeach()
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm)
if(MINGW)
list(APPEND PLATFORM_SPECIFIC_LIBS shlwapi version)
endif()
elseif(LINUX)
foreach(_pkg OPENGL GLEW GLFW3 FMOD FONTCONFIG THREADS GTK3)
cocos_use_pkg(cocos2dInternal ${_pkg})

View File

@ -29,9 +29,9 @@
NS_CC_BEGIN
CC_DLL const ValueVector ValueVectorNull;
CC_DLL const ValueMap ValueMapNull;
CC_DLL const ValueMapIntKey ValueMapIntKeyNull;
const ValueVector ValueVectorNull;
const ValueMap ValueMapNull;
const ValueMapIntKey ValueMapIntKeyNull;
const Value Value::Null;

View File

@ -1,7 +1,7 @@
#include "editor-support/cocostudio/WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
#include "platform/CCFileUtils.h"
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include "flatbuffers/flatbuffers.h"
#include "editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h"
#include "editor-support/cocostudio/CSParseBinary_generated.h"

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include "flatbuffers/flatbuffers.h"
#include "editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h"
#include "editor-support/cocostudio/CSParseBinary_generated.h"

View File

@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include "flatbuffers/flatbuffers.h"
#include "editor-support/cocostudio/WidgetReader/SkeletonReader/CSBoneBinary_generated.h"
#include "editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.h"

View File

@ -23,7 +23,7 @@
****************************************************************************/
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include "flatbuffers/flatbuffers.h"
#include "editor-support/cocostudio/WidgetReader/WidgetReader.h"
#include "editor-support/cocostudio/CSParseBinary_generated.h"

View File

@ -87,6 +87,12 @@ set(COCOS2DX_ANDROID_STATIC
add_library(cocos2dxandroid_static STATIC ${COCOS2DX_ANDROID_STATIC})
set_property(TARGET cocos2dxandroid_static PROPERTY POSITION_INDEPENDENT_CODE TRUE)
set_target_properties(cocos2dxandroid_static
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
VERSION "${COCOS2D_X_VERSION}"
)
endif()

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#include "platform/android/jni/JniHelper.h"
#include <string.h>
#include "base/CCDirector.h"
#include "../CCApplication.h"
#include "platform/CCApplication.h"
#include "platform/CCFileUtils.h"
#include "base/ccUTF8.h"

View File

@ -3,7 +3,7 @@
#include "base/CCEventType.h"
#include "base/CCEventCustom.h"
#include "base/CCEventDispatcher.h"
#include "../CCApplication.h"
#include "platform/CCApplication.h"
#include "platform/CCFileUtils.h"
#include "platform/android/jni/JniHelper.h"
#include <jni.h>

View File

@ -28,7 +28,7 @@
#include <vector>
#include <locale>
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
#include "platform/CCFileUtils.h"
#include "platform/CCApplication.h"
#include "base/CCEventListenerTouch.h"

View File

@ -3,7 +3,7 @@
#include "ConfigParser.h"
#include "cocostudio/CocoStudio.h"
#include "ui/UIHelper.h"
#include "tinyxml2/tinyxml2.h"
#include "tinyxml2.h"
////////////////////////////////////////