-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Fix android ndk clang #21222
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
Fix android ndk clang #21222
Changes from all commits
5e2a675
077ad28
6367b06
f2eb05f
02e7ba7
bd5de96
eec092c
0920613
854ca58
1ba1b4f
00ad9dc
1b1fbdc
632c5a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,8 @@ macro(z_vcpkg_determine_autotools_host_cpu out_var) | |
| endif() | ||
| if(host_arch MATCHES "(amd|AMD)64") | ||
| set(${out_var} x86_64) | ||
| elseif(host_arch MATCHES "(x|X)86_64") | ||
| set(${out_var} x86_64) | ||
| elseif(host_arch MATCHES "(x|X)86") | ||
| set(${out_var} i686) | ||
| elseif(host_arch MATCHES "^(ARM|arm)64$") | ||
|
|
@@ -316,7 +318,7 @@ function(vcpkg_configure_make) | |
| # Only for ports using autotools so we can assume that they follow the common conventions for build/target/host | ||
| if(CMAKE_HOST_WIN32) | ||
| set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-mingw32") # This is required since we are running in a msys | ||
| # shell which will be otherwise identified as ${BUILD_ARCH}-pc-msys | ||
| # shell which will be otherwise identified as ${BUILD_ARCH}-pc-msys | ||
| endif() | ||
| if(NOT TARGET_ARCH MATCHES "${BUILD_ARCH}" OR NOT CMAKE_HOST_WIN32) # we don't need to specify the additional flags if we build nativly, this does not hold when we are not on windows | ||
| string(APPEND arg_BUILD_TRIPLET " --host=${TARGET_ARCH}-pc-mingw32") # (Host activates crosscompilation; The name given here is just the prefix of the host tools for the target) | ||
|
|
@@ -465,6 +467,55 @@ function(vcpkg_configure_make) | |
| endif() | ||
| endif() | ||
|
|
||
| # Android - cross-compiling support | ||
| if(VCPKG_TARGET_IS_ANDROID) | ||
| if (VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID MATCHES "^Clang$") | ||
| string(REPLACE "-static-libstdc++" "-lc++_static" VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES ${VCPKG_DETECTED_CMAKE_CXX_STANDARD_LIBRARIES}) | ||
|
|
||
| if (DEFINED ENV{ANDROID_API_LEVEL}) | ||
| set(ANDROID_API_LEVEL $ENV{ANDROID_API_LEVEL} CACHE STRING "") | ||
| else() | ||
| set(ANDROID_API_LEVEL ${VCPKG_DETECTED_CMAKE_SYSTEM_VERSION} CACHE STRING "") | ||
| endif() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if respecting
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes, it would be. Since different API level may have different ABI, especially for the libc++. If one library is compiled with ANDROID_API_LEVEL equals 21, but others with 23, for example. They could not be linked into the final .so file.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why we should consider |
||
|
|
||
| if (arg_DETERMINE_BUILD_TRIPLET OR NOT arg_BUILD_TRIPLET) | ||
| if(VCPKG_HOST_IS_WINDOWS) | ||
| z_vcpkg_determine_autotools_host_cpu(BUILD_ARCH) # machine you are building on => --build= | ||
| z_vcpkg_determine_host_mingw(BUILD_MINGW) | ||
| set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-${BUILD_MINGW}") # This is required since we are running in a msys | ||
| # shell which will be otherwise identified as ${BUILD_ARCH}-pc-msys | ||
| elseif(VCPKG_HOST_IS_OSX) | ||
| z_vcpkg_determine_autotools_host_arch_mac(BUILD_ARCH) # machine you are building on => --build= | ||
| set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-apple-darwin${VCPKG_DETECTED_CMAKE_HOST_SYSTEM_VERSION}") | ||
| elseif(VCPKG_HOST_IS_LINUX) | ||
| z_vcpkg_determine_autotools_host_cpu(BUILD_ARCH) # machine you are building on => --build= | ||
| set(arg_BUILD_TRIPLET "--build=${BUILD_ARCH}-pc-linux-gnu") | ||
| endif() | ||
|
|
||
| z_vcpkg_determine_autotools_target_cpu(TARGET_ARCH) | ||
| if (TARGET_ARCH MATCHES "armv7-a") | ||
| string(APPEND arg_BUILD_TRIPLET " --host=arm-linux-androideabi") | ||
| else() | ||
| string(APPEND arg_BUILD_TRIPLET " --host=${TARGET_ARCH}-linux-android") | ||
| endif() | ||
| endif() | ||
| debug_message("Using make triplet: ${arg_BUILD_TRIPLET}") | ||
|
|
||
| if (TARGET_ARCH MATCHES "armv7-a") | ||
| string(APPEND configure_env " CC=armv7a-linux-androideabi${ANDROID_API_LEVEL}-clang") | ||
| string(APPEND configure_env " CXX=armv7a-linux-androideabi${ANDROID_API_LEVEL}-clang++") | ||
| else() | ||
| string(APPEND configure_env " CC=${TARGET_ARCH}-linux-android${ANDROID_API_LEVEL}-clang") | ||
| string(APPEND configure_env " CXX=${TARGET_ARCH}-linux-android${ANDROID_API_LEVEL}-clang++") | ||
| endif() | ||
|
|
||
| string(APPEND configure_env " AR=llvm-ar") | ||
| string(APPEND configure_env " RANLIB=llvm-ranlib") | ||
| string(APPEND configure_env " READELF=llvm-readelf") | ||
| string(APPEND configure_env " STRIP=llvm-strip") | ||
|
Comment on lines
+504
to
+515
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simply no. Setup the toolchain correctly..... CC and CXX and the rest of the programs should be correctly setup by cmake.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the ENV{ANDROID_API_LEVEL} since I don't want to add another argument for vcpkg_configure_make. It needs more consideration about the general purpose. It seems that an argument is reasonable? One need to customize the ANDROID API LEVEL instead of the detected version.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the CC and CXX environment variables are the core patch of this PR. Without that, the autotools
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
but not in this way because it is too specific. If necessary there needs to be a simple branch which setups all progs correctly to the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The toolchain did not correctly setup by cmake since it was out of control. When reading config-x86-android-dbg-out.txt in buildtree//, I found that most cross-compile toolchains are grabbed from the system, not in the NDK. It won't work. So I need to manually specify the toolchain through configure_env.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that is not a problem for |
||
| endif() | ||
| endif() | ||
|
|
||
| # Cleanup previous build dirs | ||
| file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" | ||
| "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -8,7 +8,8 @@ list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_CROSSCOMPILING | |||
| CMAKE_SYSTEM_NAME | ||||
| CMAKE_HOST_SYSTEM_NAME | ||||
| CMAKE_SYSTEM_PROCESSOR | ||||
| CMAKE_HOST_SYSTEM_PROCESSOR) | ||||
| CMAKE_HOST_SYSTEM_PROCESSOR | ||||
| CMAKE_HOST_SYSTEM_VERSION) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
don't see why we should care about
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When cross-compile python3, one needs to specify the --build option and on osx, it will be x86_64-apple-darwin20.6.0, where 20.6.0 is the host system version in cmake. In other words, when cross-compile some libraries on osx, one may need that variable. Yes I will shrink it to CMAKE_HOST_SYSTEM_VERSION only.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that seems oddly specific to python3. The typically configure scripts don't care about anything after |
||||
| if(CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||||
| list(APPEND VCPKG_DEFAULT_VARS_TO_CHECK CMAKE_OSX_DEPLOYMENT_TARGET | ||||
| CMAKE_OSX_SYSROOT) | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| set(ANDROID_CPP_FEATURES "rtti exceptions" CACHE STRING "") | ||
| set(CMAKE_SYSTEM_NAME Android CACHE STRING "") | ||
| set(ANDROID_TOOLCHAIN clang CACHE STRING "") | ||
| set(ANDROID_NATIVE_API_LEVEL ${CMAKE_SYSTEM_VERSION} CACHE STRING "") | ||
| set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang CACHE STRING "") | ||
|
|
||
| if (DEFINED ENV{ANDROID_API_LEVEL}) | ||
| set(ANDROID_NATIVE_API_LEVEL $ENV{ANDROID_API_LEVEL} CACHE STRING "") | ||
| set(ANDROID_PLATFORM $ENV{ANDROID_API_LEVEL} CACHE STRING "") | ||
| else() | ||
| set(ANDROID_NATIVE_API_LEVEL ${CMAKE_SYSTEM_VERSION} CACHE STRING "") | ||
| set(ANDROID_PLATFORM ${CMAKE_SYSTEM_VERSION} CACHE STRING "") | ||
| endif() | ||
|
|
||
|
Comment on lines
+6
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without env passthrough in the triplet
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is why I add the ENV here. The first time I use it, the previous version only set the ANDROID_NATIVE_API_LEVEL with an empty value. I don't know how to fix this. |
||
| if (VCPKG_TARGET_TRIPLET MATCHES "^arm64-android") | ||
| set(ANDROID_ABI arm64-v8a CACHE STRING "") | ||
| elseif(VCPKG_TARGET_TRIPLET MATCHES "^armv6-android") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this should be wrong in the detected libraries. IIRC, the NDK's toolchain has variables to configure the C++ runtime. Can't we hook into chainloading and configuring this toolchain, and then leave the detected values untouched?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot answer this. I have tried to hook the
<VCPKG_ROOT>/scripts/toolchains/android.cmakefor adding some util variables, but it seems thatvcpkg_configure_make.cmakedo not reference that file. So I have to specify the ANDROID_API_LEVEL again. So I do not think it is easy to hook NDK's toolchain file to obtain the detected. Or if I could fully understand how to do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export should be done in the
CMakeLists.txtofvcpkg_get_cmake_varsso that meson and other buildsystems are also informed about the required flags.