提交 af80ff94 编写于 作者: L Liu Yiqun

Allow the case user sets CMAKE_C_COMPILER directly instead of standalone toolchain.

上级 39f9056c
...@@ -41,7 +41,8 @@ IF(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN) ...@@ -41,7 +41,8 @@ IF(NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN)
CACHE PATH "Folder holds the standalone toolchain of Android NDK") CACHE PATH "Folder holds the standalone toolchain of Android NDK")
ENDIF() ENDIF()
IF(NOT ANDROID_STANDALONE_TOOLCHAIN) IF(NOT ANDROID_STANDALONE_TOOLCHAIN)
MESSAGE(FATAL_ERROR "Set ANDROID_STANDALONE_TOOLCHAIN to use a standalone toolchain.\n" MESSAGE(WARNING "It is recommened to set ANDROID_STANDALONE_TOOLCHAIN to "
"use a standalone toolchain.\n"
"To cross-compile for Android, you need to:\n" "To cross-compile for Android, you need to:\n"
"1. Download an Android NDK from" "1. Download an Android NDK from"
" https://developer.android.com/ndk/downloads/index.html\n" " https://developer.android.com/ndk/downloads/index.html\n"
...@@ -65,11 +66,6 @@ ENDIF() ...@@ -65,11 +66,6 @@ ENDIF()
IF(NOT DEFINED ANDROID_ARM_MODE) IF(NOT DEFINED ANDROID_ARM_MODE)
SET(ANDROID_ARM_MODE ON) SET(ANDROID_ARM_MODE ON)
ENDIF() ENDIF()
IF(NOT DEFINED ANDROID_ARM_NEON)
SET(ANDROID_ARM_NEON ON)
ENDIF()
IF(NOT ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "thumb") IF(NOT ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "thumb")
SET(ANDROID_ARM_MODE OFF) SET(ANDROID_ARM_MODE OFF)
SET(ANDROID_ARM_MODE_NAME "thumb") SET(ANDROID_ARM_MODE_NAME "thumb")
...@@ -78,6 +74,10 @@ ELSEIF(ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "arm") ...@@ -78,6 +74,10 @@ ELSEIF(ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "arm")
SET(ANDROID_ARM_MODE_NAME "arm") SET(ANDROID_ARM_MODE_NAME "arm")
ENDIF() ENDIF()
IF(NOT DEFINED ANDROID_ARM_NEON)
SET(ANDROID_ARM_NEON ON)
ENDIF()
IF(${CMAKE_VERSION} VERSION_LESS "3.7.0") IF(${CMAKE_VERSION} VERSION_LESS "3.7.0")
IF(${CMAKE_VERSION} VERSION_LESS "3.1.0") IF(${CMAKE_VERSION} VERSION_LESS "3.1.0")
SET(CMAKE_SYSTEM_NAME "Linux") SET(CMAKE_SYSTEM_NAME "Linux")
...@@ -85,47 +85,70 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.7.0") ...@@ -85,47 +85,70 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.7.0")
MESSAGE(WARNING "It is recommended to use CMake >= 3.7.0 (current version: " MESSAGE(WARNING "It is recommended to use CMake >= 3.7.0 (current version: "
"${CMAKE_VERSION}), when cross-compiling for Android.") "${CMAKE_VERSION}), when cross-compiling for Android.")
SET(CMAKE_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot") IF(ANDROID_STANDALONE_TOOLCHAIN)
SET(CMAKE_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
IF(NOT CMAKE_SYSTEM_VERSION)
SET(ANDROID_STANDALONE_TOOLCHAIN_API "") IF(NOT CMAKE_SYSTEM_VERSION)
SET(ANDROID_API_LEVEL_H_REGEX "^[\t ]*#[\t ]*define[\t ]+__ANDROID_API__[\t ]+([0-9]+)") SET(ANDROID_STANDALONE_TOOLCHAIN_API "")
FILE(STRINGS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" SET(ANDROID_API_LEVEL_H_REGEX "^[\t ]*#[\t ]*define[\t ]+__ANDROID_API__[\t ]+([0-9]+)")
ANDROID_API_LEVEL_H_CONTENT REGEX "${ANDROID_API_LEVEL_H_REGEX}") FILE(STRINGS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h"
IF(ANDROID_API_LEVEL_H_CONTENT MATCHES "${ANDROID_API_LEVEL_H_REGEX}") ANDROID_API_LEVEL_H_CONTENT REGEX "${ANDROID_API_LEVEL_H_REGEX}")
SET(ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}") IF(ANDROID_API_LEVEL_H_CONTENT MATCHES "${ANDROID_API_LEVEL_H_REGEX}")
SET(ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}")
ENDIF()
SET(CMAKE_SYSTEM_VERSION ${ANDROID_STANDALONE_TOOLCHAIN_API})
ENDIF() ENDIF()
SET(CMAKE_SYSTEM_VERSION ${ANDROID_STANDALONE_TOOLCHAIN_API})
ENDIF()
# Toolchain # Toolchain
SET(ANDROID_TOOLCHAIN "gcc") SET(ANDROID_TOOLCHAIN "gcc")
SET(ANDROID_TOOLCHAIN_ROOT ${ANDROID_STANDALONE_TOOLCHAIN}) SET(ANDROID_TOOLCHAIN_ROOT ${ANDROID_STANDALONE_TOOLCHAIN})
IF(ANDROID_ABI MATCHES "^armeabi(-v7a)?$") IF(ANDROID_ABI MATCHES "^armeabi(-v7a)?$")
SET(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi) SET(ANDROID_TOOLCHAIN_NAME arm-linux-androideabi)
IF(ANDROID_ABI STREQUAL "armeabi") IF(ANDROID_ABI STREQUAL "armeabi")
SET(CMAKE_SYSTEM_PROCESSOR armv5te) SET(CMAKE_SYSTEM_PROCESSOR armv5te)
ELSEIF(ANDROID_ABI STREQUAL "armeabi-v7a") ELSEIF(ANDROID_ABI STREQUAL "armeabi-v7a")
SET(CMAKE_SYSTEM_PROCESSOR armv7-a) SET(CMAKE_SYSTEM_PROCESSOR armv7-a)
ENDIF()
ENDIF() ENDIF()
SET(ANDROID_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-")
ENDIF() ENDIF()
SET(ANDROID_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-")
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}gcc") # C compiler
SET(CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gcc" CACHE PATH "C compiler") IF(NOT CMAKE_C_COMPILER)
SET(ANDROID_C_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gcc")
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Cannot found C compiler: ${ANDROID_TOOLCHAIN_PREFIX}gcc") GET_FILENAME_COMPONENT(ANDROID_C_COMPILER_PATH ${CMAKE_C_COMPILER} PROGRAM)
SET(ANDROID_C_COMPILER ${ANDROID_C_COMPILER_PATH})
ENDIF()
IF(NOT EXISTS ${ANDROID_C_COMPILER})
MESSAGE(FATAL_ERROR "Cannot found C compiler: ${ANDROID_C_COMPILER}")
ENDIF() ENDIF()
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}g++") # CXX compiler
SET(CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}g++" CACHE PATH "CXX compiler") IF(NOT CMAKE_CXX_COMPILER)
SET(ANDROID_CXX_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}g++")
ELSE() ELSE()
MESSAGE(FATAL_ERROR "Cannot found CXX compiler: ${ANDROID_TOOLCHAIN_PREFIX}g++") GET_FILENAME_COMPONENT(ANDROID_CXX_COMPILER_PATH ${CMAKE_CXX_COMPILER} PROGRAM)
SET(ANDROID_CXX_COMPILER ${ANDROID_CXX_COMPILER_PATH})
ENDIF()
IF(NOT EXISTS ${ANDROID_CXX_COMPILER})
MESSAGE(FATAL_ERROR "Cannot found CXX compiler: ${ANDROID_CXX_COMPILER}")
ENDIF() ENDIF()
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}gfortran") # Fortran compiler
SET(CMAKE_Fortran_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gfortran" CACHE PATH "Fortran compiler") IF(NOT CMAKE_Fortran_COMPILER)
SET(ANDROID_Fortran_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gfortran")
ELSE()
GET_FILENAME_COMPONENT(ANDROID_Fortran_COMPILER_PATH ${CMAKE_Fortran_COMPILER})
SET(ANDROID_Fortran_COMPILER ${ANDROID_Fortran_COMPILER_PATH})
ENDIF() ENDIF()
IF(NOT EXISTS ${ANDROID_Fortran_COMPILER})
SET(ANDROID_Fortran_COMPILER "")
ENDIF()
SET(CMAKE_C_COMPILER ${ANDROID_C_COMPILER} CACHE PATH "C compiler" FORCE)
SET(CMAKE_CXX_COMPILER ${ANDROID_CXX_COMPILER} CACHE PATH "CXX compiler" FORCE)
SET(CMAKE_Fortran_COMPILER ${ANDROID_Fortran_COMPILER} CACHE PATH "Fortran compiler" FORCE)
# Toolchain and ABI specific flags. # Toolchain and ABI specific flags.
SET(ANDROID_COMPILER_FLAGS "-ffunction-sections -fdata-sections -finline-limit=64") SET(ANDROID_COMPILER_FLAGS "-ffunction-sections -fdata-sections -finline-limit=64")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册