From e78abf94e325502da7ed4c09e9176de5ad700d4a Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Fri, 21 Apr 2023 11:22:26 +0200 Subject: VS/Android: Use ApplicationTypeRevision 3.0 in VS2022 Visual Studio 17 (Marketing name: Visual Studio 2022) still ships with "3.0" as most recent Variant of the Android application type. Use this revision. --- Modules/CMakeDetermineCompilerId.cmake | 2 +- Modules/Platform/Android-Determine.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 67044fb..c724008 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -432,7 +432,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} if(id_keyword STREQUAL "Android") if(CMAKE_GENERATOR MATCHES "Visual Studio 14") set(id_system_version "2.0") - elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]") set(id_system_version "3.0") else() set(id_system_version "") diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index 715f68b..bf717af 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -45,7 +45,7 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio") endif() if(CMAKE_GENERATOR MATCHES "Visual Studio 14") set(vcx_revision "2.0") - elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]") set(vcx_revision "3.0") else() set(vcx_revision "") -- cgit v0.12 From 5d5b6c741da414d7d62ac9681604cc95a1275c51 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Fri, 21 Apr 2023 11:27:09 +0200 Subject: VS/Android: Do not specify Windows Runtime library type during compiler id The VS2022 Clang toolchain adds some windows libraries to the linked library list if RuntimeLibrary is set, even if the Project is targeting Android. This causes an unexpected linker failure. --- Modules/CompilerId/VS-10.vcxproj.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in index 3598fc7..9bd618c 100644 --- a/Modules/CompilerId/VS-10.vcxproj.in +++ b/Modules/CompilerId/VS-10.vcxproj.in @@ -44,7 +44,7 @@ %(PreprocessorDefinitions) false EnableFastChecks - MultiThreadedDebugDLL + MultiThreadedDebugDLL TurnOffAllWarnings -- cgit v0.12 From 850ee280e0bb726771ea14f247ba1524b0c3dd64 Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Fri, 21 Apr 2023 18:00:35 +0200 Subject: VS/Android: Set API level explicitly during compiler identification VS2022 defaults to API 31 in 64-bit builds. This breaks if you combine VS2022 with an older Android NDK. --- Modules/CMakeDetermineCompilerId.cmake | 2 ++ Modules/CompilerId/VS-10.vcxproj.in | 1 + 2 files changed, 3 insertions(+) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index c724008..403766e 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -345,6 +345,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_platform ${CMAKE_VS_PLATFORM_NAME}) set(id_lang "${lang}") set(id_PostBuildEvent_Command "") + set(id_api_level "") if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$") set(id_cl_var "ClangClExecutable") elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Cc][Ll][Aa][Nn][Gg]([Cc][Ll]$|_[0-9])") @@ -430,6 +431,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_system "") endif() if(id_keyword STREQUAL "Android") + set(id_api_level "android-${CMAKE_SYSTEM_VERSION}") if(CMAKE_GENERATOR MATCHES "Visual Studio 14") set(id_system_version "2.0") elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]") diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in index 9bd618c..fa324d8 100644 --- a/Modules/CompilerId/VS-10.vcxproj.in +++ b/Modules/CompilerId/VS-10.vcxproj.in @@ -26,6 +26,7 @@ @id_config_type@ @id_toolset@ + @id_api_level@ MultiByte -- cgit v0.12 From f7af10100c034e485970cdff13822675b78eb48e Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Fri, 21 Apr 2023 18:08:30 +0200 Subject: VS/Android: Detect full NDK root instead of sysroot Visual Studio always uses a complete NDK and not a standalone toolchain. Let CMake handle the NDK and related logic correctly, avoid trying to find the standalone toolchain version from the unified clang toolchain in newer NDKs. --- Modules/Platform/Android-Determine.cmake | 21 ++++++++------------- Modules/Platform/Android/VCXProjInspect.vcxproj.in | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index bf717af..bc60222 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -34,15 +34,10 @@ cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # if IN_LIST # If using Android tools for Visual Studio, compile a sample project to get the -# sysroot. +# NDK path if(CMAKE_GENERATOR MATCHES "Visual Studio") - if(NOT CMAKE_SYSROOT) + if(NOT CMAKE_ANDROID_NDK) set(vcx_platform ${CMAKE_GENERATOR_PLATFORM}) - if(CMAKE_GENERATOR MATCHES "Visual Studio 1[45]") - set(vcx_sysroot_var "Sysroot") - else() - set(vcx_sysroot_var "SysrootLink") - endif() if(CMAKE_GENERATOR MATCHES "Visual Studio 14") set(vcx_revision "2.0") elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]") @@ -62,16 +57,16 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio") RESULT_VARIABLE VCXPROJ_INSPECT_RESULT ) unset(_msbuild) - if(NOT CMAKE_SYSROOT AND VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_SYSROOT=([^%\r\n]+)[\r\n]") + if(VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_ANDROID_NDK=([^%\r\n]+)[\r\n]") # Strip VS diagnostic output from the end of the line. - string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _sysroot "${CMAKE_MATCH_1}") - if(EXISTS "${_sysroot}") - file(TO_CMAKE_PATH "${_sysroot}" CMAKE_SYSROOT) + string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _ndk "${CMAKE_MATCH_1}") + if(EXISTS "${_ndk}") + file(TO_CMAKE_PATH "${_ndk}" CMAKE_ANDROID_NDK) endif() endif() if(VCXPROJ_INSPECT_RESULT) message(CONFIGURE_LOG - "Determining the sysroot for the Android NDK failed. + "Determining the Android NDK failed from msbuild failed. The output was: ${VCXPROJ_INSPECT_RESULT} ${VCXPROJ_INSPECT_OUTPUT} @@ -79,7 +74,7 @@ ${VCXPROJ_INSPECT_OUTPUT} ") else() message(CONFIGURE_LOG - "Determining the sysroot for the Android NDK succeeded. + "Determining the Android NDK succeeded. The output was: ${VCXPROJ_INSPECT_RESULT} ${VCXPROJ_INSPECT_OUTPUT} diff --git a/Modules/Platform/Android/VCXProjInspect.vcxproj.in b/Modules/Platform/Android/VCXProjInspect.vcxproj.in index 6919d2c..71fd214 100644 --- a/Modules/Platform/Android/VCXProjInspect.vcxproj.in +++ b/Modules/Platform/Android/VCXProjInspect.vcxproj.in @@ -29,7 +29,7 @@ - %40echo CMAKE_SYSROOT=$(@vcx_sysroot_var@) + %40echo CMAKE_ANDROID_NDK=$(VS_NdkRoot) -- cgit v0.12 From 16d8b65bc0efda22be8d9466cff2486cf5eada2a Mon Sep 17 00:00:00 2001 From: Michael Karcher Date: Fri, 21 Apr 2023 18:10:10 +0200 Subject: VS/Android: Use safe API level when detecting the NDK directory --- Modules/Platform/Android/VCXProjInspect.vcxproj.in | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/Platform/Android/VCXProjInspect.vcxproj.in b/Modules/Platform/Android/VCXProjInspect.vcxproj.in index 71fd214..f87d59b 100644 --- a/Modules/Platform/Android/VCXProjInspect.vcxproj.in +++ b/Modules/Platform/Android/VCXProjInspect.vcxproj.in @@ -19,6 +19,7 @@ DynamicLibrary MultiByte + android-21 -- cgit v0.12