diff --git a/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake index 6f0ef331be..eb43935625 100644 --- a/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake +++ b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake @@ -4,8 +4,4 @@ if(NOT _cmake_windows_kernel_mode_driver_enabled) message(FATAL_ERROR "Windows kernel-mode driver experimental support is not enabled.") endif() -if(CMAKE_GENERATOR MATCHES "Visual Studio") - message(FATAL_ERROR "Visual Studio generators do not yet support CMAKE_SYSTEM_NAME=WindowsKernelModeDriver.") -endif() - set(_CMAKE_FEATURE_DETECTION_TARGET_TYPE STATIC_LIBRARY) diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 913db87f5d..0cabd35b8b 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -30,7 +30,7 @@ cmExperimental::FeatureData LookupTable[] = { false }, // WindowsKernelModeDriver { "WindowsKernelModeDriver", - "fac18f65-504e-4dbb-b068-f356bb1f2ddb", + "9157bf90-2313-44d6-aefa-67cd83c8be7c", "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.", diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 3d911bdee7..3e6ba4ee8b 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -20,6 +20,7 @@ #include "cmCryptoHash.h" #include "cmDocumentationEntry.h" +#include "cmExperimental.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmGlobalVisualStudio71Generator.h" @@ -476,6 +477,13 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf) if (!this->InitializeWindowsStore(mf)) { return false; } + } else if (this->SystemName == "WindowsKernelModeDriver"_s && + cmExperimental::HasSupportEnabled( + *mf, cmExperimental::Feature::WindowsKernelModeDriver)) { + this->SystemIsWindowsKernelModeDriver = true; + if (!this->InitializeWindowsKernelModeDriver(mf)) { + return false; + } } else if (this->SystemName == "Android"_s) { if (this->PlatformInGeneratorName) { mf->IssueMessage( @@ -536,6 +544,13 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf) return false; } +bool cmGlobalVisualStudio10Generator::InitializeWindowsKernelModeDriver( + cmMakefile*) +{ + this->DefaultPlatformToolset = "WindowsKernelModeDriver10.0"; + return true; +} + bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf) { std::string v = diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index a2b351cbe6..df9733d207 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -127,6 +127,12 @@ public: /** Return true if building for WindowsStore */ bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; } + /** Return true if building for WindowsKernelModeDriver */ + bool TargetsWindowsKernelModeDriver() const + { + return this->SystemIsWindowsKernelModeDriver; + } + /** Return true if building for Android */ bool TargetsAndroid() const { return this->SystemIsAndroid; } @@ -188,6 +194,7 @@ protected: virtual bool InitializeWindowsCE(cmMakefile* mf); virtual bool InitializeWindowsPhone(cmMakefile* mf); virtual bool InitializeWindowsStore(cmMakefile* mf); + virtual bool InitializeWindowsKernelModeDriver(cmMakefile* mf); virtual bool InitializeTegraAndroid(cmMakefile* mf); virtual bool InitializeAndroid(cmMakefile* mf); @@ -249,6 +256,7 @@ protected: bool SystemIsWindowsCE = false; bool SystemIsWindowsPhone = false; bool SystemIsWindowsStore = false; + bool SystemIsWindowsKernelModeDriver = false; bool SystemIsAndroid = false; bool MSBuildCommandInitialized = false; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 0c4992bbfa..fce248c5db 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -282,6 +282,7 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); this->NsightTegra = gg->IsNsightTegra(); this->Android = gg->TargetsAndroid(); + this->WindowsKernelMode = gg->TargetsWindowsKernelModeDriver(); auto scanProp = target->GetProperty("CXX_SCAN_FOR_MODULES"); for (auto const& config : this->Configurations) { if (scanProp.IsSet()) { @@ -299,9 +300,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( &this->NsightTegraVersion[0], &this->NsightTegraVersion[1], &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]); this->MSTools = !this->NsightTegra && !this->Android; - this->Managed = false; - this->TargetCompileAsWinRT = false; - this->IsMissingFiles = false; this->DefaultArtifactDir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget)); @@ -1437,7 +1435,11 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) switch (this->GeneratorTarget->GetType()) { case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::MODULE_LIBRARY: - configType = "DynamicLibrary"; + if (this->WindowsKernelMode) { + configType = "Driver"; + } else { + configType = "DynamicLibrary"; + } break; case cmStateEnums::OBJECT_LIBRARY: case cmStateEnums::STATIC_LIBRARY: @@ -1482,6 +1484,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) } else if (this->Android) { this->WriteAndroidConfigurationValues(e1, c); } + + if (this->WindowsKernelMode) { + this->WriteMSDriverConfigurationValues(e1, c); + } } } @@ -1608,6 +1614,14 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged( oh.OutputFlagMap(); } +void cmVisualStudio10TargetGenerator::WriteMSDriverConfigurationValues( + Elem& e1, std::string const&) +{ + // FIXME: Introduce a way for project code to control these. + e1.Element("DriverType", "KMDF"); + e1.Element("DriverTargetPlatform", "Universal"); +} + void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesCommon( Elem& e1, std::string const& config) { @@ -3217,9 +3231,13 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental( if (!this->MSTools) { return; } + if (this->WindowsKernelMode) { + return; + } if (this->ProjectType == VsProjectType::csproj) { return; } + // static libraries and things greater than modules do not need // to set this option if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY || @@ -3687,6 +3705,10 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( e2.Element("ScanSourceForModuleDependencies", this->ScanSourceForModuleDependencies[configName] ? "true" : "false"); + if (this->WindowsKernelMode) { + e2.Element("WppEnabled", "true"); + e2.Element("WppRecorderEnabled", "true"); + } } bool cmVisualStudio10TargetGenerator::ComputeRcOptions() @@ -4822,6 +4844,10 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0) this->WriteMasmOptions(e1, c); this->WriteNasmOptions(e1, c); } + + if (this->WindowsKernelMode) { + Elem(e1, "DriverSign").Element("FileDigestAlgorithm", "sha256"); + } // output midl flags this->WriteMidlOptions(e1, c); // write events diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 9b7ae10a25..2a9f16ff40 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -74,6 +74,7 @@ private: std::string const& config); void WriteMSToolConfigurationValuesCommon(Elem& e1, std::string const& config); + void WriteMSDriverConfigurationValues(Elem& e1, std::string const& config); void WriteHeaderSource(Elem& e1, cmSourceFile const* sf, ConfigToSettings const& toolSettings); void WriteExtraSource(Elem& e1, cmSourceFile const* sf, @@ -234,7 +235,7 @@ private: std::string LangForClCompile; VsProjectType ProjectType; - bool InSourceBuild; + bool InSourceBuild = false; std::vector Configurations; std::vector TargetsFileAndConfigsVec; cmGeneratorTarget* const GeneratorTarget; @@ -242,14 +243,15 @@ private: std::string const Platform; std::string const Name; std::string const GUID; - bool MSTools; - bool Managed; - bool NsightTegra; - bool Android; + bool MSTools = false; + bool Managed = false; + bool NsightTegra = false; + bool Android = false; + bool WindowsKernelMode = false; bool HaveCustomCommandDepfile = false; std::map ScanSourceForModuleDependencies; unsigned int NsightTegraVersion[4]; - bool TargetCompileAsWinRT; + bool TargetCompileAsWinRT = false; std::set IPOEnabledConfigurations; std::set ASanEnabledConfigurations; std::set FuzzerEnabledConfigurations; @@ -257,7 +259,7 @@ private: cmGlobalVisualStudio10Generator* const GlobalGenerator; cmLocalVisualStudio10Generator* const LocalGenerator; std::set CSharpCustomCommandNames; - bool IsMissingFiles; + bool IsMissingFiles = false; std::vector AddedFiles; std::string DefaultArtifactDir; bool AddedDefaultCertificate = false; diff --git a/Tests/RunCMake/cmake_language/Experimental/WindowsKernelModeDriver-set.cmake b/Tests/RunCMake/cmake_language/Experimental/WindowsKernelModeDriver-set.cmake index f9e22c5c38..517cc2b995 100644 --- a/Tests/RunCMake/cmake_language/Experimental/WindowsKernelModeDriver-set.cmake +++ b/Tests/RunCMake/cmake_language/Experimental/WindowsKernelModeDriver-set.cmake @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER - "fac18f65-504e-4dbb-b068-f356bb1f2ddb") + "9157bf90-2313-44d6-aefa-67cd83c8be7c") cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED "WindowsKernelModeDriver"