there is a strange behavior when running CMake with the
Visual Studio 15 2017 Win64 generator on two different machines using the same version of Visual Studio 2017 and the same version of CMake (3.19.3):
On one machine, generated vcxproj files contain a line in the “Globals” section
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> and the software (onnxruntime) compiles without problems. On the other machine, that line is missing such that Visual Studio 2017 selects 8.1 and compilation fails with an error related to https://github.com/baldurk/renderdoc/issues/222.
The source code has exactly the same revision and the CMake flags are identical as well, so I am puzzled about this behavior. The workaround to use
CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION is not optimal, since Visual Studio, when creating new projects via the IDE also sets the
So there must be a reason why CMake incorrectly does not set it on that one machine and it would be good to find out why, so any help is appreciated.
I think this means that either the Windows SDKs that are installed are different or that there is some mismatch with the host Windows 10 patch version. @brad.king?
The code selecting the SDK version is here.
Indeed, that is the case. One version has Windows 10 OS, the other has Windows Server 2012, in which case CMake does not select Windows 10 SDK by default. So the only solution would be to set
CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION, even though new projects that are created via the VS IDE choose a Windows10SDK (even on Windows Server 2012)? I would assume that the default behavior of CMake should rather follow the VS IDE defaults… What do you think?
So the only solution would be to set
Setting that won’t do anything. It’s meant only for CMake to report what it selected.
Windows Server 2012, in which case CMake does not select Windows 10 SDK
CMAKE_HOST_SYSTEM_VERSION on that OS? I suspect it is not 10. CMake by default targets the host’s version.
One can explicitly pass
-DCMAKE_SYSTEM_VERSION=10.0 to tell CMake to target Windows 10.
Thanks guys, for the immediate hints. Indeed,
CMAKE_HOST_SYSTEM_VERSION is 6.3.9600, matching https://en.wikipedia.org/wiki/Ver_(command).
The trick with
-DCMAKE_SYSTEM_VERSION=10.0 worked, so thanks again, but see my earlier comment above, I think it would make sense that CMake mimics the default behavior of the Visual Studio IDE, and on Windows Server 12, when creating a new project interactively, the Windows SDK is set to 10 even though the host is older. It would be great if this could be implemented in an update.
The Visual Studio default might change any time and is mostly a political choice to promote Windows 10. Just as they periodically try to get rid of compatibility with older systems until the developers told them not to. It just happened again with VS2019 16.7 that building 32bit binaries with the 8.1 SDK (needed to build for Windows 7) broke.
I’m not familiar with Xcode but I’m sure it’s the same.
Basing it on the host system is a practical choice to be able to actually run the binaries that you just built. I’d rather have that…