conan-io / conan

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

[bug] Cross-compiling for armv8 but Clang uses --target=armv7-none-linux-androideabi22 #9521

Closed n-eq closed 3 years ago

n-eq commented 3 years ago

Hello,

I am trying to cross-compile a library to both Android armv7 and armv8 platforms. The first one builds correctly, but when compiling for arch armv8 I noticed clang calls -march=armv7-a and --target=armv7-none-linux-androideabi22 in its command line (see the full log below).

Here's the profile I am using (Android NDK 23.0.7599858, api level 22)

include(default)
target_host=aarch64-linux-android
android_ndk=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858
api_level=22

[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=12
os=Android
os.api_level=$api_level
[build_requires]
[options]
[env]
PATH=[$android_ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin]
CHOST=$target_host
AR=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar
AS=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-as
RANLIB=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib
CC=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android22-clang
CXX=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android22-clang++
LD=$target_host-ld
STRIP=/Users/n-eq/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip
CONAN_CMAKE_TOOLCHAIN_FILE=$android_ndk/build/cmake/android.toolchain.cmake

Environment Details (include every applicable attribute)

Steps to reproduce (Include if Applicable)

I am using the following command: $ conan create . koinbra/android_arm64-v8a -s build_type=Release -o shared=False -o log4c:shared=False --profile android_arm64-v8a -j /Users/n-eq/Dev/akl/log4c/__liv/pkg_info/pkg_info_3.00.09/arm64_Release_static.json -tf None

Logs (Executed commands with output) (Include/Attach if Applicable)

conan.log

Is there something I'm doing wrong? I appreciate your help.

dmn-star commented 3 years ago

This happens because ANDROID_ABI is not set and CMake uses a default setting.

if(NOT ANDROID_ABI)
  set(ANDROID_ABI armeabi-v7a)
endif()

I don't know how to pass cmake parameters to android toolchain. And whether that is even possible with conan. As a workaround, you can create several toolchains files. E.g. arm64-v8a.android.toolchain.cmake

set(ANDROID_ABI arm64-v8a) include(path to /android.toolchain.cmake)

and then use it with conan CONAN_CMAKE_TOOLCHAIN_FILE=arm64-v8a.android.toolchain.cmake

dmn-star commented 3 years ago

On the other hand, here's another way you can build for Android. https://github.com/conan-io/conan-center-index/issues/4220#issuecomment-758486060

n-eq commented 3 years ago

Hi @dmn-star, many thanks for the comments. I didn't find the three lines you mention:

if(NOT ANDROID_ABI)
  set(ANDROID_ABI armeabi-v7a)
endif()

However, I solved the issue by adding ANDROID_ABI = "arm64-v8a" to CMake class's definitions field before building.

dmn-star commented 3 years ago

I didn't find the three lines you mention:

They are in android.toolchain.cmake.

android_toolchain
n-eq commented 3 years ago

They are in android.toolchain.cmake.

Yes, but apparently they were removed in NDK version 23.0.7599858, which is the one I'm using.