CMake module for building drivers with Windows Development Kit (WDK)
FindWDK makes it possible to build kernel drivers and kernel libraries with Windows Development Kit (WDK) and CMake.
Requirements:
- WDK 8.0 and higher
- Visual Studio 2015 and higher
- CMake 3.0 and higher
Though no source is in this installation, a simple CMakeLists.txt was included to allow installation of packages. Simply "build and install" like you would any other package.
mkdir build-out
cd build-out
cmake ..
MSBuild.exe FindWDK.sln
Didn't really need the build step, but thought it would be uniform.
Then from a administrator command prompt:
MSBuild.exe INSTALL.vcxproj
You can find the files in C:/Program Files (x86)/FindWDK
.
If you installed the package in the above step, you just need to call find_package
on it.
find_package(FindWDK)
Then add the INCLUDE_DIR
path to your CMAKE_MODULE_PATH
:
list(APPEND CMAKE_MODULE_PATH ${FindWDK_INCLUDE_DIR})
find_package(WDK REQUIRED)
You may add FindWDK
to the module search path and call find_package
. if you did not perform the build and install. You can then replace ${FindWDK_INCLUDE_DIR}
with "<path_to_FindWDK>"
being the local path of FindWDK on your system.
FindWDK will search for the latest installed Windows Development Kit (WDK) and expose commands for creating kernel drivers and kernel libraries. Also the following variables will be defined:
WDK_FOUND
-- if false, do not try to use WDKWDK_ROOT
-- where WDK is installedWDK_VERSION
-- the version of the selected WDKWDK_WINVER
-- the WINVER used for kernel drivers and libraries (default value is0x0601
and can be changed per target or globally)WDK_NTDDI_VERSION
-- the NTDDI_VERSION used for kernel drivers and libraries, if not set, the value will be automatically calculated by WINVER
WDKContentRoot
environment variable overrides the default WDK search path.
The following command adds a kernel driver target called <name>
to be built from the source files listed in the command invocation:
wdk_add_driver(<name>
[EXCLUDE_FROM_ALL]
[KMDF <kmdf_version>]
[WINVER <winver_version>]
[NTDDI_VERSION <ntddi_version>]
source1 [source2 ...]
)
Options:
EXCLUDE_FROM_ALL
-- exclude from the default build targetKMDF <kmdf_version>
-- use KMDF and set KMDF versionWINVER <winver_version>
-- use specific WINVER versionNTDDI_VERSION <ntddi_version>
-- use specific NTDDI_VERSION
Example:
wdk_add_driver(KmdfCppDriver
KMDF 1.15
WINVER 0x0602
Main.cpp
)
The following command adds a kernel library target called <name>
to be built from the source files listed in the command invocation:
wdk_add_library(<name> [STATIC | SHARED]
[EXCLUDE_FROM_ALL]
[KMDF <kmdf_version>]
[WINVER <winver_version>]
[NTDDI_VERSION <ntddi_version>]
source1 [source2 ...]
)
Options:
EXCLUDE_FROM_ALL
-- exclude from the default build targetKMDF <kmdf_version>
-- use KMDF and set KMDF versionWINVER <winver_version>
-- use specific WINVER versionNTDDI_VERSION <ntddi_version>
-- use specific NTDDI_VERSIONSTATIC or SHARED
-- specify the type of library to be created
Example:
wdk_add_library(KmdfCppLib STATIC
KMDF 1.15
WINVER 0x0602
KmdfCppLib.h
KmdfCppLib.cpp
)
FindWDK creates imported targets for all WDK libraries. The naming pattern is WDK::<UPPERCASED_LIBNAME>
. Linking a minifilter driver to FltMgr.lib
is shown below:
target_link_libraries(MinifilterCppDriver WDK::FLTMGR)
Take a look at the samples folder to see how WMD and KMDF drivers and libraries are built.
FindWDK is licensed under the OSI-approved 3-clause BSD license. You can freely use it in your commercial or opensource software.
- New: Add ability to link to WDK libraries
- New: Add MinifilterCppDriver sample
- Fix: W4 warnings in C version of the driver, add missing /W4 /WX for C compiler
- Initial public release