1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-21 23:00:50 +08:00

WindowsKernelModeDriver: Add WDK include and link paths on MSVC

Detect Windows Kernel-Mode Driver include directories and library search
paths from the WDK command-line environment.  Require toolchain files to
specify the KMDF target version via a new variable.

Since this changes the behavior of the WindowsKernelModeDriver
experimental feature, update its UUID.
This commit is contained in:
Joseph Snyder
2024-08-02 11:29:29 -04:00
committed by Brad King
parent 989d2aff39
commit b151bcfc9e
7 changed files with 87 additions and 2 deletions

View File

@@ -143,6 +143,7 @@ Variables that Provide Information
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM
/variable/CMAKE_WINDOWS_KMDF_VERSION
/variable/CMAKE_XCODE_BUILD_SYSTEM
/variable/CMAKE_XCODE_PLATFORM_TOOLSET
/variable/PROJECT-NAME_BINARY_DIR

View File

@@ -0,0 +1,13 @@
CMAKE_WINDOWS_KMDF_VERSION
--------------------------
.. versionadded:: 3.31
Specify the `Kernel-Mode Drive Framework`_ target version.
A :variable:`toolchain file <CMAKE_TOOLCHAIN_FILE>` that sets
:variable:`CMAKE_SYSTEM_NAME` to ``WindowsKernelModeDriver``
must also set ``CMAKE_WINDOWS_KMDF_VERSION`` to specify the
KMDF target version.
.. _`Kernel-Mode Drive Framework`: https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/kmdf-version-history

View File

@@ -1 +1,2 @@
include(Platform/Windows-MSVC-C)
__windows_kernel_mode(C)

View File

@@ -1 +1,2 @@
include(Platform/Windows-MSVC-CXX)
__windows_kernel_mode(CXX)

View File

@@ -1 +1,70 @@
include(Platform/Windows)
macro(__windows_kernel_mode lang)
if(CMAKE_CROSSCOMPILING)
set(_KMDF_ERROR_EPILOGUE
"Please set a valid CMAKE_WINDOWS_KMDF_VERSION in the toolchain file. "
"For more information, see\n"
" https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/kmdf-version-history"
)
if(NOT DEFINED CMAKE_WINDOWS_KMDF_VERSION)
message(FATAL_ERROR
"The Kernel-Mode Driver Framework (KMDF) version has not been set. "
${_KMDF_ERROR_EPILOGUE}
)
endif()
if(NOT CMAKE_WINDOWS_KMDF_VERSION MATCHES "^[0-9]\.[0-9]+$")
message(FATAL_ERROR
"The Kernel-Mode Driver Framework (KMDF) version is set to an invalid value. "
"The expected format is [0-9].[0-9]+. For example, 1.15 or 1.9. "
${_KMDF_ERROR_EPILOGUE}
)
endif()
set(_KMDF_ENV_VARS
Platform
WindowsSdkDir
VCToolsInstallDir
)
if(DEFINED ENV{EnterpriseWDK})
set(_WINDOWS_SDK_VERSION "$ENV{Version_Number}")
list(APPEND _KMDF_ENV_VARS Version_Number)
else()
set(_WINDOWS_SDK_VERSION "$ENV{WindowsSDKLibVersion}")
list(APPEND _KMDF_ENV_VARS WindowsSDKLibVersion)
endif()
foreach(var IN LISTS _KMDF_ENV_VARS)
if(NOT DEFINED ENV{${var}})
message(FATAL_ERROR "Required environment variable '${var}' is not defined.")
endif()
endforeach()
unset(_KMDF_ENV_VARS)
set(_KMDF_PLATFORM "$ENV{Platform}")
if(NOT DEFINED CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES)
set(CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES
$ENV{WindowsSdkDir}/Include/${_WINDOWS_SDK_VERSION}/km
$ENV{WindowsSdkDir}/Include/${_WINDOWS_SDK_VERSION}/km/crt
$ENV{WindowsSdkDir}/Include/${_WINDOWS_SDK_VERSION}/shared
$ENV{WindowsSdkDir}/Include/wdf/kmdf/${CMAKE_WINDOWS_KMDF_VERSION}
$ENV{VCToolsInstallDir}/include
)
endif()
if(NOT DEFINED CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES)
set(CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES}
)
endif()
if(NOT DEFINED CMAKE_${lang}_STANDARD_LINK_DIRECTORIES)
set(CMAKE_${lang}_STANDARD_LINK_DIRECTORIES
$ENV{WindowsSdkDir}/Lib/${_WINDOWS_SDK_VERSION}/km/${_KMDF_PLATFORM}
)
endif()
unset(_KMDF_ERROR_EPILOGUE)
unset(_KMDF_PLATFORM)
unset(_WINDOWS_SDK_VERSION)
endif()
endmacro()

View File

@@ -30,7 +30,7 @@ cmExperimental::FeatureData LookupTable[] = {
false },
// WindowsKernelModeDriver
{ "WindowsKernelModeDriver",
"5c2d848d-4efa-4529-a768-efd57171bf68",
"7f524e81-99c7-48f3-a35d-278bae54282c",
"CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER",
"CMake's Windows kernel-mode driver support is experimental. It is meant "
"only for experimentation and feedback to CMake developers.",

View File

@@ -1,5 +1,5 @@
set(CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER
"5c2d848d-4efa-4529-a768-efd57171bf68")
"7f524e81-99c7-48f3-a35d-278bae54282c")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"WindowsKernelModeDriver"