[CMake] Need code review of my android toolchain file

Robert Dailey rcdailey.lists at gmail.com
Fri Apr 21 09:45:24 EDT 2017


I guess the only feedback I really would like is if the path
normalization I'm doing for CMAKE_ANDROID_NDK is necessary (converting
backslashes to forward slashes). Will CMake translate the backslashes
properly?

Sometimes I use CMAKE_ANDROID_NDK in custom commands and custom
targets to build absolute paths to items in the NDK.

On Tue, Apr 18, 2017 at 9:45 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> 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