From 051cea7b7ecb2dd84199407165843006765588cf Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 17 Jul 2023 14:12:10 -0400 Subject: cmExperimental: Expose feature data API --- Source/cmExperimental.cxx | 18 ++++++++---------- Source/cmExperimental.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 0a746a9..8dc2b72 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -18,14 +18,7 @@ namespace { * Search for other instances to keep the documentation and test suite * up-to-date. */ - -struct FeatureData -{ - std::string const Uuid; - std::string const Variable; - std::string const Description; - bool Warned; -} LookupTable[] = { +cmExperimental::FeatureData LookupTable[] = { // CxxModuleCMakeApi { "bf70d4b0-9fb7-465c-9803-34014e70d112", "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API", @@ -37,17 +30,22 @@ static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == static_cast(cmExperimental::Feature::Sentinel), "Experimental feature lookup table mismatch"); -FeatureData& DataForFeature(cmExperimental::Feature f) +cmExperimental::FeatureData& DataForFeature(cmExperimental::Feature f) { assert(f != cmExperimental::Feature::Sentinel); return LookupTable[static_cast(f)]; } } +const cmExperimental::FeatureData& cmExperimental::DataForFeature(Feature f) +{ + return ::DataForFeature(f); +} + bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f) { bool enabled = false; - auto& data = DataForFeature(f); + auto& data = ::DataForFeature(f); auto value = mf.GetDefinition(data.Variable); if (value == data.Uuid) { diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index 26e0d17..97eb586 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -5,6 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include + class cmMakefile; class cmExperimental @@ -17,5 +19,14 @@ public: Sentinel, }; + struct FeatureData + { + std::string const Uuid; + std::string const Variable; + std::string const Description; + bool Warned; + }; + + static const FeatureData& DataForFeature(Feature f); static bool HasSupportEnabled(cmMakefile const& mf, Feature f); }; -- cgit v0.12 From 1ca82e7a04b16159721c44385c3b5b8a2762f735 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 17 Jul 2023 11:05:38 -0400 Subject: cmake_language(): Add undocumented GET_EXPERIMENTAL_FEATURE_ENABLED mode --- Source/cmCMakeLanguageCommand.cxx | 46 +++++++++++++++++++++++++++++++++++++++ Source/cmExperimental.cxx | 2 +- Source/cmExperimental.h | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Source/cmCMakeLanguageCommand.cxx b/Source/cmCMakeLanguageCommand.cxx index c7e9209..d65543a 100644 --- a/Source/cmCMakeLanguageCommand.cxx +++ b/Source/cmCMakeLanguageCommand.cxx @@ -17,6 +17,7 @@ #include "cmArgumentParserTypes.h" #include "cmDependencyProvider.h" #include "cmExecutionStatus.h" +#include "cmExperimental.h" #include "cmGlobalGenerator.h" #include "cmListFileCache.h" #include "cmMakefile.h" @@ -328,6 +329,46 @@ bool cmCMakeLanguageCommandGET_MESSAGE_LOG_LEVEL( makefile.AddDefinition(outputVariable, outputValue); return true; } + +bool cmCMakeLanguageCommandGET_EXPERIMENTAL_FEATURE_ENABLED( + std::vector const& args, cmExecutionStatus& status) +{ + cmMakefile& makefile = status.GetMakefile(); + std::vector expandedArgs; + makefile.ExpandArguments(args, expandedArgs); + + if (expandedArgs.size() != 3) { + return FatalError(status, + "sub-command GET_EXPERIMENTAL_FEATURE_ENABLED expects " + "exactly two arguments"); + } + + auto const& featureName = expandedArgs[1]; + auto const& variableName = expandedArgs[2]; + + auto feature = cmExperimental::Feature::Sentinel; + for (std::size_t i = 0; + i < static_cast(cmExperimental::Feature::Sentinel); i++) { + if (cmExperimental::DataForFeature(static_cast(i)) + .Name == featureName) { + feature = static_cast(i); + break; + } + } + if (feature == cmExperimental::Feature::Sentinel) { + return FatalError(status, + cmStrCat("Experimental feature name \"", featureName, + "\" does not exist.")); + } + + if (cmExperimental::HasSupportEnabled(makefile, feature)) { + makefile.AddDefinition(variableName, "TRUE"); + } else { + makefile.AddDefinition(variableName, "FALSE"); + } + + return true; +} } bool cmCMakeLanguageCommand(std::vector const& args, @@ -480,5 +521,10 @@ bool cmCMakeLanguageCommand(std::vector const& args, return cmCMakeLanguageCommandGET_MESSAGE_LOG_LEVEL(args, status); } + if (expArgs[expArg] == "GET_EXPERIMENTAL_FEATURE_ENABLED") { + return cmCMakeLanguageCommandGET_EXPERIMENTAL_FEATURE_ENABLED(args, + status); + } + return FatalError(status, "called with unknown meta-operation"); } diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 8dc2b72..bdbd353 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -20,7 +20,7 @@ namespace { */ cmExperimental::FeatureData LookupTable[] = { // CxxModuleCMakeApi - { "bf70d4b0-9fb7-465c-9803-34014e70d112", + { "CxxModuleCMakeApi", "bf70d4b0-9fb7-465c-9803-34014e70d112", "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API", "CMake's C++ module support is experimental. It is meant only for " "experimentation and feedback to CMake developers.", diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index 97eb586..46c5fb7 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -21,6 +21,7 @@ public: struct FeatureData { + std::string const Name; std::string const Uuid; std::string const Variable; std::string const Description; -- cgit v0.12 From d84681d8f068225f786453a5a77791a1eb8e5459 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 17 Jul 2023 14:02:33 -0400 Subject: try_compile(): Pass down CMAKE_EXPERIMENTAL_* feature flags --- Source/cmCoreTryCompile.cxx | 12 ++++++++++++ Source/cmExperimental.cxx | 1 + Source/cmExperimental.h | 1 + 3 files changed, 14 insertions(+) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 7d4ab50..586db1b 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -18,6 +18,7 @@ #include "cmArgumentParser.h" #include "cmConfigureLog.h" +#include "cmExperimental.h" #include "cmExportTryCompileFileGenerator.h" #include "cmGlobalGenerator.h" #include "cmList.h" @@ -1068,6 +1069,17 @@ cm::optional cmCoreTryCompile::TryCompileCode( cmakeVariables.emplace("CMAKE_OSX_ARCHITECTURES", *tcArchs); } + // Pass down CMAKE_EXPERIMENTAL_* feature flags + for (std::size_t i = 0; + i < static_cast(cmExperimental::Feature::Sentinel); + i++) { + auto const& data = cmExperimental::DataForFeature( + static_cast(i)); + if (data.ForwardThroughTryCompile) { + vars.insert(data.Variable); + } + } + for (std::string const& var : vars) { if (cmValue val = this->Makefile->GetDefinition(var)) { std::string flag = "-D" + var + "=" + *val; diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index bdbd353..5d25f66 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -24,6 +24,7 @@ cmExperimental::FeatureData LookupTable[] = { "CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API", "CMake's C++ module support is experimental. It is meant only for " "experimentation and feedback to CMake developers.", + false, // https://gitlab.kitware.com/cmake/cmake/-/issues/25097 false }, }; static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index 46c5fb7..bd84bb3 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -25,6 +25,7 @@ public: std::string const Uuid; std::string const Variable; std::string const Description; + bool const ForwardThroughTryCompile; bool Warned; }; -- cgit v0.12 From b01f5eb079ad2cb2ac4a114132f6bd12daa712d9 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 13 Mar 2023 13:54:37 -0700 Subject: Windows: Add experimental WindowsKernelModeDriver platform --- Modules/Platform/Windows-MSVC.cmake | 24 ++++++++++++++++++++-- Modules/Platform/Windows.cmake | 6 +++++- .../WindowsKernelModeDriver-Initialize.cmake | 11 ++++++++++ .../Platform/WindowsKernelModeDriver-MSVC-C.cmake | 1 + .../WindowsKernelModeDriver-MSVC-CXX.cmake | 1 + Modules/Platform/WindowsKernelModeDriver.cmake | 1 + Source/cmExperimental.cxx | 6 ++++++ Source/cmExperimental.h | 1 + 8 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 Modules/Platform/WindowsKernelModeDriver-Initialize.cmake create mode 100644 Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake create mode 100644 Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake create mode 100644 Modules/Platform/WindowsKernelModeDriver.cmake diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 8e96bf4..829ab9b 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -28,6 +28,8 @@ endif() if(CMAKE_SYSTEM_NAME STREQUAL "WindowsCE") set(_PLATFORM_LINK_FLAGS " /subsystem:windowsce") +elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(_PLATFORM_LINK_FLAGS " -subsystem:native -kernel -MANIFEST:NO") else() set(_PLATFORM_LINK_FLAGS "") endif() @@ -223,6 +225,18 @@ elseif(WINDOWS_PHONE OR WINDOWS_STORE) else() set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") endif() +elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(CMAKE_C_STANDARD_LIBRARIES_INIT "") + set(_FLAGS_C " -kernel") + set(_FLAGS_CXX " -kernel") + foreach(t EXE SHARED MODULE) + string(APPEND CMAKE_${t}_LINKER_FLAGS_INIT " -NODEFAULTLIB") + endforeach() + if((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "x64") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "x64")) + set(_PLATFORM_DEFINES "${_PLATFORM_DEFINES} -D_AMD64_ -DAMD64") + elseif((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64")) + set(_PLATFORM_DEFINES "${_PLATFORM_DEFINES} -D_ARM64_ -DARM64") + endif() else() set(_PLATFORM_DEFINES "/DWIN32") if((_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64EC") OR (_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64EC")) @@ -294,7 +308,7 @@ endif() # add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype # on versions that support it set( MSVC_INCREMENTAL_YES_FLAG "") -if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE) +if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") if(NOT MSVC_INCREMENTAL_DEFAULT) set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES") else() @@ -353,8 +367,14 @@ macro(__windows_compiler_msvc lang) set(_CMAKE_VS_LINK_DLL " -E vs_link_dll --intdir= --rc= --mt= --manifests -- ") set(_CMAKE_VS_LINK_EXE " -E vs_link_exe --intdir= --rc= --mt= --manifests -- ") endif() + if(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(_DLL_DRIVER "-driver") + else() + set(_DLL_DRIVER "/dll") + endif() set(CMAKE_${lang}_CREATE_SHARED_LIBRARY - "${_CMAKE_VS_LINK_DLL} ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out: /implib: /pdb: /dll /version:.${_PLATFORM_LINK_FLAGS} ${CMAKE_END_TEMP_FILE}") + "${_CMAKE_VS_LINK_DLL} ${CMAKE_CL_NOLOGO} ${CMAKE_START_TEMP_FILE} /out: /implib: /pdb: ${_DLL_DRIVER} /version:.${_PLATFORM_LINK_FLAGS} ${CMAKE_END_TEMP_FILE}") + unset(_DLL_DRIVER) set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY}) set(CMAKE_${lang}_CREATE_STATIC_LIBRARY " ${CMAKE_CL_NOLOGO} /out: ") diff --git a/Modules/Platform/Windows.cmake b/Modules/Platform/Windows.cmake index 8697e7a..1bf39cf 100644 --- a/Modules/Platform/Windows.cmake +++ b/Modules/Platform/Windows.cmake @@ -1,7 +1,11 @@ set(CMAKE_STATIC_LIBRARY_PREFIX "") set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib -set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so +if(CMAKE_SYSTEM_NAME STREQUAL "WindowsKernelModeDriver") + set(CMAKE_SHARED_LIBRARY_SUFFIX ".sys") # .so +else() + set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") # .so +endif() set(CMAKE_IMPORT_LIBRARY_PREFIX "") set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib") set(CMAKE_EXECUTABLE_SUFFIX ".exe") # .exe diff --git a/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake new file mode 100644 index 0000000..6f0ef33 --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-Initialize.cmake @@ -0,0 +1,11 @@ +# undocumented, do not use outside of CMake +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED "WindowsKernelModeDriver" _cmake_windows_kernel_mode_driver_enabled) +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/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake b/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake new file mode 100644 index 0000000..ce8060b --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-MSVC-C.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-C) diff --git a/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake b/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake new file mode 100644 index 0000000..281eadc --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver-MSVC-CXX.cmake @@ -0,0 +1 @@ +include(Platform/Windows-MSVC-CXX) diff --git a/Modules/Platform/WindowsKernelModeDriver.cmake b/Modules/Platform/WindowsKernelModeDriver.cmake new file mode 100644 index 0000000..65b2eae --- /dev/null +++ b/Modules/Platform/WindowsKernelModeDriver.cmake @@ -0,0 +1 @@ +include(Platform/Windows) diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 5d25f66..51c174e 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -26,6 +26,12 @@ cmExperimental::FeatureData LookupTable[] = { "experimentation and feedback to CMake developers.", false, // https://gitlab.kitware.com/cmake/cmake/-/issues/25097 false }, + // WindowsKernelModeDriver + { "WindowsKernelModeDriver", "5c2d848d-4efa-4529-a768-efd57171bf68", + "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.", + true, false }, }; static_assert(sizeof(LookupTable) / sizeof(LookupTable[0]) == static_cast(cmExperimental::Feature::Sentinel), diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index bd84bb3..3374ba8 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -15,6 +15,7 @@ public: enum class Feature { CxxModuleCMakeApi, + WindowsKernelModeDriver, Sentinel, }; -- cgit v0.12