Fix search of VCTargetsPath for VS2019 build. #698
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a somewhat cryptic change about VS2017 -> VS2019, I am struggling to find information about this on the web.
It looks like a change in Windows SDK or VS2017 -> VS2019 has shuffled paths around the toolchains, hence what used to be
VCTargetsPath\Common7\IDE\VC\VCTargets
can now be located inVCTargetsPath\MSBuild\Microsoft\VC\v160\
.Also not quite sure I understand the role of the
VCTargetsPath
environment variable. The intended role ofVCTargetsPath
is something I don't understand properly, and it is not really well documented.My impression of this situation is that the
VCTargetsPath
environment variable would have been something that Microsoft Visual Studio has once had as a property that's needed, and CMake was built to rely on it. But as newer Visual Studios came around,VCTargetsPath
has been demoted to an internal VS project/solution property, and not a full environment variable. CMake however never changed, and it still expects to seeVCTargetsPath
when targeting Visual Studio.The above is a complete guess however, I am struggling to find information about this on the web.
Current official VS 2019 Command Prompt does not have that environment variable. Neither does VS 2017 Command Prompt. It is something that CMake expects to see when compiling using the Visual Studio generator.
In https://discourse.cmake.org/t/cmake-failed-to-get-the-value-of-vctargetspath-with-vs2019-16-7/1839/16 Brad King, a core CMake developer suggested that
If the imported file is missing, that means Visual Studio’s own VCTargetsPath is incorrect. This likely indicates a problem with its installation.
. However the core issue is that Visual Studio does no longer has that env. var in 2017 or 2019, so not sure what to make of it.In any case, this change fixes VS2019 build for me. In the future it is possible that we need to manually update the directory search list to
Microsoft.Cpp.Default.props
as new toolchain versions come out; unless someone knows how this stuff is supposed to work in CMake and/or VS and can offer an automated search feature :)