-
Notifications
You must be signed in to change notification settings - Fork 258
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
[BUG] CMake 3.21 + NDK r23 sets MINGW=1 in CMake #1581
Comments
@bradking hoping you can offer some advice here. It looks like the bug here is on the CMake side. If I've understood correctly, https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeDetermineCXXCompiler.cmake#L120 can only ever identify the default target of the compiler since the |
@DanAlbert you're correct. The logic here predates Clang or any notion of a compiler that supports more than one target. Therefore for Clang, it determines the default target. It can probably be updated to be aware of |
Thanks for confirming. Filed https://gitlab.kitware.com/cmake/cmake/-/issues/22647 We might be able to forcibly add the target argument to the compiler name so that CMake can't avoid it in compiler ID, but idk if that'll cause other problems. If that doesn't work we probably need to bump the CMake version that's required for using the non-legacy toolchain since this does render this path quite unusable on windows (and probably has subtle bugs elsewhere). Unfortunately that would mean effectively unshipping this feature for now since there obviously is no CMake version with the fix yet. |
Okay, looks like I can add this to the (new) toolchain file as a workaround: if(CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a)
set(ANDROID_LLVM_TRIPLE armv7-none-linux-androideabi)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a)
set(ANDROID_LLVM_TRIPLE aarch64-none-linux-android)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL x86)
set(ANDROID_LLVM_TRIPLE i686-none-linux-android)
elseif(CMAKE_ANDROID_ARCH_ABI STREQUAL x86_64)
set(ANDROID_LLVM_TRIPLE x86_64-none-linux-android)
else()
message(FATAL_ERROR "Invalid Android ABI: ${ANDROID_ABI}.")
endif()
set(CMAKE_C_COMPILER_TARGET "${ANDROID_LLVM_TRIPLE}${CMAKE_SYSTEM_VERSION}")
set(CMAKE_CXX_COMPILER_TARGET "${ANDROID_LLVM_TRIPLE}${CMAKE_SYSTEM_VERSION}") (thanks Brad for the hint on the other bug) It won't help anyone not using our toolchain file, but I wasn't having any luck finding another way to do it, and our toolchain file is the workflow with the regression, so I think that's probably fine? |
https://android-review.googlesource.com/c/platform/ndk/+/1827522 adds a workaround. |
So we can set |
Aha, thanks! I'll try that change tomorrow. I'd poked around in a few of the hooks but whatever I'd tried didn't work. Haven't really gotten familiar with the new system yet. |
Yeah.. sorry for all the mess I left here...😭 |
Not so much a mess as just I haven't taken the time to learn it yet :) |
Uploaded https://android-review.googlesource.com/c/platform/ndk/+/1829052 to apply the workaround better and https://android-review.googlesource.com/c/platform/ndk/+/1829092 to make it non-permanent, since Brad already has a fix up targeted at 3.22. We shouldn't submit the latter until the CMake fix actually lands so not on autosubmit. |
Hmm, although that breaks the legacy toolchain because apparently the hooks are loaded even in that case (where |
For now I've just opted that hook out. We may want to copy/paste that into all the hooks. |
The hooks are there so that the NDK can add logic before/after CMake's logic. The hooks themselves can start with some kind of |
Gotcha. That's what I've done, but wasn't sure if that was the intent. Thanks for confirming. |
If we don't explicitly set the target CMake will ID the compiler using the default target, causing MINGW to be defined when a Windows host is used. Test: added Bug: android/ndk#1581 Bug: https://gitlab.kitware.com/cmake/cmake/-/issues/22647 Change-Id: I3c4829eefd4fad6fbe85709c0d045b5e595b7b8e (cherry picked from commit 063d2b8)
Move this into the hook so it works for non-toolchain file users too. Thanks hhb for the pointer! Test: re-tested this on Windows Bug: android/ndk#1581 Change-Id: I39a1c8646d5853eea4bf557c6f6efa2ca5244cf2 (cherry picked from commit 02dfb02)
Test: added a FATAL_ERROR log and checked with a TOT CMake Bug: android/ndk#1581 Change-Id: Ic57323b1a4ac83ab02d29768932e67105c1fc2ed
Description
Observed behaviour:
When using CMake 3.21 with NDK r23 the compiler detection performed by CMake identifies NDK's Clang toolchain as MINGW.
This causes failures during the subsequent build because MINGW=1 implies that the Windows platform is targeted which means
Windows specific files and libraries might be included into the build.
Expected behaviour:
The
MINGW
variable is not defined in CMake.The expected behaviour can be restored either by setting
ANDROID_USE_LEGACY_TOOLCHAIN_FILE=1
or by manipulatingCMAKE_<LANG>_FLAGS
intc.txt
.Environment Details
The text was updated successfully, but these errors were encountered: