cmake --build does not see CMAKE_GENERATOR_PLATFORM in toolchain file
In summary:
The documentation at https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html indicates that CMAKE_GENERATOR_PLATFORM can be set in a toolchain file. I've found that it is disregarded during the build phase of a project using the VS2019 generator, unless set on the command line (during configuration) using -A Win32
or -DCMAKE_GENERATOR_PLATFORM=Win32
.
Minimal reproduction (tested using 3.14.5 and 3.15.0-rc2) at https://github.com/barometz/cmake-issue-win32.
I have a build using a toolchain file that boils down to..
set(CMAKE_GENERATOR_PLATFORM Win32)
set(CMAKE_SYSTEM_VERSION 10.0.15063.0)
Recently I switched (unintentionally) from the VS2017 generator to the VS2019 one. The former defaults to Win32 for the CMAKE_GENERATOR_PLATFORM, while the latter defaults to using the host platform. The behaviour I now see is:
$ cmake . -DCMAKE_TOOLCHAIN_FILE=x86-windows-msvc.cmake -G "Visual Studio 16 2019"
$ cmake --build .
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(283,5): error MSB8013: This project doesn't contain the Configuration and Platform combination of Debug|x64. [<...>\CmakeIssue\ZERO_CHECK.vcxproj]
In short, the CMAKE_GENERATOR_PLATFORM in the toolchain file does cause Win32 targets to be generated, but cmake --build
then ignores it and tries to build Debug|x64 instead. However, when I set the platform on the command line instead (either -A Win32
or -DCMAKE_GENERATOR_PLATFORM=Win32
) it does work.
For me personally this is an issue since my project builds on multiple platforms (plus a cross-compile) and I don't want to have any platform-specific command-line flags; the toolchain file (and an occasional if (WIN32)
) handles all the differences.