summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/WindowsKernelModeDriver.cmake
diff options
context:
space:
mode:
authorJoseph Snyder <joe.snyder@kitware.com>2024-08-02 15:29:29 (GMT)
committerBrad King <brad.king@kitware.com>2024-09-03 15:10:35 (GMT)
commitb151bcfc9ee53ad6aa4e24760bce87f1004f6381 (patch)
tree58ffdc7aa6b0661cb6a3e75919929ae78ee5b3a8 /Modules/Platform/WindowsKernelModeDriver.cmake
parent989d2aff3968a254fe03b57f9e8bc33db6837b03 (diff)
downloadCMake-b151bcfc9ee53ad6aa4e24760bce87f1004f6381.zip
CMake-b151bcfc9ee53ad6aa4e24760bce87f1004f6381.tar.gz
CMake-b151bcfc9ee53ad6aa4e24760bce87f1004f6381.tar.bz2
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.
Diffstat (limited to 'Modules/Platform/WindowsKernelModeDriver.cmake')
-rw-r--r--Modules/Platform/WindowsKernelModeDriver.cmake69
1 files changed, 69 insertions, 0 deletions
diff --git a/Modules/Platform/WindowsKernelModeDriver.cmake b/Modules/Platform/WindowsKernelModeDriver.cmake
index 65b2eae..3b1a427 100644
--- a/Modules/Platform/WindowsKernelModeDriver.cmake
+++ b/Modules/Platform/WindowsKernelModeDriver.cmake
@@ -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()