Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] How to use android-ndk (android_ndk_installer) in combination with classic CMake projects #4224

Closed
andioz opened this issue Jan 12, 2021 · 2 comments
Labels
question Further information is requested

Comments

@andioz
Copy link
Contributor

andioz commented Jan 12, 2021

Hi all,

I apologize for this very basic question, but I'm stuck and cannot find good documentation for solving my problem. Therefore I ask it here, maybe this is of interest for other developers too.

A sample project is here: hello-world.zip

I have a (quite large) project with CMake. I use conan of course, and typically I run conan export (for local recipes) and conan install from inside CMakeLists.txt. To simplify that let's say I run conan install before running CMake here:

conan install . -if build/linux-old -b missing -pr linux_profile
# linux_profile

include(default)

[settings]
compiler.libcxx=libstdc++11

[options]
[env]
# conanfile.py

import conans


class ProjectConan(conans.ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    requires = (
        "gtest/1.10.0"
    )

    default_options = (
        "gtest:shared=False"
    )

Then I run cmake, in CMakeLists.txt I use the typical Conan includes and functions:

cmake --build build/linux-old
# CMakeLists.txt

cmake_minimum_required(VERSION 3.18)
project(hello-world CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::gtest)

After that, building works an everything is fine for the Linux host platform. This is my happy path.


Now, I want to use the same project for Android. I use the old android_ndk_installer first because this is my current setup, but I want to change to the newer version when I've solved this one. Anyway it's included in the examples too (using the new build/host profile setup).

What I don't understand: all information for the NDK (ANDROID_ABI and CMAKE_TOOLCHAIN_FILE) is known by the android_ndk_installer, and I want to use this information. But how? I think I have to run now this commands, where I add the values for both settings to the CMake command line:

conan install . -if build/android-old -b missing -pr android_profile
cmake -B build/android-old \
  -D ANDROID_ABI=arm64-v8a \
  -D CMAKE_TOOLCHAIN_FILE=/home/zoufala/.conan/data/android_ndk_installer/r20/bincrafters/stable/package/84fc5086d5b84ea42507b9623275f83e74452fe1/build/cmake/android.toolchain.cmake

At least, it is what I do currently, with this hard-coded settings.

# android_profile

include(default)

[settings]
arch=armv8
compiler=clang
compiler.libcxx=libc++
compiler.version=8
os=Android
os.api_level=21

[build_requires]
android_ndk_installer/r20@bincrafters/stable

[options]
[env]

As you can see, I have to know the values for ANDROID_ABI and CMAKE_TOOLCHAIN_FILE here, but how to get it from android_ndk_installer?

I cannot change the project setup too much, because it is big and has many other constraints. But I hope there is a simple solution for this?

Is there a more detailed documentation you can recommend to me? https://docs.conan.io/en/latest/integrations/cross_platform/android.html doesn't explain much, just In case of using CMake, it will inject the appropriate toolchain file and set up the necessary CMake variables.

Many thanks in advance!

@andioz andioz added the question Further information is requested label Jan 12, 2021
@andioz
Copy link
Contributor Author

andioz commented Jan 12, 2021

I created a repo with the example code: https://github.com/andioz/conan-cmake-multiplatform

@andioz
Copy link
Contributor Author

andioz commented Jan 13, 2021

I found an interesting issue: conan-io/conan#2956

Would be the usage of virtualenv and/or CMakeToolchain generators be the way to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant