提交 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)
CACHE PATH "Folder holds the standalone toolchain of Android NDK")
ENDIF()
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"
"1. Download an Android NDK from"
" https://developer.android.com/ndk/downloads/index.html\n"
......@@ -65,11 +66,6 @@ ENDIF()
IF(NOT DEFINED ANDROID_ARM_MODE)
SET(ANDROID_ARM_MODE ON)
ENDIF()
IF(NOT DEFINED ANDROID_ARM_NEON)
SET(ANDROID_ARM_NEON ON)
ENDIF()
IF(NOT ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "thumb")
SET(ANDROID_ARM_MODE OFF)
SET(ANDROID_ARM_MODE_NAME "thumb")
......@@ -78,6 +74,10 @@ ELSEIF(ANDROID_ARM_MODE OR ANDROID_ARM_MODE STREQUAL "arm")
SET(ANDROID_ARM_MODE_NAME "arm")
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.1.0")
SET(CMAKE_SYSTEM_NAME "Linux")
......@@ -85,6 +85,7 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.7.0")
MESSAGE(WARNING "It is recommended to use CMake >= 3.7.0 (current version: "
"${CMAKE_VERSION}), when cross-compiling for Android.")
IF(ANDROID_STANDALONE_TOOLCHAIN)
SET(CMAKE_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot")
IF(NOT CMAKE_SYSTEM_VERSION)
......@@ -110,23 +111,45 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.7.0")
ENDIF()
ENDIF()
SET(ANDROID_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_NAME}-")
ENDIF()
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}gcc")
SET(CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gcc" CACHE PATH "C compiler")
# C compiler
IF(NOT CMAKE_C_COMPILER)
SET(ANDROID_C_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gcc")
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()
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}g++")
SET(CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}g++" CACHE PATH "CXX compiler")
# CXX compiler
IF(NOT CMAKE_CXX_COMPILER)
SET(ANDROID_CXX_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}g++")
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()
IF(EXISTS "${ANDROID_TOOLCHAIN_PREFIX}gfortran")
SET(CMAKE_Fortran_COMPILER "${ANDROID_TOOLCHAIN_PREFIX}gfortran" CACHE PATH "Fortran compiler")
# 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()
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.
SET(ANDROID_COMPILER_FLAGS "-ffunction-sections -fdata-sections -finline-limit=64")
SET(ANDROID_LINKER_FLAGS "-Wl,--gc-sections")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册