Browse Source

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.
Michael Karcher 2 years ago
parent
commit
f7af10100c

+ 8 - 13
Modules/Platform/Android-Determine.cmake

@@ -34,15 +34,10 @@ cmake_policy(PUSH)
 cmake_policy(SET CMP0057 NEW) # if IN_LIST
 cmake_policy(SET CMP0057 NEW) # if IN_LIST
 
 
 # If using Android tools for Visual Studio, compile a sample project to get the
 # If using Android tools for Visual Studio, compile a sample project to get the
-# sysroot.
+# NDK path
 if(CMAKE_GENERATOR MATCHES "Visual Studio")
 if(CMAKE_GENERATOR MATCHES "Visual Studio")
-  if(NOT CMAKE_SYSROOT)
+  if(NOT CMAKE_ANDROID_NDK)
     set(vcx_platform ${CMAKE_GENERATOR_PLATFORM})
     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")
     if(CMAKE_GENERATOR MATCHES "Visual Studio 14")
       set(vcx_revision "2.0")
       set(vcx_revision "2.0")
     elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]")
     elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[567]")
@@ -62,16 +57,16 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio")
       RESULT_VARIABLE VCXPROJ_INSPECT_RESULT
       RESULT_VARIABLE VCXPROJ_INSPECT_RESULT
       )
       )
     unset(_msbuild)
     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.
       # 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()
     endif()
     endif()
     if(VCXPROJ_INSPECT_RESULT)
     if(VCXPROJ_INSPECT_RESULT)
       message(CONFIGURE_LOG
       message(CONFIGURE_LOG
-        "Determining the sysroot for the Android NDK failed.
+        "Determining the Android NDK failed from msbuild failed.
 The output was:
 The output was:
 ${VCXPROJ_INSPECT_RESULT}
 ${VCXPROJ_INSPECT_RESULT}
 ${VCXPROJ_INSPECT_OUTPUT}
 ${VCXPROJ_INSPECT_OUTPUT}
@@ -79,7 +74,7 @@ ${VCXPROJ_INSPECT_OUTPUT}
 ")
 ")
     else()
     else()
       message(CONFIGURE_LOG
       message(CONFIGURE_LOG
-        "Determining the sysroot for the Android NDK succeeded.
+        "Determining the Android NDK succeeded.
 The output was:
 The output was:
 ${VCXPROJ_INSPECT_RESULT}
 ${VCXPROJ_INSPECT_RESULT}
 ${VCXPROJ_INSPECT_OUTPUT}
 ${VCXPROJ_INSPECT_OUTPUT}

+ 1 - 1
Modules/Platform/Android/VCXProjInspect.vcxproj.in

@@ -29,7 +29,7 @@
   </PropertyGroup>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">
     <PostBuildEvent>
     <PostBuildEvent>
-      <Command>%40echo CMAKE_SYSROOT=$(@vcx_sysroot_var@)</Command>
+      <Command>%40echo CMAKE_ANDROID_NDK=$(VS_NdkRoot)</Command>
     </PostBuildEvent>
     </PostBuildEvent>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />