Android LTO: need a way to specify '*-gcc-ar' instead of '*-ar'
Hi,
I'm creating Android toolchain with LTO support. This configuration works fine for me on Linux:
# android.cmake
set(ANDROID_NDK "$ENV{ANDROID_NDK_r10e}")
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_CXX_FLAGS_INIT "-flto" CACHE STRING "")
set(CMAKE_C_FLAGS_INIT "-flto" CACHE STRING "")
set(
CMAKE_AR
"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-ar"
CACHE
PATH
""
FORCE
)
set(CMAKE_RANLIB "/bin/true" CACHE PATH "" FORCE)
# CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(foo)
add_library(a STATIC a.cpp)
add_executable(b main.cpp)
target_link_libraries(b PUBLIC a)
add_library(c SHARED main.cpp)
target_link_libraries(c PUBLIC a)
However as you may noticed I have to hardcode value of CMAKE_AR
because variables like CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG
will be available only later. This prevents generalization. What will be the best way of switching from *-ar
to *-gcc-ar
? I'm thinking about CMAKE_ANDROID_USE_GCC_AR
.