conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
949 stars 1.74k forks source link

[question] How can we use android-ndk with CMakeToolchain generator? #5179

Open hsuanguo opened 3 years ago

hsuanguo commented 3 years ago

Hi

I am quite confused and can't find a related document, I know that now we have CMakeToolchain and the new two-profile way for cross building, ideally what I tried to achieve is(android for example):

include(default)
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=9
os=Android
os.api_level=24

[build_requires]
android-ndk/r21d

[options]
[env]

[settings] compiler.libcxx=libstdc++11

[options] [env]


- Lastly, a conanfile.txt for the project

[requires] hello_pkg1/1.0.0@my_pkgs/test hello_pkg2/2.0.0@my_pkgs/test

[build_requires] android-ndk/r21d

[generators] cmake_find_package_multi CMakeToolchain

[options] [imports]


My thought was, with the 2 profiles, and the CMakeToolchain I should be able to build my project without installing the NDK on the build machine,

without `CMakeToolchain`, it works quite well:

conan install ../conanfile.txt --profile:build=linux-x86_x64-build-default.txt --profile:host=android-armv8-clang9-api24_release.txt --build=missing


I can see both  `hello_pkg1` `hello_pkg2` were built and cmake targets files are generated, however, with the `CMakeToolchain`, I got the following error:

ERROR: Error in generator 'CMakeToolchain': Cannot find ANDROID_NDK (ndk-build) in the PATH


I know that I can invoke the toolchain in the NDK package manually,

cmake -DCMAKE_TOOLCHAINFILE=/Users/a4z/.conan/data/android-ndk/r21d//_/package/46f53f156846659bf39ad6675fa0ee8156e859fe/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 ..



but it is it would be much smoother if we can use CMakeToolchain and use` conantoolchain.cmake` instead.

Thanks.
memsharded commented 3 years ago

Hi @hsuanguo

The CMakeToolchain is currently ongoing development, and new changes will be released in Conan 1.36: https://github.com/conan-io/conan/pull/8749.

As you can see the new default way will use the AndroidNDK provided cmake, which is simpler and robust. If your question is about the ConanCenter android-ndk package, probably this is something that we should consider also somehow in the CMakeToolchain feature, not only here in conan-center-index android-ndk recipe.

hsuanguo commented 3 years ago

Thanks for the explanation, great work, I am looking forward to it.

Yeah, it was just that I felt it's one step from great :)

kenfred commented 11 months ago

I see that this is supported now, although still indicated to be "experimental".

I'm still not sure how to get this to work. Following the doc above, I keep getting errors like: CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.

This points to something related to a note under a non-CMakeToolchain Generator technique.

Can you provide a clear example of build and host profiles to cross-compile from windows to Android while using the CMakeToolchain generator? Also, I'm using Conan 1.59, not Conan 2.

Thanks!