Changed: Updated Android ans iOS toolchains

--HG--
branch : develop
This commit is contained in:
kervala 2017-10-01 15:18:15 +02:00
parent 30c6a7a935
commit aa6d1a7bbb
2 changed files with 78 additions and 121 deletions

View file

@ -28,14 +28,14 @@ IF(TARGET_CPU STREQUAL "armv7")
SET(TOOLCHAIN_ARCH "arm")
SET(GCC_TOOLCHAIN_PREFIX "arm-linux-androideabi")
SET(TOOLCHAIN_BIN_PREFIX "arm-linux-androideabi")
SET(MINIMUM_NDK_TARGET 4)
SET(MINIMUM_NDK_TARGET 9)
ELSEIF(TARGET_CPU STREQUAL "armv5")
SET(LIBRARY_ARCHITECTURE "armeabi")
SET(CMAKE_SYSTEM_PROCESSOR "armv5")
SET(TOOLCHAIN_ARCH "arm")
SET(GCC_TOOLCHAIN_PREFIX "arm-linux-androideabi")
SET(TOOLCHAIN_BIN_PREFIX "arm-linux-androideabi")
SET(MINIMUM_NDK_TARGET 4)
SET(MINIMUM_NDK_TARGET 9)
ELSEIF(TARGET_CPU STREQUAL "arm64")
SET(LIBRARY_ARCHITECTURE "arm64-v8a")
SET(CMAKE_SYSTEM_PROCESSOR "arm64")
@ -76,14 +76,9 @@ ELSE()
ENDIF()
SET(CLANG_TOOLCHAIN_PREFIX "llvm")
SET(ANDROID_COMPILER "GCC")
IF(NDK_TOOLCHAIN_VERSION STREQUAL "clang")
SET(ANDROID_COMPILER "clang")
SET(CLANG ON)
ELSE()
SET(GCC_TOOLCHAIN_VERSION ${NDK_TOOLCHAIN_VERSION})
ENDIF()
SET(ANDROID_COMPILER "clang")
SET(ANDROID_COMPILER "clang")
SET(CLANG ON)
IF(NOT NDK_TARGET)
SET(NDK_TARGET ${MINIMUM_NDK_TARGET})
@ -94,88 +89,71 @@ ELSE()
ENDIF()
IF(CMAKE_HOST_WIN32)
SET(TOOLCHAIN_HOST "windows")
SET(TOOLCHAIN_HOST "windows-x86_64")
SET(TOOLCHAIN_BIN_SUFFIX ".exe")
ELSEIF(CMAKE_HOST_APPLE)
SET(TOOLCHAIN_HOST "apple")
SET(TOOLCHAIN_BIN_SUFFIX "")
ELSEIF(CMAKE_HOST_UNIX)
SET(TOOLCHAIN_HOST "linux")
SET(TOOLCHAIN_HOST "linux-x86_64")
SET(TOOLCHAIN_BIN_SUFFIX "")
ENDIF()
MACRO(SEARCH_TOOLCHAIN _COMPILER)
SET(${_COMPILER}_TOOLCHAIN_VERSIONS)
FILE(GLOB _TOOLCHAIN_VERSIONS "${NDK_ROOT}/toolchains/${${_COMPILER}_TOOLCHAIN_PREFIX}-*")
IF(_TOOLCHAIN_VERSIONS)
# clang
SET(CLANG_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${CLANG_TOOLCHAIN_PREFIX}/prebuilt/${TOOLCHAIN_HOST}")
IF(EXISTS ${CLANG_TOOLCHAIN_ROOT})
MESSAGE(STATUS "Found LLVM toolchain in ${CLANG_TOOLCHAIN_ROOT}")
ELSE()
MESSAGE(FATAL_ERROR "No LLVM toolchain found in default search path ${CLANG_TOOLCHAIN_ROOT}")
ENDIF()
# gcc
SET(GCC_TOOLCHAIN_VERSIONS)
FILE(GLOB _TOOLCHAIN_VERSIONS "${NDK_ROOT}/toolchains/${GCC_TOOLCHAIN_PREFIX}-*")
IF(_TOOLCHAIN_VERSIONS)
LIST(SORT _TOOLCHAIN_VERSIONS)
LIST(REVERSE _TOOLCHAIN_VERSIONS)
FOREACH(_TOOLCHAIN_VERSION ${_TOOLCHAIN_VERSIONS})
STRING(REGEX REPLACE ".+${_PREFIX}-([0-9.]+)" "\\1" _TOOLCHAIN_VERSION "${_TOOLCHAIN_VERSION}")
IF(_TOOLCHAIN_VERSION MATCHES "^([0-9.]+)$")
LIST(APPEND ${_COMPILER}_TOOLCHAIN_VERSIONS ${_TOOLCHAIN_VERSION})
LIST(APPEND GCC_TOOLCHAIN_VERSIONS ${_TOOLCHAIN_VERSION})
ENDIF()
ENDFOREACH()
ENDIF()
ENDIF()
# try prefixes without version
SET(_TOOLCHAIN_WITHOUT_VERSION "${NDK_ROOT}/toolchains/${${_COMPILER}_TOOLCHAIN_PREFIX}")
IF(EXISTS ${_TOOLCHAIN_WITHOUT_VERSION})
LIST(APPEND ${_COMPILER}_TOOLCHAIN_VERSIONS "default")
ENDIF()
IF(NOT GCC_TOOLCHAIN_VERSIONS)
MESSAGE(FATAL_ERROR "No GCC version found in default search path ${NDK_ROOT}/toolchains")
ENDIF()
IF(NOT ${_COMPILER}_TOOLCHAIN_VERSIONS)
MESSAGE(FATAL_ERROR "No Android ${_COMPILER} toolchain found in default search path ${NDK_ROOT}/toolchains")
ENDIF()
IF(${_COMPILER}_TOOLCHAIN_VERSIONS)
LIST(FIND ${_COMPILER}_TOOLCHAIN_VERSIONS "${${_COMPILER}_TOOLCHAIN_VERSION}" _INDEX)
IF(GCC_TOOLCHAIN_VERSIONS)
LIST(FIND GCC_TOOLCHAIN_VERSIONS "${GCC_TOOLCHAIN_VERSION}" _INDEX)
IF(_INDEX EQUAL -1)
LIST(GET ${_COMPILER}_TOOLCHAIN_VERSIONS 0 ${_COMPILER}_TOOLCHAIN_VERSION)
ENDIF()
ELSE()
LIST(GET ${_COMPILER}_TOOLCHAIN_VERSIONS 0 ${_COMPILER}_TOOLCHAIN_VERSION)
LIST(GET GCC_TOOLCHAIN_VERSIONS 0 GCC_TOOLCHAIN_VERSION)
ENDIF()
ELSE()
LIST(GET GCC_TOOLCHAIN_VERSIONS 0 GCC_TOOLCHAIN_VERSION)
ENDIF()
MESSAGE(STATUS "TOOLCHAIN_PREFIX = ${${_COMPILER}_TOOLCHAIN_VERSION}")
SET(GCC_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${GCC_TOOLCHAIN_PREFIX}-${GCC_TOOLCHAIN_VERSION}/prebuilt/${TOOLCHAIN_HOST}")
IF("${${_COMPILER}_TOOLCHAIN_VERSION}" STREQUAL "default")
MESSAGE(STATUS "default")
SET(${_COMPILER}_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${${_COMPILER}_TOOLCHAIN_PREFIX}/prebuilt/${TOOLCHAIN_HOST}")
ELSE()
MESSAGE(STATUS "not default")
SET(${_COMPILER}_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${${_COMPILER}_TOOLCHAIN_PREFIX}-${${_COMPILER}_TOOLCHAIN_VERSION}/prebuilt/${TOOLCHAIN_HOST}")
ENDIF()
IF(NOT EXISTS "${${_COMPILER}_TOOLCHAIN_ROOT}")
FILE(GLOB _TOOLCHAIN_PREFIXES "${${_COMPILER}_TOOLCHAIN_ROOT}*")
IF(NOT EXISTS "${GCC_TOOLCHAIN_ROOT}")
FILE(GLOB _TOOLCHAIN_PREFIXES "${GCC_TOOLCHAIN_ROOT}*")
IF(_TOOLCHAIN_PREFIXES)
LIST(GET _TOOLCHAIN_PREFIXES 0 ${_COMPILER}_TOOLCHAIN_ROOT)
LIST(GET _TOOLCHAIN_PREFIXES 0 GCC_TOOLCHAIN_ROOT)
ENDIF()
ENDIF()
ENDMACRO()
IF(CLANG)
SEARCH_TOOLCHAIN(CLANG)
MESSAGE(STATUS "Target Android NDK ${NDK_TARGET} and use clang ${CLANG_TOOLCHAIN_VERSION}")
ENDIF()
SEARCH_TOOLCHAIN(GCC)
MESSAGE(STATUS "Target Android NDK ${NDK_TARGET} and use GCC ${GCC_TOOLCHAIN_VERSION}")
IF(CLANG_TOOLCHAIN_ROOT)
MESSAGE(STATUS "Found Android LLVM toolchain in ${CLANG_TOOLCHAIN_ROOT}")
ENDIF()
IF(GCC_TOOLCHAIN_ROOT)
MESSAGE(STATUS "Found Android GCC toolchain in ${GCC_TOOLCHAIN_ROOT}")
IF(EXISTS "${GCC_TOOLCHAIN_ROOT}")
MESSAGE(STATUS "Found GCC toolchain in ${GCC_TOOLCHAIN_ROOT}")
ELSE()
MESSAGE(FATAL_ERROR "No GCC toolchain found in default search path ${GCC_TOOLCHAIN_ROOT}")
ENDIF()
# NDK
SET(PLATFORM_ROOT "${NDK_ROOT}/platforms/android-${NDK_TARGET}/arch-${TOOLCHAIN_ARCH}")
MESSAGE(STATUS "Found Android platform in ${PLATFORM_ROOT}")
MESSAGE(STATUS "Target Android NDK ${NDK_TARGET} found in ${PLATFORM_ROOT}")
# include dirs
SET(PLATFORM_INCLUDE_DIR "${PLATFORM_ROOT}/usr/include")
@ -208,41 +186,29 @@ MACRO(SET_TOOLCHAIN_BINARY_GCC _NAME _BINARY)
SET(${_NAME} ${GCC_TOOLCHAIN_ROOT}/bin/${TOOLCHAIN_BIN_PREFIX}-${_BINARY}${TOOLCHAIN_BIN_SUFFIX} CACHE PATH "" FORCE)
ENDMACRO()
# Force the compilers to GCC for Android
include (CMakeForceCompiler)
SET(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
IF(CLANG)
MESSAGE(STATUS "Using clang compiler")
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_C_COMPILER clang)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_CXX_COMPILER clang++)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_C_COMPILER clang)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_CXX_COMPILER clang++)
SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER})
SET(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN_BIN_PREFIX})
SET(CMAKE_C_COMPILER_FORCED TRUE)
CMAKE_FORCE_C_COMPILER(${CMAKE_C_COMPILER} clang)
CMAKE_FORCE_CXX_COMPILER(${CMAKE_CXX_COMPILER} clang)
SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
SET(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN_BIN_PREFIX})
SET(CMAKE_CXX_COMPILER_FORCED TRUE)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_ASM_COMPILER llvm-as)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_AR llvm-ar)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_LINKER clang++)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_ASM_COMPILER llvm-as)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_AR llvm-ar)
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_LINKER clang++)
IF(NOT EXISTS "${CMAKE_ASM_COMPILER}")
IF(NOT EXISTS "${CMAKE_ASM_COMPILER}")
SET_TOOLCHAIN_BINARY_GCC(CMAKE_ASM_COMPILER as)
ENDIF()
ENDIF()
IF(NOT EXISTS "${CMAKE_AR}")
IF(NOT EXISTS "${CMAKE_AR}")
SET_TOOLCHAIN_BINARY_GCC(CMAKE_AR ar)
ENDIF()
ELSE()
MESSAGE(STATUS "Using GCC compiler")
SET_TOOLCHAIN_BINARY_GCC(CMAKE_C_COMPILER gcc)
SET_TOOLCHAIN_BINARY_GCC(CMAKE_CXX_COMPILER g++)
CMAKE_FORCE_C_COMPILER(${CMAKE_C_COMPILER} GNU)
CMAKE_FORCE_CXX_COMPILER(${CMAKE_CXX_COMPILER} GNU)
SET_TOOLCHAIN_BINARY_GCC(CMAKE_ASM_COMPILER as)
SET_TOOLCHAIN_BINARY_GCC(CMAKE_AR ar)
SET_TOOLCHAIN_BINARY_GCC(CMAKE_LINKER ld)
ENDIF()
SET_TOOLCHAIN_BINARY_GCC(CMAKE_STRIP strip)

View file

@ -35,23 +35,6 @@ SET(UNIX ON)
SET(APPLE ON)
SET(IOS ON)
# Force the compilers to Clang for iOS
include (CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER (clang Clang)
CMAKE_FORCE_CXX_COMPILER (clang++ Clang)
IF(CMAKE_CXX_COMPILER)
EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} --version
OUTPUT_VARIABLE CLANG_VERSION_RAW
OUTPUT_STRIP_TRAILING_WHITESPACE)
STRING(REGEX REPLACE "Apple LLVM version ([\\.0-9]+).*"
"\\1" CMAKE_CXX_COMPILER_VERSION "${CLANG_VERSION_RAW}")
SET(CMAKE_C_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})
SET(CMAKE_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})
ENDIF()
# Setup iOS platform
IF(NOT DEFINED IOS_PLATFORM)
SET(IOS_PLATFORM "OS")
@ -162,14 +145,14 @@ IF(CMAKE_GENERATOR MATCHES Xcode)
ENDIF()
ELSE()
IF(${IOS_PLATFORM} STREQUAL "OS")
SET(ARCHS "armv7;arm64")
SET(ARCHS armv7 arm64)
SET(CMAKE_SYSTEM_PROCESSOR "armv7")
ELSEIF(${IOS_PLATFORM} STREQUAL "SIMULATOR")
# iPhone simulator targets i386
SET(ARCHS "i386")
SET(CMAKE_SYSTEM_PROCESSOR "x86")
ELSEIF(${IOS_PLATFORM} STREQUAL "ALL")
SET(ARCHS "armv7;arm64;i386;x86_64")
SET(ARCHS armv7 arm64 i386 x86_64)
SET(CMAKE_SYSTEM_PROCESSOR "armv7")
ENDIF()
ENDIF()
@ -198,5 +181,13 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Force the compilers to Clang for iOS
SET(CMAKE_C_COMPILER clang)
SET(CMAKE_CXX_COMPILER clang++)
# Skip the platform compiler checks for cross compiling.
SET(CMAKE_CXX_COMPILER_FORCED TRUE)
SET(CMAKE_C_COMPILER_FORCED TRUE)
# determinate location for bin utils based on CMAKE_FIND_ROOT_PATH
include(CMakeFindBinUtils)
INCLUDE(CMakeFindBinUtils)