Android: Refactor sysroot detection under Visual Studio

Since commit 6051a49c78 (Visual Studio: Add Android support, 2020-06-12,
v3.19.0-rc1~619^2) we run MSBuild to build a sample project to detect
the sysroot.  Previously we relied on `CMAKE_VS_MSBUILD_COMMAND` being
available.  That required commit d5b5c19278 (cmGlobalGenerator:
FindMakeProgram() before CMakeDetermineSystem, 2020-06-15,
v3.19.0-rc1~619^2~3) to make it available early enough.  However, that
ordering broke `CMAKE_GENERATOR_INSTANCE` so we need to prepare to
revert it.  Use `cmake_host_system_information` to get the location of
MSBuild under a VS generator instead.
This commit is contained in:
Brad King 2021-10-20 12:07:59 -04:00
parent 44a86d0b38
commit 42418b02f7

View File

@ -52,14 +52,16 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio")
endif()
configure_file(${CMAKE_ROOT}/Modules/Platform/Android/VCXProjInspect.vcxproj.in
${CMAKE_PLATFORM_INFO_DIR}/VCXProjInspect.vcxproj @ONLY)
cmake_host_system_information(RESULT _msbuild QUERY VS_MSBUILD_COMMAND) # undocumented query
execute_process(
COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" "VCXProjInspect.vcxproj"
COMMAND "${_msbuild}" "VCXProjInspect.vcxproj"
"/p:Configuration=Debug" "/p:Platform=${vcx_platform}"
WORKING_DIRECTORY ${CMAKE_PLATFORM_INFO_DIR}
OUTPUT_VARIABLE VCXPROJ_INSPECT_OUTPUT
ERROR_VARIABLE VCXPROJ_INSPECT_OUTPUT
RESULT_VARIABLE VCXPROJ_INSPECT_RESULT
)
unset(_msbuild)
if(NOT CMAKE_SYSROOT AND VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_SYSROOT=([^%\r\n]+)[\r\n]")
# Strip VS diagnostic output from the end of the line.
string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _sysroot "${CMAKE_MATCH_1}")