[CMake] Need code review of my android toolchain file

Volker Enderlein volker.enderlein at ifm-chemnitz.de
Fri Apr 21 10:09:12 EDT 2017


Hi Robert,

I would use

file(TO_NATIVE_PATH "${_dir}" _dir) and file(TO_CMAKE_PATH "${_dir}" _dir)

hope that helps,

Cheers, Volker

Am 21/04/2017 um 15:45 schrieb Robert Dailey:
> 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.


-- 
Volker Enderlein                         Institut für Mechatronik e.V.
Phone: +49 (0)371 531 19651              Reichenhainer Strasse 88
Fax:   +49 (0)371 531 19699              D-09126 Chemnitz
Mail: volker.enderlein at ifm-chemnitz.de   www.ifm-chemnitz.de

Vorstand:
Prof. Dr.-Ing. Welf-Guntram Drossel (Vorsitz)
Dipl.-Ing. Heiko Freudenberg (Geschäftsführer)

Amtsgericht Chemnitz VR 713
Ust.-IdNr. DE 159285348



More information about the CMake mailing list