# Unable to fully build Windows UMDF Driver Using CMake

**URL:** https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368
**Category:** Code
**Tags:** os:windows
**Created:** [December 14, 2020, 4:57pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368 "2020-12-14T16:57:08Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![nsulmol](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nsulmol](https://discourse.cmake.org/u/nsulmol)
#### Post date: [December 14, 2020, 4:57pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/1 "2020-12-14T16:57:08Z")

</div>

Hello everyone,

I’m running into issues trying to compile a Windows UMDF driver using CMake version 3.18+. More specifically, I am able to _compile_, but run into a strange ZERO\_CHECK error that causes the build to fail.

Within my CMakeLists.txt, I call a helper method wdk\_add\_library(), which looks as follows:

```
function(wdk_add_library _target)
    cmake_parse_arguments(WDK "" "UMDF;WINVER" "" ${ARGN})

    add_library(${_target} ${WDK_UNPARSED_ARGUMENTS})
    set_target_properties(${_target} PROPERTIES VS_PLATFORM_TOOLSET "WindowsUserModeDriver10.0")
    set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${WDK_COMPILE_FLAGS}")
    set_target_properties(${_target} PROPERTIES COMPILE_DEFINITIONS 
        "${WDK_COMPILE_DEFINITIONS};$<$<CONFIG:Debug>:${WDK_COMPILE_DEFINITIONS_DEBUG};_WIN32_WINNT=${WDK_WINVER}>"
        )
    set_target_properties(${_target} PROPERTIES LINK_FLAGS "${WDK_LINK_FLAGS}")

    target_include_directories(${_target} SYSTEM PRIVATE
        "${WDK_ROOT}/Include/${WDK_VERSION}/shared"
        "${WDK_ROOT}/Include/${WDK_VERSION}/um"
        )

    target_link_libraries( ${_target} WDK::NTDLL WDK::MINCORE )

    if(DEFINED WDK_UMDF)
        target_include_directories(${_target} SYSTEM PRIVATE "${WDK_ROOT}/Include/wdf/umdf/${WDK_UMDF}")
        target_link_libraries(${_target}
            "${WDK_ROOT}/Lib/wdf/umdf/${WDK_PLATFORM}/${WDK_UMDF}/WdfDriverStubUm.lib"
            )
    endif()
endfunction()

```

I’m basing this off of a FindWDK.cmake module created [here](https://github.com/SergiusTheBest/FindWDK/blob/master/cmake/FindWdk.cmake), which has been used for KMDF driver purposes. I have changed stuff around to detect the associated UMDF libraries and includes, rather than the KMDF ones.

I am calling wdk\_add\_library() with a SHARED type, as Windows UMDF drivers are DLLs.

The source files of my driver don’t seem to be the issue here - they compile fine and can be properly used in a template UMDF Visual Studio project. The issue occurs when ZERO\_CHECK is called (after compilation):

 ![image](https://discourse.cmake.org/uploads/default/original/2X/b/b461cad2d6172f24004a565de5c2422bc77fe4d0.png)

I have spent a bit of time looking for this target definition in other solution files, as well as references to it on search engines (hoping it would be a known/expected target in a Visual Studio vcxproj). However, I haven’t been able to find it quite yet.

I should note that the issue disappears if I build my library as a STATIC one. However, I don’t believe I can really move forward at that stage, as the rest of the driver process expects a dll.

Is anyone familiar with building UMDF drivers using CMake able to point out what I am doing wrong? I’m sorry if this is quite obvious!

Thank you,  
Nick

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 15, 2020, 4:34pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/2 "2020-12-15T16:34:02Z")

</div>

I’m not sure exactly what’s going on here, but I’ll note that I think it’d be better to use the `target_` family of commands rather than setting their properties directly:

- `COMPILE_OPTIONS` → `target_compile_options`
- `COMPILE_DEFINITIONS` → `target_compile_definitions`
- `LINK_FLAGS` → `target_link_options`

Back to the actual question, does `GetDriverProjectAttributes` show up in your project at all?

Cc: @brad.king in case you’ve seen something like this before.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [December 15, 2020, 5:16pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/3 "2020-12-15T17:16:47Z")

</div>

For reference, the [VS\_PLATFORM\_TOOLSET](https://cmake.org/cmake/help/latest/prop_tgt/VS_PLATFORM_TOOLSET.html) target property (mentioned in the example above) was added by [CMake MR 4682](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4682) specifically to support driver mode builds.

---

<div class="post-metadata">

### Author: ![nsulmol](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nsulmol](https://discourse.cmake.org/u/nsulmol)
#### Post date: [December 15, 2020, 9:27pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/4 "2020-12-15T21:27:05Z")

</div>

Thanks for the quick response, Ben and Brad. I updated to use target\_XXX calls where applicable (as far as I can tell, this cannot be done for VS\_PLATFORM\_TOOLSET). As expected, the problem remains.

This call does not show up anywhere in my project, nor does it show up in the vcxproj files. As far as I can decipher, whatever logic was added for “VS\_PLATFORM\_TOOLSET == WindowsUserModeDriver10.0” seems to be expecting the created vcxproj to contain a GetDriverProjectAttributes target? From perusing the Visual Studio vcxproj / sln file documentation, I don’t see any reference to anything like this, though.

I should clarify that I have tried this both with MSVC++ compiler v141 and v142, and that I’m trying this using Visual Studio 2019, with Windows SDK 10.0.18362.0. The compilation and linking seem fine, though - this seems to really be some byproduct of my settings causing the ZERO\_CHECK project to look for something that is not there…

Thanks again for any help.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 15, 2020, 10:56pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/5 "2020-12-15T22:56:14Z")

</div>

Hmm. We might need to add something to the vcxproj files according to this commit: [https://gitlab.freedesktop.org/spice/win32/usbdk/-/commit/2cd4aa5262fd293c3e512961f869dee5d40b28d1#bf28dd91e2de29de3b2fa70d6541e552e4166b69\_1038\_372](https://gitlab.freedesktop.org/spice/win32/usbdk/-/commit/2cd4aa5262fd293c3e512961f869dee5d40b28d1#bf28dd91e2de29de3b2fa70d6541e552e4166b69_1038_372)

---

<div class="post-metadata">

### Author: ![nsulmol](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nsulmol](https://discourse.cmake.org/u/nsulmol)
#### Post date: [December 15, 2020, 11:36pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/6 "2020-12-15T23:36:15Z")

</div>

Hi Ben,

I’m wondering if this is some older vcxproj attribute - although I don’t see it in Microsoft documentation, they have a tendency to flush and redo their documentation every couple years (or at least, misplace hyperlinks). The target “GetDriverProjectAttributes” does not show up in the sample UMDF driver I am comparing against (created by selecting a new sample UMDF 2 Driver using Visual Studio), nor does it in a separate UMDF driver project I am also checking. I would upload either here, but do not yet have the rights to do so.

If that’s the case, wouldn’t the situation be the other way around? Whatever logic is getting called during ZERO\_CHECK is checking that the associated .vcxproj has a target “GetDriverProjectAttributes”, when this is not necessary?

I’ve tried grep-ing around in the share/Modules portion of my CMake install, to see if I could find any references to this. No luck thus far…

Thanks,  
Nick

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2020, 2:53pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/7 "2020-12-16T14:53:06Z")

</div>

CMake’s source code doesn’t mention it either, so figuring out what ends up wanting it would be useful. Can you reproduce it with a minimal example that you could upload?

---

<div class="post-metadata">

### Author: ![nsulmol](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nsulmol](https://discourse.cmake.org/u/nsulmol)
#### Post date: [December 16, 2020, 4:38pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/8 "2020-12-16T16:38:31Z")

</div>

Sure thing. I am not able to upload files directly here (as a new user), but I’ve uploaded a sample to Google Drive. See here: [https://drive.google.com/file/d/1hE0VSUc8-EKMMz48vBZMKL-Uad4iGs-f/view?usp=sharing](https://drive.google.com/file/d/1hE0VSUc8-EKMMz48vBZMKL-Uad4iGs-f/view?usp=sharing)

A couple notes:

- You need the WDK to compile this. I’m using WDK for Windows 10, Version 1903: [https://docs.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads](https://docs.microsoft.com/en-us/windows-hardware/drivers/other-wdk-downloads).
- I am calling cmake with the following arguments, as I am compiling for SDK 10.0.18362:  
`cmake .. -DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=10.0.18362.0 -DCMAKE_SYSTEM_VERSION=10.0.18362.0`

Let me know if you run into any issues! Thanks again.

---

<div class="post-metadata">

### Author: ![0xMyon](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/0/94ad74/32.png) [@0xMyon](https://discourse.cmake.org/u/0xMyon)
#### Post date: [May 3, 2021, 9:25am UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/9 "2021-05-03T09:25:35Z")

</div>

Hi!

As Ben mentiond before, adding the “GetDriverProjectAttributes” and “GetPackageFiles” manually for **all** dependend .vcxproj did the trick. I’ve compared the cmake-generated against my UMDF project file (as this is build without errors) to identify a potential setting that may causes this issue with no success.

I’m suspecting the -tag itself to be the problem here, as the error occures while the driver is building complaining that the Tags are missing in the depended project. Here is a potential related issue I found: [https://github.com/dotnet/msbuild/issues/2874](https://github.com/dotnet/msbuild/issues/2874) where adding something to the project reference bypasses the problem. But I’m also stuck at this point.

Any progress on your side?

---

<div class="post-metadata">

### Author: ![nsulmol](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f04885/32.png) [@nsulmol](https://discourse.cmake.org/u/nsulmol)
#### Post date: [May 6, 2021, 5:03pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/10 "2021-05-06T17:03:20Z")

</div>

Hi Myon,

I wasn’t able to get past the issue, to be honest. I ended up working around it for now by using include\_external\_msproject(). Certainly not the best solution, but I was stuck at that point…

When you say: “adding the “GetDriverProjectAttributes” and “GetPackageFiles” manually for **all** dependend .vcxproj did the trick”, do you mean that manually adding these to the generated files allows the project to compile? Again, I didn’t test this because my sample/comparison UMDF driver did not have them (I had no sample for what they should look like).

---

<div class="post-metadata">

### Author: ![thxkiwi](https://discourse.cmake.org/user_avatar/discourse.cmake.org/thxkiwi/32/1611_2.png) [@thxkiwi](https://discourse.cmake.org/u/thxkiwi)
#### Post date: [July 2, 2021, 10:42pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/11 "2021-07-02T22:42:59Z")

</div>

Did anyone ever get to the bottom of what was causing this error and how to resolve?

I’m actually getting the error _without_ cmake; using solely Visual Studio generated MSBuild vcxproj files.

Figured I’d add that as a datapoint here and also hopeful that someone found a solution.

---

<div class="post-metadata">

### Author: ![0xMyon](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/0/94ad74/32.png) [@0xMyon](https://discourse.cmake.org/u/0xMyon)
#### Post date: [August 4, 2021, 12:20pm UTC](https://discourse.cmake.org/t/unable-to-fully-build-windows-umdf-driver-using-cmake/2368/12 "2021-08-04T12:20:28Z")

</div>

Visual Studio requires all dependencies to have Targets “GetDriverProjectAttributes” and “GetPackageFiles”. So I added them inside the node for ZERO\_CHECK and my two other dependencies by hand:

```auto
  <Target Name="GetDriverProjectAttributes" Returns="@(DriverProjectAttributes)"/>
  <Target Name="GetPackageFiles" Returns="@(FullyQualifiedFilesToPackage)"/>

```

For automation I created an ugly script “FixProjects.cmake” that just injects thes two lines at line 2:

```auto
file(READ "${PATH}" contents)

STRING(REGEX REPLACE ";" "#SEMICOLON#" contents "${contents}")
STRING(REGEX REPLACE "\n" ";" contents "${contents}")

LIST(GET contents 2 line_2)
LIST(GET contents 3 line_3)

set(miss_1 " <Target Name=\"GetDriverProjectAttributes\" Returns=\"@(DriverProjectAttributes)\"/>")
set(miss_2 " <Target Name=\"GetPackageFiles\" Returns=\"@(FullyQualifiedFilesToPackage)\"/>")

if ((NOT ${line_2} STREQUAL ${miss_1}) OR (NOT ${line_3} STREQUAL ${miss_2}))
	LIST(INSERT contents 2 ${miss_1} ${miss_2})

	STRING(REGEX REPLACE ";" "\n" contents "${contents}")
	STRING(REGEX REPLACE "#SEMICOLON#" ";" contents "${contents}")
	
	file(WRITE "${PATH}" "${contents}")
	message("Fixed Project-File: ${PATH}")
endif()

```

In your CMakeLists.txt just add the folowing custom command:

```auto
add_custom_command(
	TARGET ${PROJECT_NAME}
	PRE_BUILD
	COMMAND ${CMAKE_COMMAND} -D "PATH=\"${CMAKE_BINARY_DIR}/ZERO_CHECK.vcxproj\"" -P "${CMAKE_CURRENT_SOURCE_DIR}/FixProjects.cmake"
	COMMAND ${CMAKE_COMMAND} -D "PATH=\"${CMAKE_BINARY_DIR}/<path-to-any-other-dependency>.vcxproj\"" -P "${CMAKE_CURRENT_SOURCE_DIR}/FixProjects.cmake"
)

```

Not pretty but it works for me
