Android: Populate compiler flags for current ABI

Initialize the CMAKE_{C,CXX}_FLAGS{,_<CONFIG>} cache entries with
flags for each ABI as specified by NDK toolchain `setup.mk` files.
This commit is contained in:
Brad King 2016-06-02 15:11:42 -04:00
parent b6a3102a9f
commit b22294bc41
17 changed files with 192 additions and 0 deletions

View File

@ -17,5 +17,36 @@ if(__ANDROID_COMPILER_COMMON)
endif()
set(__ANDROID_COMPILER_COMMON 1)
# The NDK toolchain configuration files at:
#
# <ndk>/[build/core/]toolchains/*/setup.mk
#
# contain logic to set TARGET_CFLAGS and TARGET_LDFLAGS (and debug/release
# variants) to tell their build system what flags to pass for each ABI.
# We need to produce the same flags here to produce compatible binaries.
# We initialize these variables here and set them in the compiler-specific
# modules that include this one. Then we use them in the macro below when
# it is called.
set(_ANDROID_ABI_INIT_CFLAGS "")
set(_ANDROID_ABI_INIT_CFLAGS_DEBUG "")
set(_ANDROID_ABI_INIT_CFLAGS_RELEASE "")
set(_ANDROID_ABI_INIT_LDFLAGS "")
macro(__android_compiler_common lang)
if(_ANDROID_ABI_INIT_CFLAGS)
string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_ANDROID_ABI_INIT_CFLAGS}")
endif()
if(_ANDROID_ABI_INIT_CFLAGS_DEBUG)
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " ${_ANDROID_ABI_INIT_CFLAGS_DEBUG}")
endif()
if(_ANDROID_ABI_INIT_CFLAGS_RELEASE)
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}")
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " ${_ANDROID_ABI_INIT_CFLAGS_RELEASE}")
endif()
if(_ANDROID_ABI_INIT_LDFLAGS)
foreach(t EXE SHARED MODULE)
string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " ${_ANDROID_ABI_INIT_LDFLAGS}")
endforeach()
endif()
endmacro()

View File

@ -1,3 +1,8 @@
# <ndk>/build/core/toolchains/aarch64-linux-android-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "aarch64-none-linux-android")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,6 @@
# <ndk>/build/core/toolchains/aarch64-linux-android-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1,3 +1,20 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "armv5te-none-linux-androideabi")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv5te"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -msoft-float"
" -mtune=xscale"
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,18 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv5te"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -msoft-float"
" -mtune=xscale"
" -fpic"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1,3 +1,19 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "armv6-none-linux-androideabi")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv6"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -mfloat-abi=softfp"
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,17 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv6"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -mfloat-abi=softfp"
" -fpic"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1,3 +1,29 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "armv7-none-linux-androideabi")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv7-a"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
if(CMAKE_ANDROID_ARM_NEON)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=neon")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=vfpv3-d16")
endif()
string(APPEND _ANDROID_ABI_INIT_LDFLAGS
" -Wl,--fix-cortex-a8"
)
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -mfloat-abi=softfp"
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,27 @@
# <ndk>/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -march=armv7-a"
)
if(CMAKE_ANDROID_ARM_MODE)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -marm")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mthumb")
endif()
if(CMAKE_ANDROID_ARM_NEON)
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=neon")
else()
string(APPEND _ANDROID_ABI_INIT_CFLAGS " -mfpu=vfpv3-d16")
endif()
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -mfloat-abi=softfp"
" -fpic"
)
string(APPEND _ANDROID_ABI_INIT_LDFLAGS
" -Wl,--fix-cortex-a8"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1 +1,6 @@
string(APPEND _ANDROID_ABI_INIT_CFLAGS
#" -Wno-invalid-command-line-argument"
#" -Wno-unused-command-line-argument"
)
include(Platform/Android/abi-common)

View File

@ -0,0 +1,4 @@
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -funwind-tables"
" -no-canonical-prefixes"
)

View File

@ -1,3 +1,8 @@
# <ndk>/build/core/toolchains/mipsel-linux-android-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "mipsel-none-linux-android")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,6 @@
# <ndk>/build/core/toolchains/mipsel-linux-android-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1,3 +1,8 @@
# <ndk>/build/core/toolchains/mips64el-linux-android-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "mips64el-none-linux-android")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,2 +1,6 @@
# <ndk>/build/core/toolchains/mips64el-linux-android-4.9/setup.mk
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fpic"
)
include(Platform/Android/abi-common-GNU)

View File

@ -1,3 +1,8 @@
# <ndk>/build/core/toolchains/x86-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "i686-none-linux-android")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fPIC"
)
include(Platform/Android/abi-common-Clang)

View File

@ -1,3 +1,8 @@
# <ndk>/build/core/toolchains/x86_64-clang/setup.mk
set(_ANDROID_ABI_CLANG_TARGET "x86_64-none-linux-android")
string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -fPIC"
)
include(Platform/Android/abi-common-Clang)