2013-09-06 11:38:19 +00:00
|
|
|
IF(DEFINED CMAKE_CROSSCOMPILING)
|
|
|
|
# subsequent toolchain loading is not really needed
|
|
|
|
RETURN()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
# Standard settings
|
|
|
|
SET(CMAKE_SYSTEM_NAME Linux)
|
|
|
|
SET(CMAKE_SYSTEM_VERSION 1) # TODO: determine target Linux version
|
|
|
|
SET(UNIX ON)
|
|
|
|
SET(LINUX ON)
|
|
|
|
SET(ANDROID ON)
|
|
|
|
|
|
|
|
IF(NOT NDK_ROOT)
|
|
|
|
SET(NDK_ROOT $ENV{NDK_ROOT})
|
|
|
|
|
|
|
|
IF(CMAKE_HOST_WIN32)
|
|
|
|
FILE(TO_CMAKE_PATH ${NDK_ROOT} NDK_ROOT)
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
|
|
|
IF(NOT TARGET_CPU)
|
|
|
|
SET(TARGET_CPU "armv7")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2013-09-06 11:38:19 +00:00
|
|
|
IF(TARGET_CPU STREQUAL "armv7")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "armeabi-v7a")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "armv7")
|
|
|
|
SET(TOOLCHAIN_ARCH "arm")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "arm-linux-androideabi")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "arm-linux-androideabi")
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(MINIMUM_NDK_TARGET 9)
|
2013-09-06 11:38:19 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "armv5")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "armeabi")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "armv5")
|
|
|
|
SET(TOOLCHAIN_ARCH "arm")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "arm-linux-androideabi")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "arm-linux-androideabi")
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(MINIMUM_NDK_TARGET 9)
|
2015-12-15 12:41:27 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "arm64")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "arm64-v8a")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "arm64")
|
|
|
|
SET(TOOLCHAIN_ARCH "arm64")
|
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "aarch64-linux-android")
|
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "aarch64-linux-android")
|
|
|
|
SET(MINIMUM_NDK_TARGET 21)
|
2013-09-06 11:38:19 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "x86")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "x86")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "x86")
|
|
|
|
SET(TOOLCHAIN_ARCH "x86")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "x86")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "i686-linux-android")
|
2013-09-06 11:38:19 +00:00
|
|
|
SET(MINIMUM_NDK_TARGET 9)
|
2015-12-15 12:41:27 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "x86_64")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "x86_64")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "x86_64")
|
|
|
|
SET(TOOLCHAIN_ARCH "x86_64")
|
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "x86_64")
|
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "x86_64-linux-android")
|
|
|
|
SET(MINIMUM_NDK_TARGET 21)
|
2013-09-06 11:38:19 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "mips")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "mips")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "mips")
|
|
|
|
SET(TOOLCHAIN_ARCH "mips")
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "mipsel-linux-android")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "mipsel-linux-android")
|
2013-09-06 11:38:19 +00:00
|
|
|
SET(MINIMUM_NDK_TARGET 9)
|
2015-12-15 12:41:27 +00:00
|
|
|
ELSEIF(TARGET_CPU STREQUAL "mips64")
|
|
|
|
SET(LIBRARY_ARCHITECTURE "mips64")
|
|
|
|
SET(CMAKE_SYSTEM_PROCESSOR "mips64")
|
|
|
|
SET(TOOLCHAIN_ARCH "mips64")
|
|
|
|
SET(GCC_TOOLCHAIN_PREFIX "mips64el-linux-android")
|
|
|
|
SET(TOOLCHAIN_BIN_PREFIX "mips64el-linux-android")
|
|
|
|
SET(MINIMUM_NDK_TARGET 21)
|
|
|
|
ELSE()
|
|
|
|
MESSAGE(FATAL_ERROR "Unable to process TARGET_CPU ${TARGET_CPU}")
|
|
|
|
ENDIF()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
2015-12-15 12:41:27 +00:00
|
|
|
SET(CLANG_TOOLCHAIN_PREFIX "llvm")
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(ANDROID_COMPILER "clang")
|
|
|
|
SET(ANDROID_COMPILER "clang")
|
|
|
|
SET(CLANG ON)
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2013-09-06 11:38:19 +00:00
|
|
|
IF(NOT NDK_TARGET)
|
|
|
|
SET(NDK_TARGET ${MINIMUM_NDK_TARGET})
|
2015-12-15 12:41:27 +00:00
|
|
|
ELSE()
|
|
|
|
IF(NDK_TARGET LESS MINIMUM_NDK_TARGET)
|
|
|
|
SET(NDK_TARGET ${MINIMUM_NDK_TARGET})
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
|
|
|
IF(CMAKE_HOST_WIN32)
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(TOOLCHAIN_HOST "windows-x86_64")
|
2013-09-06 11:38:19 +00:00
|
|
|
SET(TOOLCHAIN_BIN_SUFFIX ".exe")
|
|
|
|
ELSEIF(CMAKE_HOST_APPLE)
|
|
|
|
SET(TOOLCHAIN_HOST "apple")
|
|
|
|
SET(TOOLCHAIN_BIN_SUFFIX "")
|
|
|
|
ELSEIF(CMAKE_HOST_UNIX)
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(TOOLCHAIN_HOST "linux-x86_64")
|
2013-09-06 11:38:19 +00:00
|
|
|
SET(TOOLCHAIN_BIN_SUFFIX "")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
# clang
|
|
|
|
SET(CLANG_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${CLANG_TOOLCHAIN_PREFIX}/prebuilt/${TOOLCHAIN_HOST}")
|
2016-06-11 14:55:54 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
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()
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
# 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 GCC_TOOLCHAIN_VERSIONS ${_TOOLCHAIN_VERSION})
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
2017-10-01 13:18:15 +00:00
|
|
|
ENDFOREACH()
|
|
|
|
ENDIF()
|
2016-06-11 14:55:54 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
IF(NOT GCC_TOOLCHAIN_VERSIONS)
|
|
|
|
MESSAGE(FATAL_ERROR "No GCC version found in default search path ${NDK_ROOT}/toolchains")
|
|
|
|
ENDIF()
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
IF(GCC_TOOLCHAIN_VERSIONS)
|
|
|
|
LIST(FIND GCC_TOOLCHAIN_VERSIONS "${GCC_TOOLCHAIN_VERSION}" _INDEX)
|
|
|
|
IF(_INDEX EQUAL -1)
|
|
|
|
LIST(GET GCC_TOOLCHAIN_VERSIONS 0 GCC_TOOLCHAIN_VERSION)
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
2017-10-01 13:18:15 +00:00
|
|
|
ELSE()
|
|
|
|
LIST(GET GCC_TOOLCHAIN_VERSIONS 0 GCC_TOOLCHAIN_VERSION)
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(GCC_TOOLCHAIN_ROOT "${NDK_ROOT}/toolchains/${GCC_TOOLCHAIN_PREFIX}-${GCC_TOOLCHAIN_VERSION}/prebuilt/${TOOLCHAIN_HOST}")
|
2013-09-06 11:38:19 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
IF(NOT EXISTS "${GCC_TOOLCHAIN_ROOT}")
|
|
|
|
FILE(GLOB _TOOLCHAIN_PREFIXES "${GCC_TOOLCHAIN_ROOT}*")
|
|
|
|
IF(_TOOLCHAIN_PREFIXES)
|
|
|
|
LIST(GET _TOOLCHAIN_PREFIXES 0 GCC_TOOLCHAIN_ROOT)
|
|
|
|
ENDIF()
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
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}")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
# NDK
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(PLATFORM_ROOT "${NDK_ROOT}/platforms/android-${NDK_TARGET}/arch-${TOOLCHAIN_ARCH}")
|
2013-09-06 11:38:19 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
MESSAGE(STATUS "Target Android NDK ${NDK_TARGET} found in ${PLATFORM_ROOT}")
|
2013-09-06 11:38:19 +00:00
|
|
|
|
|
|
|
# include dirs
|
|
|
|
SET(PLATFORM_INCLUDE_DIR "${PLATFORM_ROOT}/usr/include")
|
|
|
|
SET(STL_DIR "${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++")
|
|
|
|
|
2015-02-14 12:47:37 +00:00
|
|
|
IF(EXISTS "${STL_DIR}/${GCC_TOOLCHAIN_VERSION}")
|
2013-09-06 11:38:19 +00:00
|
|
|
# NDK version >= 8b
|
2015-02-14 12:47:37 +00:00
|
|
|
SET(STL_DIR "${STL_DIR}/${GCC_TOOLCHAIN_VERSION}")
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDIF()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
|
|
|
SET(STL_INCLUDE_DIR "${STL_DIR}/include")
|
|
|
|
SET(STL_LIBRARY_DIR "${STL_DIR}/libs/${LIBRARY_ARCHITECTURE}")
|
|
|
|
SET(STL_INCLUDE_CPU_DIR "${STL_LIBRARY_DIR}/include")
|
|
|
|
SET(STL_LIBRARY "${STL_LIBRARY_DIR}/libgnustl_static.a")
|
|
|
|
|
2015-02-14 12:47:37 +00:00
|
|
|
MESSAGE(STATUS "STL include dir: ${STL_INCLUDE_DIR}")
|
|
|
|
MESSAGE(STATUS "STL library dir: ${STL_LIBRARY_DIR}")
|
|
|
|
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH ${CLANG_TOOLCHAIN_ROOT} ${GCC_TOOLCHAIN_ROOT} ${PLATFORM_ROOT}/usr ${CMAKE_PREFIX_PATH} ${CMAKE_INSTALL_PREFIX} $ENV{EXTERNAL_ANDROID_PATH} CACHE string "Android find search path root")
|
2013-09-06 11:38:19 +00:00
|
|
|
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
|
|
|
2015-12-15 12:41:27 +00:00
|
|
|
MACRO(SET_TOOLCHAIN_BINARY_LLVM _NAME _BINARY)
|
2016-06-11 14:55:54 +00:00
|
|
|
SET(${_NAME} ${CLANG_TOOLCHAIN_ROOT}/bin/${_BINARY}${TOOLCHAIN_BIN_SUFFIX} CACHE PATH "" FORCE)
|
2015-12-15 12:41:27 +00:00
|
|
|
ENDMACRO()
|
|
|
|
|
|
|
|
MACRO(SET_TOOLCHAIN_BINARY_GCC _NAME _BINARY)
|
|
|
|
SET(${_NAME} ${GCC_TOOLCHAIN_ROOT}/bin/${TOOLCHAIN_BIN_PREFIX}-${_BINARY}${TOOLCHAIN_BIN_SUFFIX} CACHE PATH "" FORCE)
|
|
|
|
ENDMACRO()
|
2013-09-06 11:38:19 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
2015-12-15 12:41:27 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_C_COMPILER clang)
|
|
|
|
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_CXX_COMPILER clang++)
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER})
|
|
|
|
SET(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN_BIN_PREFIX})
|
|
|
|
SET(CMAKE_C_COMPILER_FORCED TRUE)
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
|
|
|
|
SET(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN_BIN_PREFIX})
|
|
|
|
SET(CMAKE_CXX_COMPILER_FORCED TRUE)
|
2016-06-11 14:55:54 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_ASM_COMPILER llvm-as)
|
|
|
|
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_AR llvm-ar)
|
|
|
|
SET_TOOLCHAIN_BINARY_LLVM(CMAKE_LINKER clang++)
|
2015-02-14 12:47:37 +00:00
|
|
|
|
2017-10-01 13:18:15 +00:00
|
|
|
IF(NOT EXISTS "${CMAKE_ASM_COMPILER}")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_ASM_COMPILER as)
|
2017-10-01 13:18:15 +00:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(NOT EXISTS "${CMAKE_AR}")
|
2015-12-15 12:41:27 +00:00
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_AR ar)
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
|
|
|
|
2015-12-15 12:41:27 +00:00
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_STRIP strip)
|
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_NM nm)
|
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_OBJCOPY objcopy)
|
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_OBJDUMP objdump)
|
|
|
|
SET_TOOLCHAIN_BINARY_GCC(CMAKE_RANLIB ranlib)
|