[cmake-developers] Android variables

Florent Castelli florent.castelli at gmail.com
Fri Nov 11 19:21:11 EST 2016


On 10/11/2016 16:05, Ruslan Baratov via cmake-developers wrote:
> Hi,
>
> I wonder if it's possible to introduce next variables describing Android
> tools:
> * C preprocessor. Similar to CMAKE_CXX_COMPILER the variable that will
> contain the path to preprocessor. Example:
>   * CMAKE_CXX_COMPILER =
> <ndk-root>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
>   * CMAKE_C_PREPROCESSOR =
> <ndk-root>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp
> * ANDROID_TOOLCHAIN_MACHINE_NAME. In fact I'm not sure what this
> variable mean but it's an important part of move from taka-no-me
> toolchain to CMake 3.7. I guess it's like
>   * CMAKE_CXX_COMPILER =
> <ndk-root>/toolchains/${ANDROID_TOOLCHAIN_MACHINE_NAME}-4.9/prebuilt/linux-x86_64/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++
>
> Of course if I'm not missing something and they are not already somewhere :)
>
> Ruslo

How about ${CMAKE_C/CXX_COMPILER} -E to call the preprocessor? Calling 
it directly is kind of dangerous though since you will probably be 
missing the proper language information and other options that might 
affect the predefined preprocessor defines. gcc has different binaries 
for different target archs and has some defines baked in, but this won't 
apply to Clang that uses only one binary and a target triple. You'll 
also lose the c/c++ language definition (unless you pass -x c++), 
language standard in use...

gcc (or clang) are just "drivers". They will call the proper programs 
automatically. Either the preprocessor, the compiler (cc1) or the 
linker, so you should be able to do everything with it directly!

As for the ANDROID_TOOLCHAIN_MACHINE_NAME that is used for gcc prefix, 
it shouldn't be needed. If you rely on gcc, you should investigate on 
using Clang which is the supported compiler now in the NDK. What is your 
exact usage of the variable?


/Florent



More information about the cmake-developers mailing list