[cmake-developers] A goal for a simple Android toolchain file.

Eric Wing ewmailing at gmail.com
Sun Mar 23 15:43:42 EDT 2014


On 3/21/14, Stephen Kelly <steveire at gmail.com> wrote:
>
> Hi,
>
> I'd like it to be this easy to create an Android toolchain file:
>
>  set(CMAKE_SYSTEM_NAME Android)
>
>  set(ANDROID_SDK_ROOT "/home/stephen/android/android-sdk-linux/")
>  set(ANDROID_NDK_ROOT "/home/stephen/android/android-ndk-r9/")
>  set(ANDROID_NDK_PLATFORM "android-18")
>
>  set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
>  set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
>  set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
>  set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
>
>
> In order to do that, more stuff would need to be in the Android.cmake
> platform file.
>
> The platform file I'm currently experimenting with is here:
>
>  http://www.steveire.com/Android.cmake
>
> I would aim to obsolete the toolchain file which is commonly used for
> Android, which is here:
>
> http://code.google.com/p/android-cmake/source/browse/toolchain/android.toolchain.cmake
>
> I think part of the solution will need to be an interface in CMake for
> selecting an STL version. That will probably also be usable to select
> between libstdc++ and libc++ when using clang.
>
> Any comments on adding that kind of thing to the Android toolchain file?
>
> Thanks,
>
> Steve.

I have been using my fork of the Android-CMake (originally from
OpenCV) that you want to obsolete. My fork contains a lot of fixes to
deal with more recent NDK updates and more complicated requirements
that I have.
https://bitbucket.org/ewing/android-cmake

It is completely reliant on the Android "standalone toolchain"
technique which I vastly dislike, but it works and does solve the
problem of selecting between gcc 4.6, gcc 4.8, clang 3.3 (or whatever
versions they have), as well as dealing with stlport, gnu libstdc++,
clang libc++ and so forth. And I can at least brute force the multiple
architecture builds (armv5, armv7, x86) with this technique.


I am using it to build multiple projects, two of which I actually documented:
ALmixer
https://bitbucket.org/ewing/hello-android-almixer
JavaScriptCore (this one is a nightmare to build correctly and I will
be very unhappy with any new Android CMake toolchain that doesn't
handle this.)
https://github.com/appcelerator/hyperloop/wiki/Building-JavaScriptCore-for-Android

So while I'm not opposed to a brand new Android toolchain file, I want
to assert that it needs to be correct and it does need to handle a
variety of cases. So learn as much as you can from the existing ones.
In my fork, I spent a lot of time re-reverse-engineering the
standard/default Android flags passed to the compiler. OpenCV took too
many liberties with changing what Android passes normally which
resulted in unexpected/broken behavior for some of my other projects.
I think a very conservative, deferential approach should be taken.


My wish list is that it would not require the "standalone toolchain".
This would go a long way to simplifying the end-user experience. I
would also like it to understand multiple architectures which would
also go a long way to simplifying the end-user experience, though I'm
worried this might take deeper CMake changes.


>  set(ANDROID_SDK_ROOT "/home/stephen/android/android-sdk-linux/")
>  set(ANDROID_NDK_ROOT "/home/stephen/android/android-ndk-r9/")

It should also handle the semi-blessed/official Android environmental
variables like ANDROID_SDK_ROOT and ANDROID_NDK_ROOT so you don't have
to explicitly set them in CMake scripts.

>  set(ANDROID_NDK_PLATFORM "android-18")

It should automatically detect and use the latest Android target API
if it is not explicitly specified. There also may need to be a setting
to set the minSdkVersion, though that may fall outside of this since
CMake is currently limited to deal only with the NDK side.

I've ranted in multiple places about why the latest Android target API
should be used. My most recent public post is here:
https://forums.libsdl.org/viewtopic.php?p=42622&sid=ce5cec7c0379740c39bd3819a914b99d

Thanks,
Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/



More information about the cmake-developers mailing list