Unable to fully build Windows UMDF Driver Using CMake

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:

  <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:

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:

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