[CMake] Need code review of my android toolchain file

Robert Dailey rcdailey.lists at gmail.com
Tue Apr 18 22:45:46 EDT 2017


I'm trying to follow best practices where I can, but the trouble is
I'm not aware of any. So I want to post my android.toolchain.cmake
file here, with the hope that I can get some pointers.

The main thing I want to understand is when it is appropriate to
require cache variables be set via command line argument (-D) or via
the toolchain file itself. Here is what is in my toolchain right now:


set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 15) # API level
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_STL_TYPE c++_static)
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)

string(REGEX REPLACE "\\\\" "/" ndk_path "$ENV{ANDROID_NDK}")
set(CMAKE_ANDROID_NDK ${ndk_path})

unset(ndk_path)



My idea here is to provide a different toolchain file per specific NDK
configuration. For example, I need to build my native libraries for
both x86 and ARM platforms, so I would use 2 CMAKE_BINARY_DIR, each
configured using a different toolchain:

x86 would use "android.toolchain.x86.cmake"
ARM would use "android.toolchain.arm.cmake"

Something like that. Is this best practice? What other advice would you offer?

Thanks in advance.


More information about the CMake mailing list