Experimental: provide useful warning for invalid experimental variable values

Provide a useful warning if an invalid UUID is given in a
`CMAKE_EXPERIMENTAL_` variable.  This can occur if a different CMake
version is used than the one that the feature was implemented with, or
if there is a simple typo in the value.  It should reduce confusion with
the use of experimental features.

Co-authored-by: Brad King <brad.king@kitware.com>
This commit is contained in:
Bill Hoffman
2025-05-12 14:48:44 -04:00
committed by Brad King
parent b05e5403d9
commit 9036aa10f3
8 changed files with 152 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmValue.h"
namespace {
@@ -120,6 +121,16 @@ bool cmExperimental::HasSupportEnabled(cmMakefile const& mf, Feature f)
if (mf.GetGlobalGenerator()->ShouldWarnExperimental(data.Name, *value)) {
if (enabled) {
mf.IssueMessage(MessageType::AUTHOR_WARNING, data.Description);
} else {
mf.IssueMessage(
MessageType::AUTHOR_WARNING,
cmStrCat(
data.Variable, " is set to incorrect value\n ", value, '\n',
"See 'Help/dev/experimental.rst' in the source tree of this "
"version of CMake for documentation of the experimental feature "
"and the corresponding activation value. This project's code "
"may require changes to work with this CMake's version of the "
"feature."));
}
}
}

View File

@@ -0,0 +1,25 @@
^CMake Warning \(dev\) at Experimental/CxxImportStd-wrong\.cmake:4 \(cmake_language\):
CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is set to incorrect value
01234567-0123-0123-0123-0123456789ab
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.
+
CMake Warning \(dev\) at Experimental/CxxImportStd-wrong\.cmake:19 \(cmake_language\):
CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is set to incorrect value
76543210-3210-3210-3210-ba9876543210
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.$

View File

@@ -0,0 +1,21 @@
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
"01234567-0123-0123-0123-0123456789ab")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"CxxImportStd"
feature_present)
if (NOT feature_present STREQUAL "FALSE")
message(FATAL_ERROR
"Expected the `CxxImportStd` feature to be disabled.")
endif ()
# Test if/when warning is repeated.
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"CxxImportStd"
feature_present)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
"76543210-3210-3210-3210-ba9876543210")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"CxxImportStd"
feature_present)

View File

@@ -0,0 +1,25 @@
^CMake Warning \(dev\) at Experimental/ExportPackageDependencies-wrong\.cmake:4 \(cmake_language\):
CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES is set to incorrect value
01234567-0123-0123-0123-0123456789ab
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.
+
CMake Warning \(dev\) at Experimental/ExportPackageDependencies-wrong\.cmake:19 \(cmake_language\):
CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES is set to incorrect value
76543210-3210-3210-3210-ba9876543210
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.$

View File

@@ -0,0 +1,21 @@
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES
"01234567-0123-0123-0123-0123456789ab")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"ExportPackageDependencies"
feature_present)
if (NOT feature_present STREQUAL "FALSE")
message(FATAL_ERROR
"Expected the `ExportPackageDependencies` feature to be disabled.")
endif ()
# Test if/when warning is repeated.
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"ExportPackageDependencies"
feature_present)
set(CMAKE_EXPERIMENTAL_EXPORT_PACKAGE_DEPENDENCIES
"76543210-3210-3210-3210-ba9876543210")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"ExportPackageDependencies"
feature_present)

View File

@@ -0,0 +1,25 @@
^CMake Warning \(dev\) at Experimental/WindowsKernelModeDriver-wrong\.cmake:4 \(cmake_language\):
CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER is set to incorrect value
01234567-0123-0123-0123-0123456789ab
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.
+
CMake Warning \(dev\) at Experimental/WindowsKernelModeDriver-wrong\.cmake:19 \(cmake_language\):
CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER is set to incorrect value
76543210-3210-3210-3210-ba9876543210
See 'Help/dev/experimental\.rst' in the source tree of this version of CMake
for documentation of the experimental feature and the corresponding
activation value\. This project's code may require changes to work with
this CMake's version of the feature\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.$

View File

@@ -0,0 +1,21 @@
set(CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER
"01234567-0123-0123-0123-0123456789ab")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"WindowsKernelModeDriver"
feature_present)
if (NOT feature_present STREQUAL "FALSE")
message(FATAL_ERROR
"Expected the `WindowsKernelModeDriver` feature to be disabled.")
endif ()
# Test if/when warning is repeated.
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"WindowsKernelModeDriver"
feature_present)
set(CMAKE_EXPERIMENTAL_WINDOWS_KERNEL_MODE_DRIVER
"76543210-3210-3210-3210-ba9876543210")
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
"WindowsKernelModeDriver"
feature_present)

View File

@@ -159,8 +159,11 @@ run_cmake_command(
run_cmake(Experimental/CxxImportStd-set)
run_cmake(Experimental/CxxImportStd-unset)
run_cmake(Experimental/CxxImportStd-wrong)
run_cmake(Experimental/ExportPackageDependencies-set)
run_cmake(Experimental/ExportPackageDependencies-unset)
run_cmake(Experimental/ExportPackageDependencies-wrong)
run_cmake(Experimental/WindowsKernelModeDriver-set)
run_cmake(Experimental/WindowsKernelModeDriver-unset)
run_cmake(Experimental/WindowsKernelModeDriver-wrong)
run_cmake(Experimental/Unknown)