conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[question] find_package fails to find the package for Android build #14266

Open htonakanya opened 1 year ago

htonakanya commented 1 year ago

What is your question?

Hi there, I'm trying to create a Conan 2.0 package, and I'm encountering an issue when building the test package for Android. The sources are attached. The build is successful for other platforms such as Win64, iOS, MacOS, Linux(x86, x64, armv7, and armv8). However, I'm getting the following error:

CMake Error at CMakeLists.txt:4 (find_package):
  Could not find a package configuration file provided by "isa-l" with any of
  the following names:

    isa-lConfig.cmake
    isa-l-config.cmake

  Add the installation prefix of "isa-l" to CMAKE_PREFIX_PATH or set
  "isa-l_DIR" to a directory containing one of the above files.  If "isa-l"
  provides a separate development package or SDK, be sure it has been
  installed.

ERROR: isa-l/2.30.0_0@****/testing_NETW-263_demo (test package): Error in build() method, line 61
    cmake.configure()
    ConanException: Error 1 while executing cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/devel/****/workspace/isa-l_NETW-263_demo/test_package

I'm using the following configuration:

[settings]
arch=armv7
arch_build=x86_64
build_type=Release
compiler=clang
compiler.cppstd=17
compiler.libcxx=libc++
compiler.version=14
os=Android
os.api_level=22
os_build=Linux

[options]
[build_requires]
[env]
ANDROID_NDK=/opt/android-ndk
ANDROID_NDK_HOME=/opt/android-ndk
ANDROID_NDK_ROOT=/opt/android-ndk
CONAN_CMAKE_ANDROID_NDK=/opt/android-ndk
CONAN_CMAKE_SYSTEM_NAME=Android
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake
CONAN_MAKE_PROGRAM=/opt/android-ndk/prebuilt/linux-x86_64/bin/make
CXXFLAGS=-frtti -fexceptions
PATH=[/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin,/opt/android-ndk/prebuilt/linux-x86_64/bin]

cmake version 3.22.1
conan version 1.59.0
GNU Make 4.3

I would appreciate it if someone could review this configuration and let me know if I'm missing any Android-specific configuration or if this issue might be a bug.

I attempted to resolve the issue by including the isa-l-config.cmake file in the package, but unfortunately, it did not solve the problem. I would like to know if the isa-l-config.cmake file is the root cause of the issue, and if so, what should be the content of the file and where should it be placed within the package. Additionally, I'm curious to understand why the package builds successfully on other platforms but it needs this config.cmake file for Android.

Thanks in advance.

Have you read the CONTRIBUTING guide?

memsharded commented 1 year ago

Hi @htonakanya

Thanks for your question.

It seems you are using a Conan 1.X configuration in [env] that does nothing in Conan 2.0.

To define env-vars in Conan 2.0 (and also works in 1.X with the new generators like VirtualBuildEnv) is more like:

[buildenv]
ANDROID_NDK_HOME=(path)/opt/android-ndk

Also, all the CONAN_XXX variables are no longer used in the new generators (not only in 2.0, but also in the new generators in 1.X) like CMakeDeps and CMakeToolchain. The equivalent is done with conf like:

[conf]
tools.build:cxxflags=[...]
tools.gnu:make_program=...

Check https://docs.conan.io/2/reference/config_files/global_conf.html and the output of conan config list

It also seems that you are using the old cross-compile model with arch_build=x86_64 and os_build. But that should fail in Conan 2.0, there is something not right there.

htonakanya commented 1 year ago

Hi @memsharded,

Thank you for the reply, I'll try to fix the profiles and see whether it helps

vtkacenko commented 4 months ago

I suspect this is due to https://stackoverflow.com/questions/40054495/set-cmake-prefix-path-not-working-with-android-toolchain . At least in similar (or equivalent) use case for me with conan 2.x .

If one enables set(CMAKE_FIND_DEBUG_MODE ON) in the "test_package" CMakeLists.txt you can see in the output that the "CMAKE_PREFIX_PATH" contains the the "test_package/.../generators" directory where the CMake config for the main package is found.

Linux and Windows are fine (at least when cross-compile is not involved), but when Android toolchain is involved CMAKE_PREFIX_PATH gets ignored and find_package skips looking into "test_package/.../generators".

Adding the following in the test_package CMakeLists.txt makes find_package look into those directories when using Android toolchain:

if(ANDROID)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
endif(ANDROID)

alternatively specifying the directory explicitly also works (but one has to map it properly as it's dynamic based on Conan profile)

set(<main lib>_DIR <test_package/.../generator>)

I wonder if there is a cleaner way to address this (or at least streamline across many packages through the profiles/other Conan instrumentation).

Perhaps I am misusing Conan with this workflow and there's a better way. Open to suggestions!