CMake issueshttps://gitlab.kitware.com/cmake/cmake/-/issues2023-11-28T17:21:54-05:00https://gitlab.kitware.com/cmake/cmake/-/issues/23320Android: CMake can't find ar tool during configuration on macOS host2023-11-28T17:21:54-05:00Yauheni KhnykinAndroid: CMake can't find ar tool during configuration on macOS hostHi.
I believe that this is CMake issue, not NDK.
My environment:
- MacOS Monterey 12.2.1
- Xcode 13.2.1
- Android Studio 2021.1.1 Patch 1
- Gradle 7.2 based project which uses Android Gradle Plugin 7.1.0
- NDK 23.1.7779620
- CMake 3.22...Hi.
I believe that this is CMake issue, not NDK.
My environment:
- MacOS Monterey 12.2.1
- Xcode 13.2.1
- Android Studio 2021.1.1 Patch 1
- Gradle 7.2 based project which uses Android Gradle Plugin 7.1.0
- NDK 23.1.7779620
- CMake 3.22.3
When I try to compile the project with **./gradlew assembleRelease** (this issues is not reproduced on Debug!) I see the following error:
```
FAILED: xxx/libminizip.a
: && /Applications/CMake.app/Contents/bin/cmake -E rm -f xxx/libminizip.a && /usr/bin/ar qc xxx/libminizip.a external/minizip/CMakeFiles/minizip.dir/ioapi.c.o external/minizip/CMakeFiles/minizip.dir/ioapi_mem.c.o external/minizip/CMakeFiles/minizip.dir/mztools.c.o external/minizip/CMakeFiles/minizip.dir/unzip.c.o external/minizip/CMakeFiles/minizip.dir/zip.c.o && /Users/yyyy/AndroidSDK/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ranlib xxx/libminizip.a && /Applications/CMake.app/Contents/bin/cmake -E touch xxx/libminizip.a && :
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: Unsupported triple for mach-o cpu type: thumbv7-none-linux-android21
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: Unsupported triple for mach-o cpu type: thumbv7-none-linux-android21
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: Unsupported triple for mach-o cpu type: thumbv7-none-linux-android21
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: Unsupported triple for mach-o cpu type: thumbv7-none-linux-android21
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: Unsupported triple for mach-o cpu type: thumbv7-none-linux-android21
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar: internal ranlib command failed
```
Obviously it uses **ar** tool from system (see /usr/bin/ar), not from NDK. CMakeCache.txt:
```
//Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar
```
Note: everything works if I specify **-DANDROID_USE_LEGACY_TOOLCHAIN_FILE=ON**.
android-legacy.toolchain.cmake contains following lines:
```
set(CMAKE_AR "${ANDROID_AR}" CACHE FILEPATH "Archiver")
set(CMAKE_RANLIB "${ANDROID_RANLIB}" CACHE FILEPATH "Ranlib")
set(CMAKE_STRIP "${ANDROID_STRIP}" CACHE FILEPATH "Strip")
```3.21.7Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/25281Android: Requesting C++23 support causes an error on Android with NDK r262023-09-28T09:50:40-04:00ZingamAndroid: Requesting C++23 support causes an error on Android with NDK r26The clang compiler in NDK r26 isn't actually an Clang 17 compiler and the following error is produces when cxx_std_23 compile feature is requested:
```txt
[1/2] Building CXX object CMakeFiles/myapplication.dir/native-lib.cpp.o
FAILED:...The clang compiler in NDK r26 isn't actually an Clang 17 compiler and the following error is produces when cxx_std_23 compile feature is requested:
```txt
[1/2] Building CXX object CMakeFiles/myapplication.dir/native-lib.cpp.o
FAILED: CMakeFiles/myapplication.dir/native-lib.cpp.o
/Users/-/Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android29 --sysroot=/Users/hristohristov/Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -Dmyapplication_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -std=gnu++23 -fPIC -MD -MT CMakeFiles/myapplication.dir/native-lib.cpp.o -MF CMakeFiles/myapplication.dir/native-lib.cpp.o.d -o CMakeFiles/myapplication.dir/native-lib.cpp.o -c /Users/hristohristov/AndroidStudioProjects/MyApplication2/app/src/main/cpp/native-lib.cpp
error: invalid value 'gnu++23' in '-std=gnu++23'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++20' for 'ISO C++ 2020 DIS' standard
note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
note: use 'c++2b' for 'Working draft for ISO C++ 2023 DIS' standard
note: use 'gnu++2b' for 'Working draft for ISO C++ 2023 DIS with GNU extensions' standard
ninja: build stopped: subcommand failed
```3.27.7Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/25004CMake 3.27.0-rc vcpkg regressions; UNIX changed for Android?2023-07-13T07:21:33-04:00Alexander NeumannCMake 3.27.0-rc vcpkg regressions; UNIX changed for Android?So I analyzed some of the android regressions in https://github.com/microsoft/vcpkg/pull/31931 and some of them seem to be related to
`if(UNIX)` which seems to no longer apply if `CMAKE_SYSTEM_NAME` is `Android`?So I analyzed some of the android regressions in https://github.com/microsoft/vcpkg/pull/31931 and some of them seem to be related to
`if(UNIX)` which seems to no longer apply if `CMAKE_SYSTEM_NAME` is `Android`?3.27.0Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/24975Android: Wrong 'ar' selected on Darwin hosts2023-06-08T10:44:49-04:00Dan AlbertAndroid: Wrong 'ar' selected on Darwin hostsSome time between CMake 3.22 and 3.26, CMake started incorrectly identifying the ar binary for Android targets from macOS hosts:
```bash
$ cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.co...Some time between CMake 3.22 and 3.26, CMake started incorrectly identifying the ar binary for Android targets from macOS hosts:
```bash
$ cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.26)
project(CMakeArTest C CXX)
if(APPLE)
message(FATAL_ERROR "should not be APPLE")
endif()
foreach(TEST_VAR CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_AR CMAKE_STRIP CMAKE_RANLIB)
if(NOT DEFINED "${TEST_VAR}")
message(FATAL_ERROR "${TEST_VAR} not set")
elseif(NOT ${TEST_VAR} MATCHES "${CMAKE_ANDROID_NDK}")
message(FATAL_ERROR "${TEST_VAR} (${${TEST_VAR}}) is outside the NDK (${CMAKE_ANDROID_NDK})")
else()
message(WARNING "${TEST_VAR} is ${${TEST_VAR}}")
endif()
endforeach()
$ mkdir build
$ cd build
$ cmake -DCMAKE_ANDROID_NDK=/Users/danalbert/Library/Android/sdk/ndk/25.2.9519653 -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 ..
-- Android: Targeting API '21' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 14.0.7
-- The CXX compiler identification is Clang 14.0.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/danalbert/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/danalbert/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at CMakeLists.txt:14 (message):
CMAKE_C_COMPILER is
/Users/danalbert/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
CMake Warning at CMakeLists.txt:14 (message):
CMAKE_CXX_COMPILER is
/Users/danalbert/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
CMake Error at CMakeLists.txt:12 (message):
CMAKE_AR (/usr/bin/ar) is outside the NDK
(/Users/danalbert/Library/Android/sdk/ndk/25.2.9519653)
-- Configuring incomplete, errors occurred!
```
("25.2.9519653" decodes to NDK r25c, downloadable at https://github.com/android/ndk/wiki)
I suspect https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7039 is the culprit. If you run that command with `--trace` you'll see something very odd:
```
/Applications/CMake.app/Contents/share/cmake-3.26/Modules/CMakeFindBinUtils.cmake(176): if(APPLE )
/Applications/CMake.app/Contents/share/cmake-3.26/Modules/CMakeFindBinUtils.cmake(181): list(APPEND _CMAKE_AR_NAMES llvm-ar )
```
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.4/Modules/CMakeFindBinUtils.cmake#L176-184
`APPLE` is evaluating to true despite `-DCMAKE_SYSTEM_NAME=Android`. It seems that at the time CMakeFindBinUtils.cmake is executed, the build target has not yet been set correctly.
ac2562afb3fda621854f4c3a470e36f10cf507b3 and a54e25b547989cb790bde61f9dfbb6775e8feb87 are related commits that might cause similar problems that are not yet released (I think).
See https://github.com/android/ndk/issues/1698 for more context if needed.3.27.0Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/23352Android: Does not support `Visual Studio 17 2022` yet?2023-04-26T10:28:46-04:00Craig HutchinsonAndroid: Does not support `Visual Studio 17 2022` yet?# Issue
When using CMake to build for Android with the `Visual Studio 17 2022` generator `CmakeError.log` state:
```
"Determining the sysroot for the Android NDK failed."
```
The CMake generated output includes this as the symptom:
```
...# Issue
When using CMake to build for Android with the `Visual Studio 17 2022` generator `CmakeError.log` state:
```
"Determining the sysroot for the Android NDK failed."
```
The CMake generated output includes this as the symptom:
```
1> [CMake] CMake Error at CMakeProject1/CMakeLists.txt:10 (target_compile_features):
1> [CMake] target_compile_features no known features for CXX compiler
1> [CMake]
1> [CMake] ""
1> [CMake]
1> [CMake] version .
```
# Diagnostics
Investigating this message takes you to the following check for Sysroot in `Android-Determine.cmake` which has check for `14-16` i.e. `17` is not apparently included?
https://github.com/Kitware/CMake/blob/7936fc65dc75ac089e60b66bc28eb16ef64e534d/Modules/Platform/Android-Determine.cmake#L48
# Reproducer
**NOTE: Path to SDK/NDK may need adjusting respectively**
[Android_CMake_VisualStudio17.zip](/uploads/7dc89e81b977c990f148128b2dda59f4/Android_CMake_VisualStudio17.zip)
CMakePreset:
```
{
"name": "android-msvc",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"architecture": {
"value": "arm64",
"strategy": "set"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_SYSTEM_NAME": "Android",
"CMAKE_SYSTEM_VERSION": "29",
"CMAKE_ANDROID_ARCH_ABI": "arm64-v8a",
"CMAKE_ANDROID_STL_TYPE": "c++_static",
"CMAKE_ANDROID_SDK": "C:/Microsoft/AndroidSDK/25",
"CMAKE_ANDROID_NDK": "C:/Microsoft/AndroidNDK/android-ndk-r21e"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
```https://gitlab.kitware.com/cmake/cmake/-/issues/24386Android: CMAKE_ANDROID_NDK_VERSION not defined with legacy NDK toolchain file2023-02-07T09:32:25-05:00shxykeAndroid: CMAKE_ANDROID_NDK_VERSION not defined with legacy NDK toolchain file`CMAKE_ANDROID_NDK_VERSION` is skipped when `CMAKE_SYSTEM_VERSION` equals 1
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.25.2/Modules/Platform/Android-Determine.cmake#L23
which will set the `-fuse-ld=gold`, cause link error
https:...`CMAKE_ANDROID_NDK_VERSION` is skipped when `CMAKE_SYSTEM_VERSION` equals 1
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.25.2/Modules/Platform/Android-Determine.cmake#L23
which will set the `-fuse-ld=gold`, cause link error
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.25.2/Modules/Compiler/Clang.cmake#L83
move `CMAKE_ANDROID_NDK_VERSION` to the top might solve this
```diff
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index 715f68bb4e..824e790d1d 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -11,6 +11,44 @@ if(CMAKE_ANDROID_NDK)
include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Determine.cmake OPTIONAL)
endif()
+if(CMAKE_ANDROID_NDK AND EXISTS "${CMAKE_ANDROID_NDK}/source.properties")
+ # Android NDK revision
+ # Possible formats:
+ # * r16, build 1234: 16.0.1234
+ # * r16b, build 1234: 16.1.1234
+ # * r16 beta 1, build 1234: 16.0.1234-beta1
+ #
+ # Canary builds are not specially marked.
+ file(READ "${CMAKE_ANDROID_NDK}/source.properties" _ANDROID_NDK_SOURCE_PROPERTIES)
+
+ set(_ANDROID_NDK_REVISION_REGEX
+ "^Pkg\\.Desc = Android NDK\nPkg\\.Revision = ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-beta([0-9]+))?")
+ if(NOT _ANDROID_NDK_SOURCE_PROPERTIES MATCHES "${_ANDROID_NDK_REVISION_REGEX}")
+ string(REPLACE "\n" "\n " _ANDROID_NDK_SOURCE_PROPERTIES "${_ANDROID_NDK_SOURCE_PROPERTIES}")
+ message(FATAL_ERROR
+ "Android: Failed to parse NDK revision from:\n"
+ " ${CMAKE_ANDROID_NDK}/source.properties\n"
+ "with content:\n"
+ " ${_ANDROID_NDK_SOURCE_PROPERTIES}")
+ endif()
+
+ set(_ANDROID_NDK_MAJOR "${CMAKE_MATCH_1}")
+ set(_ANDROID_NDK_MINOR "${CMAKE_MATCH_2}")
+ set(_ANDROID_NDK_BUILD "${CMAKE_MATCH_3}")
+ set(_ANDROID_NDK_BETA "${CMAKE_MATCH_5}")
+ if(_ANDROID_NDK_BETA STREQUAL "")
+ set(_ANDROID_NDK_BETA "0")
+ endif()
+ set(CMAKE_ANDROID_NDK_VERSION "${_ANDROID_NDK_MAJOR}.${_ANDROID_NDK_MINOR}")
+
+ unset(_ANDROID_NDK_SOURCE_PROPERTIES)
+ unset(_ANDROID_NDK_REVISION_REGEX)
+ unset(_ANDROID_NDK_MAJOR)
+ unset(_ANDROID_NDK_MINOR)
+ unset(_ANDROID_NDK_BUILD)
+ unset(_ANDROID_NDK_BETA)
+endif()
+
# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously
# implemented in the CMake VS IDE generators. Avoid interfering with
# that functionality for now.
@@ -228,44 +266,6 @@ if(CMAKE_ANDROID_NDK)
include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake" OPTIONAL RESULT_VARIABLE _INCLUDED_ABIS)
endif()
-if(CMAKE_ANDROID_NDK AND EXISTS "${CMAKE_ANDROID_NDK}/source.properties")
- # Android NDK revision
- # Possible formats:
- # * r16, build 1234: 16.0.1234
- # * r16b, build 1234: 16.1.1234
- # * r16 beta 1, build 1234: 16.0.1234-beta1
- #
- # Canary builds are not specially marked.
- file(READ "${CMAKE_ANDROID_NDK}/source.properties" _ANDROID_NDK_SOURCE_PROPERTIES)
-
- set(_ANDROID_NDK_REVISION_REGEX
- "^Pkg\\.Desc = Android NDK\nPkg\\.Revision = ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-beta([0-9]+))?")
- if(NOT _ANDROID_NDK_SOURCE_PROPERTIES MATCHES "${_ANDROID_NDK_REVISION_REGEX}")
- string(REPLACE "\n" "\n " _ANDROID_NDK_SOURCE_PROPERTIES "${_ANDROID_NDK_SOURCE_PROPERTIES}")
- message(FATAL_ERROR
- "Android: Failed to parse NDK revision from:\n"
- " ${CMAKE_ANDROID_NDK}/source.properties\n"
- "with content:\n"
- " ${_ANDROID_NDK_SOURCE_PROPERTIES}")
- endif()
-
- set(_ANDROID_NDK_MAJOR "${CMAKE_MATCH_1}")
- set(_ANDROID_NDK_MINOR "${CMAKE_MATCH_2}")
- set(_ANDROID_NDK_BUILD "${CMAKE_MATCH_3}")
- set(_ANDROID_NDK_BETA "${CMAKE_MATCH_5}")
- if(_ANDROID_NDK_BETA STREQUAL "")
- set(_ANDROID_NDK_BETA "0")
- endif()
- set(CMAKE_ANDROID_NDK_VERSION "${_ANDROID_NDK_MAJOR}.${_ANDROID_NDK_MINOR}")
-
- unset(_ANDROID_NDK_SOURCE_PROPERTIES)
- unset(_ANDROID_NDK_REVISION_REGEX)
- unset(_ANDROID_NDK_MAJOR)
- unset(_ANDROID_NDK_MINOR)
- unset(_ANDROID_NDK_BUILD)
- unset(_ANDROID_NDK_BETA)
-endif()
-
if(CMAKE_ANDROID_NDK)
# Identify the host platform.
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
```
Or use `ANDROID_NDK_REVISION` instead
```diff
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index 715f68bb4e..73baa13359 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -11,6 +11,10 @@ if(CMAKE_ANDROID_NDK)
include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Determine.cmake OPTIONAL)
endif()
+if(ANDROID_NDK_REVISION AND NOT CMAKE_ANDROID_NDK_VERSION)
+ set(CMAKE_ANDROID_NDK_VERSION "${ANDROID_NDK_REVISION}")
+endif()
+
# Support for NVIDIA Nsight Tegra Visual Studio Edition was previously
# implemented in the CMake VS IDE generators. Avoid interfering with
# that functionality for now.
```3.25.3Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/21772Android NDK22 with LTO enabled crash as gold linker is no longer available2023-02-06T17:24:18-05:00Christian MelchiorAndroid NDK22 with LTO enabled crash as gold linker is no longer availableAndroid NDK22 removed the gold linker and made lld the default. However, CMake forces the use of gold linker in https://github.com/Kitware/CMake/blob/af695cee7346fa0eee478f71952fd02f0df989cf/Modules/Compiler/Clang.cmake#L81
This is prob...Android NDK22 removed the gold linker and made lld the default. However, CMake forces the use of gold linker in https://github.com/Kitware/CMake/blob/af695cee7346fa0eee478f71952fd02f0df989cf/Modules/Compiler/Clang.cmake#L81
This is problematic as CMAKE_CXX_LINK_OPTIONS_IPO are appended after any other user flags, overriding any custom linker defined by either android.toolchain.cmake or the user.
This means that Android NDK22 CMake builds with LTO enabled crash, and right now the best work-around is something like:
```
STRING(REGEX REPLACE "-fuse-ld=gold" "" CMAKE_CXX_LINK_OPTIONS_IPO ${CMAKE_CXX_LINK_OPTIONS_IPO})
```
But this seems rather suboptimal.
I'm not sure whether this should be fixed in the Android NDK or CMake, but I created a similar issue on the NDK side https://github.com/android/ndk/issues/14443.20.0https://gitlab.kitware.com/cmake/cmake/-/issues/22647Android: MINGW defined with Clang compiler on Windows host2023-02-06T16:59:59-05:00Ghost UserAndroid: MINGW defined with Clang compiler on Windows hostOriginally filed at https://github.com/android/ndk/issues/1581
The issue is that the compiler ID code that does compiler id (https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.2/Modules/CMakeDetermineCXXCompiler.cmake#L120-132) does no...Originally filed at https://github.com/android/ndk/issues/1581
The issue is that the compiler ID code that does compiler id (https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.2/Modules/CMakeDetermineCXXCompiler.cmake#L120-132) does not account for `CMAKE_${lang}_COMPILER_TARGET` so it is only able to identify the default target when using Clang. This means that for a configuration that targets android will identify as MINGW when building on Windows because the _default_ clang target on that host is windows.
Issue-created-by: @danalbert3.22.0Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/23830Android: find_package(JNI) found wrong library2022-12-28T18:39:36-05:00huangqinjinAndroid: find_package(JNI) found wrong library## Environment
- Host OS: Linux
- CMake: 3.24
- Android NDK: 25.0.8775105
- Android API Level: 26
## CMakeLists.txt
```cmake
cmake_minimum_required(VERSION 3.24)
project(Test)
message(STATUS "CMAKE_ANDROID_API=${CMAKE_ANDROID_API}")
...## Environment
- Host OS: Linux
- CMake: 3.24
- Android NDK: 25.0.8775105
- Android API Level: 26
## CMakeLists.txt
```cmake
cmake_minimum_required(VERSION 3.24)
project(Test)
message(STATUS "CMAKE_ANDROID_API=${CMAKE_ANDROID_API}")
find_package(JNI)
```
## Issue 1: x86_64
```shell
$ cmake .. --debug-find-var=JAVA_NativeHelper_LIBRARY -DCMAKE_ANDROID_NDK=${ANDROID_NDK_HOME} -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=26 -DCMAKE_ANDROID_ARCH_ABI=x86_64
-- Could NOT find JNI (missing: NativeHelper) (found version "25.0.8775105")
```
NativeHelper is only available since API 31, CMake should not try to find it in this case. The problem seems that [CMAKE_ANDROID_API](https://cmake.org/cmake/help/v3.24/variable/CMAKE_ANDROID_API.html) is never set.
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.24.0/Modules/FindJNI.cmake#L110
## Issue 2: x86
```shell
$ cmake .. --debug-find-var=JAVA_NativeHelper_LIBRARY -DCMAKE_ANDROID_NDK=${ANDROID_NDK_HOME} -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=26 -DCMAKE_ANDROID_ARCH_ABI=x86
CMake Debug Log at /usr/share/cmake/Modules/FindJNI.cmake:498 (find_library):
find_library(JAVA_NativeHelper_LIBRARY) added replacement path
/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/i686-linux-android/32/
to PATH_SUFFIXES for architecture suffix '32'
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
The item was found at
/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/i686-linux-android/32/libnativehelper.so
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
-- Found JNI: /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include (found version "25.0.8775105") found components: NativeHelper
```
CMake searches `sysroot/usr/lib/i686-linux-android/32/`, But here `32` is the API level.3.24.3https://gitlab.kitware.com/cmake/cmake/-/issues/24196Android: CMake 3.25.0 sets LINUX true2022-12-06T08:39:31-05:00Robert NevalaAndroid: CMake 3.25.0 sets LINUX trueSetting global variable LINUX in CMake 3.25.0 is causing problems with Android builds on OSX
CMake 3.25.0 considers ANDROID build on OSX a LINUX target due to the compiler in the android toolchain (`__linux__`).
With build systems that ...Setting global variable LINUX in CMake 3.25.0 is causing problems with Android builds on OSX
CMake 3.25.0 considers ANDROID build on OSX a LINUX target due to the compiler in the android toolchain (`__linux__`).
With build systems that handle Linux and Android build targets separately this will cause a lot of problems.
Added following to showcase the problem:
```
message("#### before project() LINUX = ${LINUX}")
project(${PROJ_NAME})
message("#### after project() LINUX = ${LINUX}")
```
Outputs the following:
```
C/C++: debug|arm64-v8a :#### before project() LINUX =
C/C++: debug|arm64-v8a :#### after project() LINUX = 1
```
Starting to set this flag now is a bit odd choice as many build systems have already built handling for this case.
In our case we have a lot of logic using LINUX & ANDROID separately.3.25.1Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/16665Android LTO: need a way to specify '*-gcc-ar' instead of '*-ar'2022-07-21T06:11:41-04:00Ruslan Baratovx@ruslo.devAndroid LTO: need a way to specify '*-gcc-ar' instead of '*-ar'Hi,
I'm creating Android toolchain with LTO support. This configuration works fine for me on Linux:
```cmake
# android.cmake
set(ANDROID_NDK "$ENV{ANDROID_NDK_r10e}")
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_CXX_FLAGS_INIT "-flto" ...Hi,
I'm creating Android toolchain with LTO support. This configuration works fine for me on Linux:
```cmake
# android.cmake
set(ANDROID_NDK "$ENV{ANDROID_NDK_r10e}")
set(CMAKE_SYSTEM_NAME "Android")
set(CMAKE_CXX_FLAGS_INIT "-flto" CACHE STRING "")
set(CMAKE_C_FLAGS_INIT "-flto" CACHE STRING "")
set(
CMAKE_AR
"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-ar"
CACHE
PATH
""
FORCE
)
set(CMAKE_RANLIB "/bin/true" CACHE PATH "" FORCE)
```
```cmake
# CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(foo)
add_library(a STATIC a.cpp)
add_executable(b main.cpp)
target_link_libraries(b PUBLIC a)
add_library(c SHARED main.cpp)
target_link_libraries(c PUBLIC a)
```
However as you may noticed I have to hardcode value of `CMAKE_AR` because variables like `CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG` will be available only later. This prevents generalization. What will be the best way of switching from `*-ar` to `*-gcc-ar`? I'm thinking about `CMAKE_ANDROID_USE_GCC_AR`.Ruslan Baratovx@ruslo.devRuslan Baratovx@ruslo.devhttps://gitlab.kitware.com/cmake/cmake/-/issues/22886Android: Target API Level not set in Visual Studio2022-06-09T09:23:11-04:00Francisco GarciaAndroid: Target API Level not set in Visual StudioHi CMake team!
I have created a very simple NDK project, and I want to build it using the **android-24** API for **armeabi-v7a** and **arm64-v8a**
```
cmake -G "Visual Studio 16 2019" ^
-A ARM ^
--toolchain %ANDROID_NDK%\bu...Hi CMake team!
I have created a very simple NDK project, and I want to build it using the **android-24** API for **armeabi-v7a** and **arm64-v8a**
```
cmake -G "Visual Studio 16 2019" ^
-A ARM ^
--toolchain %ANDROID_NDK%\build\cmake\android.toolchain.cmake ^
-S . ^
-B armeabi-v7a ^
-DANDROID_ABI="armeabi-v7a" ^
-DANDROID_NATIVE_API_LEVEL="android-24" ^
-DANDROID_API="24"
cmake -G "Visual Studio 16 2019" ^
-A ARM64 ^
--toolchain %ANDROID_NDK%\build\cmake\android.toolchain.cmake ^
-S . ^
-B arm64-v8a ^
-DANDROID_ABI="arm64-v8a" ^
-DANDROID_NATIVE_API_LEVEL="android-24" ^
-DANDROID_API="24"
```
If you open both VS solutions, the **Target API Level** has not been set, which causes compilation/linking problems in projects that must use this API.
![ARM64](/uploads/bd06c9aa6c297b192668f1510d047dfe/ARM64.png)
![ARM](/uploads/918471f6da997e814ec85746eba39468/ARM.png)
If you edit by hand Target API Level value, a new line appears in VisualStudio solution file, and now projects compile/link with the correct API.
![Edited_By_Hand](/uploads/07dc444ec3cc98b396bd48010fd42298/Edited_By_Hand.png)
![Edited_By_Hand2](/uploads/a34daae64cb6a2b6b75d42b4c7578043/Edited_By_Hand2.png)
Is there any way to modify **Target API Level** from CMake?
It's a bug?
I attach a simple project for testing. Just run `script.bat` inside dir.
[android_src.zip](/uploads/db233364e03bed79606b48b5e60f9a98/android_src.zip)3.24.0https://gitlab.kitware.com/cmake/cmake/-/issues/22021Android Gradle Plugin regression with CMake 3.20.02022-03-11T09:02:32-05:00Ryan TremblayAndroid Gradle Plugin regression with CMake 3.20.0CMake 3.20.0 was recently released, and Azure DevOps Linux agents and GitHub Mac agents have upgraded to this version (from 3.19.6). In both of these cases, builds for multiple of our projects have started failing with the following nota...CMake 3.20.0 was recently released, and Azure DevOps Linux agents and GitHub Mac agents have upgraded to this version (from 3.19.6). In both of these cases, builds for multiple of our projects have started failing with the following notable build log snippets:
```
CMakeLists.txt : C/C++ release|armeabi-v7a : Start JSON generation. Platform version: 21 min SDK version: armeabi-v7a
CMakeLists.txt : C/C++ release|armeabi-v7a : Gradle local properties file not found at /Users/runner/work/BabylonReactNative/BabylonReactNative/Apps/Playground/android/local.properties
CMakeLists.txt : C/C++ release|armeabi-v7a : Trying to locate CMake in local SDK repository.
CMakeLists.txt : C/C++ release|armeabi-v7a : CMake '3.10.2' found in SDK could not satisfy requested version '3.13.2' because it was lower.
CMakeLists.txt : C/C++ release|armeabi-v7a : Requested CMake version 3.13.2 was not satisfied by default version 3.10.2 for this Android Gradle Plugin
CMakeLists.txt : C/C++ release|armeabi-v7a : Trying to locate CMake in PATH.
CMakeLists.txt : C/C++ release|armeabi-v7a : - CMake found in PATH at '/usr/local' had version '3.20.0'
...
CMakeLists.txt : C/C++ release|armeabi-v7a : rebuilding JSON /Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/android/.cxx/cmake/release/armeabi-v7a/android_gradle_build.json due to:
CMakeLists.txt : C/C++ release|armeabi-v7a : - expected json /Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/android/.cxx/cmake/release/armeabi-v7a/android_gradle_build.json file is not present, will remove stale json folder
CMakeLists.txt : C/C++ release|armeabi-v7a : - missing previous command file /Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/android/.cxx/cmake/release/armeabi-v7a/build_command.txt, will remove stale json folder
CMakeLists.txt : C/C++ release|armeabi-v7a : - command changed from previous, will remove stale json folder
CMakeLists.txt : C/C++ release|armeabi-v7a : removing stale contents from '/Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/android/.cxx/cmake/release/armeabi-v7a'
CMakeLists.txt : C/C++ release|armeabi-v7a : created folder '/Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/android/.cxx/cmake/release/armeabi-v7a'
CMakeLists.txt : C/C++ release|armeabi-v7a : executing cmake Executable : /usr/local/bin/cmake
...
CMakeLists.txt : C/C++ release|armeabi-v7a : null
...
> Task :babylonjs_react-native:generateJsonModelRelease FAILED
* What went wrong:
:babylonjs_react-native:generateJsonModelRelease (Thread[Daemon worker,5,main]) completed. Took 8.735 secs.
Execution failed for task ':babylonjs_react-native:generateJsonModelRelease'.
> java.lang.NullPointerException (no error message)
```
I was able to repro this locally as well by simply upgrading from CMake 3.16.5 (what I've been using for some time) to CMake 3.20.0. This repros in our open source project which can be found here: https://github.com/BabylonJS/BabylonReactNative/pull/193/checks?check_run_id=2256782153https://gitlab.kitware.com/cmake/cmake/-/issues/23004Android system STL broken with rtti/exceptions enabled2021-12-14T09:40:22-05:00Ryan PrichardAndroid system STL broken with rtti/exceptions enabledIf I configure CMake to use the system STL but enable either of rtti or exceptions, then CMake tries to link with -landroid_support, but it uses a `;` in CMAKE_CXX_STANDARD_LIBRARIES when it needs to use a ` `, so the link command fails....If I configure CMake to use the system STL but enable either of rtti or exceptions, then CMake tries to link with -landroid_support, but it uses a `;` in CMAKE_CXX_STANDARD_LIBRARIES when it needs to use a ` `, so the link command fails.
CMakeLists.txt:
```
cmake_minimum_required(VERSION 3.21.0)
project(test C CXX ASM)
message(STATUS "CMAKE_CXX_STANDARD_LIBRARIES=[${CMAKE_CXX_STANDARD_LIBRARIES}]")
add_executable(hello hello.cpp)
```
hello.cpp:
```
int main() { return 0; }
```
CMake Invocation:
```
$ cmake -GNinja -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_NDK=... \
-DCMAKE_SYSTEM_VERSION=19 \
-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \
-DCMAKE_ANDROID_STL_TYPE=system \
-DCMAKE_ANDROID_EXCEPTIONS=ON
```
Output:
```
...
-- CMAKE_CXX_STANDARD_LIBRARIES=[ -lc++abi;-landroid_support -latomic -lm]
...
$ ninja
[2/2] Linking CXX executable hello
FAILED: hello
: && /x/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -mfpu=vfpv3-d16 -Wformat -Werror=format-security -fexceptions -fno-rtti -stdlib=libstdc++ -O2 -g -DNDEBUG -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined -Wl,--gc-sections CMakeFiles/hello.dir/hello.cpp.o -o hello -lc++abi;-landroid_support -latomic -lm && :
/bin/sh: line 1: -landroid_support: command not found
ninja: build stopped: subcommand failed.
```
The fix is trivial. I wasn't sure I needed to file a bug, but maybe it's helpful.
This code in Android-Common.json uses list-append but needs to use string-append:
```
macro(__android_stl lang)
string(APPEND CMAKE_${lang}_FLAGS_INIT " -stdlib=libstdc++")
if(_ANDROID_STL_EXCEPTIONS OR _ANDROID_STL_RTTI)
string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -lc++abi")
if(CMAKE_SYSTEM_VERSION LESS 21)
list(APPEND CMAKE_${lang}_STANDARD_LIBRARIES "-landroid_support")
endif()
endif()
endmacro()
```3.22.2https://gitlab.kitware.com/cmake/cmake/-/issues/22634Android: find_program cannot find host executables2021-09-20T11:44:04-04:00jheydebrandAndroid: find_program cannot find host executablesWhen setting `CMAKE_SYSTEM_NAME=Android` in a toolchain file (e.g. by using the toolchain file from NDK 23), calls to `find_program()` will not find any applications in the host's `PATH` environment variable anymore due to `CMAKE_FIND_US...When setting `CMAKE_SYSTEM_NAME=Android` in a toolchain file (e.g. by using the toolchain file from NDK 23), calls to `find_program()` will not find any applications in the host's `PATH` environment variable anymore due to `CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=OFF` (https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.2/Modules/Platform/Android-Initialize.cmake#L61).
Android seems to be the only platform which explicitly sets this value to OFF.
Are all projects, which want to find executables in the host's PATH, supposed to turn `CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=ON` again?
If yes, should it happen before or after the `project()` command (i.e. would that setting being ON break something for the Android toolchain file)?
If no, shouldn't Android-Initialize.cmake refrain from setting this variable?
Example CMake file which highlights the issue (invocation command line below):
```cmake
cmake_minimum_required(VERSION 3.21.0)
# Will find the executable in host's PATH
find_program(attemptOne git)
if(TRYBEFORE)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH 1)
endif()
project(AndroidFindProgramTest LANGUAGES C CXX)
if(TRYAFTER)
set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH 1)
endif()
# Will only find the executable if at least one of TRYBEFORE or TRYAFTER is true'ish
find_program(attemptTwo git)
message(STATUS "attemptOne=${attemptOne}")
message(STATUS "attemptTwo=${attemptTwo}")
```
Problematic example use:
```bash
$ cmake.exe --version
cmake version 3.21.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ set | find "Path"
Path=[...];C:/Users/build/AppData/Local/Programs/Git/cmd
$ cmake.exe -GNinja -DCMAKE_TOOLCHAIN_FILE=D:/android/ndk/23.0.7599858/build/cmake/android.toolchain.cmake -S . -B . -DTRYBEFORE=0 -DTRYAFTER=0
-- Android: Targeting API '16' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
-- Android: Selected unified Clang toolchain
-- The C compiler identification is Clang 12.0.5
-- The CXX compiler identification is Clang 12.0.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/android/ndk/23.0.7599858/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/android/ndk/23.0.7599858/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- attemptOne=C:/Users/build/AppData/Local/Programs/Git/cmd/git.exe
-- attemptTwo=attemptTwo-NOTFOUND
-- Configuring done
-- Generating done
```3.20.6https://gitlab.kitware.com/cmake/cmake/-/issues/21399Unable to build CMake for Android. (To use in Termux, for example)2021-08-19T10:28:44-04:00ChuviUnable to build CMake for Android. (To use in Termux, for example)I used Android NDK Cross-compiler with ANDROID_ABI=arm64-v8a and ANDROID_PLATFORM=android-29
Also i has tryed to build it inside Termux, and got the same errors. In Termux I have cmake 3.18.4 and clang 10.0.1
[cmlibarchive/archive.h#L1...I used Android NDK Cross-compiler with ANDROID_ABI=arm64-v8a and ANDROID_PLATFORM=android-29
Also i has tryed to build it inside Termux, and got the same errors. In Termux I have cmake 3.18.4 and clang 10.0.1
[cmlibarchive/archive.h#L101](https://gitlab.kitware.com/cmake/cmake/-/blob/master/Utilities/cmlibarchive/libarchive/archive.h#L101) android_lf.h not exists.
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Utilities/cmlibuv/src/unix/core.c#L1394 error: use of undeclared identifier 'CPU_SETSIZE'
return CPU_SETSIZE;
Please, note that CMake 3.18.4 (without cmake-curses-gui) has been successfully build inside Termux without any problems.https://gitlab.kitware.com/cmake/cmake/-/issues/21652Android NDK support in CMake 3.16 broken by NDK r222021-01-05T03:42:32-05:00Yuri6037Android NDK support in CMake 3.16 broken by NDK r22The support for Android NDK is totally broken:
```
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 29)
set(CMAKE_ANDROID_ARCH_ABI aarch64)
set(CMAKE_ANDROID_NDK "/home/X/Android/Sdk")
```
I have already installed the NDK V22 fr...The support for Android NDK is totally broken:
```
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 29)
set(CMAKE_ANDROID_ARCH_ABI aarch64)
set(CMAKE_ANDROID_NDK "/home/X/Android/Sdk")
```
I have already installed the NDK V22 from the Android Studio (there are no other versions available).
When this code is ran before any other cmake code we get:
```
CMake Error at /usr/share/cmake-3.16/Modules/Platform/Android-Initialize.cmake:40 (message):
Android: The system root directory needed for the selected Android version
and architecture does not exist:
```
Which is normal considering the wrong directory structure CMake expects. It appears CMake is trying to locate a folder called arch-arm under android-29 folder. The android-29 folder exists however the arch-arm folder does not exist and yet CMake thinks it should. Why?
If that error is "by design", then why keep a code that basically does not work at all?https://gitlab.kitware.com/cmake/cmake/-/issues/20038Android: Wrong binutils when building with NDK r19+2021-01-04T13:13:54-05:00Christopher BroadbentAndroid: Wrong binutils when building with NDK r19+Building with cmake 3.16 with the toolchain file:
```
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_STL_TYP...Building with cmake 3.16 with the toolchain file:
```
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 21)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_STL_TYPE c++_static)
set(CMAKE_ANDROID_ARM_NEON TRUE)
set(CMAKE_ANDROID_ARM_MODE TRUE)
```
Under NDK r18b, cmake finds the correct version of objcopy with arm support:
```
//Path to a program.
CMAKE_NM:FILEPATH=<path-to-ndk>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm
//Path to a program.
CMAKE_OBJCOPY:FILEPATH=<path-to-ndk>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objcopy
//Path to a program.
CMAKE_OBJDUMP:FILEPATH=<path-to-ndk>/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objdump
```
but under NDK r20, it defaults to the system objcopy, which doesn't support arm:
```
//Path to a program.
CMAKE_NM:FILEPATH=/usr/bin/nm
//Path to a program.
CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy
//Path to a program.
CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump
```
this seems to effect the entire suite of `CMAKE_` binutils programs, and even `CMAKE_LINKER` + `CMAKE_AR`, but linking still works ok when doing builds.3.16.4Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/18739Android: NDK r19+ support2021-01-04T13:13:54-05:00DanilAndroid: NDK r19+ supportI've been trying to build simple Qt application with Kirigami for Android and found that ndk r19 isn't working for me and judging from the sources it couldn't work at the moment.
In r19 in `build/core/toolchains/arm-linux-androideabi-cl...I've been trying to build simple Qt application with Kirigami for Android and found that ndk r19 isn't working for me and judging from the sources it couldn't work at the moment.
In r19 in `build/core/toolchains/arm-linux-androideabi-clang/setup.mk` there no `TOOLCHAIN_ROOT` which means when clang is used
(`-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang` ) [Determine-Compiler-NDK.cmake#L120](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Android/Determine-Compiler-NDK.cmake#L120) clears `_ANDROID_TOOL_NAME` and it is expected that [Determine-Compiler-NDK.cmake#L182](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Android/Determine-Compiler-NDK.cmake#L182) will set it.
However since there is no `TOOLCHAIN_ROOT` - `_ANDROID_TOOL_NAME` is never populated and when `_ANDROID_TOOL_C_TOOLCHAIN_PREFIX` is constructed in [Determine-Compiler-NDK.cmake#L231](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/Platform/Android/Determine-Compiler-NDK.cmake#L231) it becomes incorrect.
I may be doing something inherently wrong since I'm unable to build the app with any ndk for different reasons. But this one looks like a genuine bug.
Manually adding `TOOLCHAIN_ROOT := $(call get-toolchain-root,llvm)` to setup.mk moves the build further but fails due to:
`android-ndk-r19-beta2/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lunwind` (probably `TOOLCHAIN_ROOT` addition is just meaningless)3.16.0Brad KingBrad Kinghttps://gitlab.kitware.com/cmake/cmake/-/issues/19840Android: Add support for natively building on Android2020-11-05T10:16:00-05:00B FaceAndroid: Add support for natively building on AndroidA bit of background first, [the Termux app for Android](https://termux.com/) presents a terminal and package manager for Android, which has included [a native Android CMake package from Termux's inception more than four years ago](https:...A bit of background first, [the Termux app for Android](https://termux.com/) presents a terminal and package manager for Android, which has included [a native Android CMake package from Termux's inception more than four years ago](https://github.com/termux/termux-packages/commits/master/packages/cmake). However, CMake checks utsname to determine CMAKE_HOST_SYSTEM_NAME and it would represent an Android host as "Linux", so CMake would treat an Android-AArch64 device as a Linux-AArch64 host for builds. This worked but [quickly got annoying](https://github.com/termux/termux-packages/issues/151), so [I finally patched CMake a couple months ago and got it merged in the Termux package repo](https://github.com/termux/termux-packages/pull/4222), which I'm now submitting here, !3917, so Termux doesn't have to maintain this.