瀏覽代碼

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.
Brad King 9 年之前
父節點
當前提交
b22294bc41

+ 31 - 0
Modules/Platform/Android-Common.cmake

@@ -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()

+ 5 - 0
Modules/Platform/Android/abi-arm64-v8a-Clang.cmake

@@ -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)

+ 4 - 0
Modules/Platform/Android/abi-arm64-v8a-GNU.cmake

@@ -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)

+ 17 - 0
Modules/Platform/Android/abi-armeabi-Clang.cmake

@@ -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)

+ 16 - 0
Modules/Platform/Android/abi-armeabi-GNU.cmake

@@ -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)

+ 16 - 0
Modules/Platform/Android/abi-armeabi-v6-Clang.cmake

@@ -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)

+ 15 - 0
Modules/Platform/Android/abi-armeabi-v6-GNU.cmake

@@ -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)

+ 26 - 0
Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake

@@ -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)

+ 25 - 0
Modules/Platform/Android/abi-armeabi-v7a-GNU.cmake

@@ -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)

+ 5 - 0
Modules/Platform/Android/abi-common-Clang.cmake

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

+ 4 - 0
Modules/Platform/Android/abi-common.cmake

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

+ 5 - 0
Modules/Platform/Android/abi-mips-Clang.cmake

@@ -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)

+ 4 - 0
Modules/Platform/Android/abi-mips-GNU.cmake

@@ -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)

+ 5 - 0
Modules/Platform/Android/abi-mips64-Clang.cmake

@@ -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)

+ 4 - 0
Modules/Platform/Android/abi-mips64-GNU.cmake

@@ -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)

+ 5 - 0
Modules/Platform/Android/abi-x86-Clang.cmake

@@ -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)

+ 5 - 0
Modules/Platform/Android/abi-x86_64-Clang.cmake

@@ -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)