CMake config issue on Win11 22H2 WDK (windows driver project)
Environment: VS2022, SDK/WDK 10.0.22621.0
Issue: CMake configuration step fails (output below)
cmake <workspace-path>\<repo-folder> -G"Visual Studio 17 2022" -A x64 -T"WindowsApplicationForDrivers10.0,host=x64" -DCMAKE_SYSTEM_VERSION="10.0.22621.0"
CMake Error at CMakeLists.txt:24 (project):
Failed to run MSBuild command:
C:/Program Files/Microsoft Visual Studio/2022/Professional/MSBuild/Current/Bin/amd64/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 7/11/2022 1:40:20 PM.
Project "<workspace-path>\build\CMakeFiles\3.21.4\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Windows Kits\10\build\10.0.22621.0\WindowsDriver.common.targets(314,5): error MSB4044: The "ValidateNTTargetVersion" task was not given a value for the required parameter "ValidNTTargetVersions". [<workspace-path>\build\CMakeFiles\3.21.4\VCTargetsPath.vcxproj]
Done Building Project "<workspace-path>\build\CMakeFiles\3.21.4\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"<workspace-path>\build\CMakeFiles\3.21.4\VCTargetsPath.vcxproj" (default target) (1) ->
(ValidateNTTargetVersion target) ->
C:\Program Files (x86)\Windows Kits\10\build\10.0.22621.0\WindowsDriver.common.targets(314,5): error MSB4044: The "ValidateNTTargetVersion" task was not given a value for the required parameter "ValidNTTargetVersions". [<workspace-path>\build\CMakeFiles\3.21.4\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.22
Exit code: 1
-- Configuring incomplete, errors occurred!
See also "C:/git-repos/apo_workspace/build/CMakeFiles/CMakeOutput.log".
Spent some time rootcausing the issue. It seems that the following commented out line
<!-- This is commented as setting it here over writes the one in the drivergenral.xml and it shows Windows10 rather than the value in xml file -->
<!--<TargetVersion Condition="'$(TargetVersion)' == ''">$(LatestTargetVersion)</TargetVersion>-->
in this file c:\Program Files (x86)\Windows Kits\10\build\10.0.22621.0\WindowsDriver.Default.props
causes the problem. Not sure if this got commented out only in the latest WDK, but uncommenting it makes the issue go away. Another way to mitigate is to add cmd.push_back(std::string("/p:TargetVersion=Windows10"));
to cmGlobalVisualStudio10Generator.cxx
.
This made me think if we could actually infer the TargetVersion
from CMAKE_SYSTEM_VERSION
and add something like cmd.push_back(std::string("/p:TargetVersion=") + this->GetTargetVersion());
to the codebase.