This roughly allowed us to have toolchains work in Visual Studio builds. It actually worked really well.
Until Microsoft introduced this new external stuff…
Hmm. I suspect we’ll run into this when we update our CI machines to 16.10 (since we still use 16.8 and 16.9 toolchains). I’m not familiar enough with Visual Studio to know much else here though.
I ended up writing a cmake function that can extract the exact vs version using vswhere.exe
I just tested it locally and it works great! Not sure if the CMake team needs something like this. But it’s worth thinking about at least.
# This function will get the VS Version
function(amd_get_vs_versions version)
# Return 0 for non-vs generators
if (NOT (CMAKE_GENERATOR MATCHES "Visual Studio") )
set(${version} 0)
return()
endif()
# https://github.com/microsoft/vswhere/wiki
set(CMAKE_VS_WHERE "C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe")
# Get the major version number from the generator name
# EX: 16 for vs2019
# EX: 15 for vs2017
string(REGEX MATCHALL "Visual Studio ([0-9]+) [0-9]+" throwaway ${CMAKE_GENERATOR})
set(vsMajorVersion ${CMAKE_MATCH_1})
execute_process(
# Extract the exact version(s) of Visual Studio
COMMAND "${CMAKE_VS_WHERE}" -property catalog_productDisplayVersion
OUTPUT_VARIABLE vs_where_output
)
# We are regexing for the string "16.10.0" for example
if ((${vs_where_output} MATCHES "(${vsMajorVersion}\.[0-9]+\.[0-9]+).*"))
set(${version} "${CMAKE_MATCH_1}" PARENT_SCOPE)
else()
message(FATAL_ERROR "CMAKE | Failed regex vswhere.exe output!")
endif()
endfunction()