Merge topic 'cmake-diagnostics-variables'

72e7305c3e Diagnostics: Handle CMAKE_{WARN,ERROR}_DEPRECATED
be057c5a01 cmVariableWatch: Use enum for access type
cba542f32c cmake.cxx: Organize includes

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11948
This commit is contained in:
Brad King
2026-05-08 11:43:29 +00:00
committed by Kitware Robot
29 changed files with 408 additions and 85 deletions

View File

@@ -44,12 +44,10 @@ influences the way the message is handled:
CMake Warning, continue processing.
``AUTHOR_WARNING``
CMake Warning (dev), continue processing.
CMake :diagnostic:`CMD_AUTHOR` diagnostic.
``DEPRECATION``
CMake Deprecation Error or Warning if variable
:variable:`CMAKE_ERROR_DEPRECATED` or :variable:`CMAKE_WARN_DEPRECATED`
is enabled, respectively, else no message.
CMake :diagnostic:`CMD_DEPRECATED` diagnostic.
(none) or ``NOTICE``
Important message printed to stderr to attract user's attention.

View File

@@ -7,3 +7,11 @@ CMD_DEPRECATED
Warn about use of a deprecated function or package. This is the category
triggered by :command:`message(DEPRECATION)`.
.. note::
If :policy:`CMP0218` is not set to ``NEW``, :command:`message(DEPRECATION)`
invocations, along with builtin deprecation messages that existed prior to
CMake 4.4, will ignore this diagnostic state and will instead use the
:variable:`CMAKE_WARN_DEPRECATED` and :variable:`CMAKE_ERROR_DEPRECATED`
variables to determine the severity of deprecation messages.

View File

@@ -100,6 +100,7 @@ Policies Introduced by CMake 4.4
.. toctree::
:maxdepth: 1
CMP0218: The CMAKE_WARN_DEPRECATED and CMAKE_ERROR_DEPRECATED variables are ignored. </policy/CMP0218>
CMP0217: The MACROS directory property does not exist anymore. </policy/CMP0217>
CMP0216: Swift targets have a default project name. </policy/CMP0216>
CMP0215: Ninja generators emit Swift modules separately from compilation. </policy/CMP0215>

View File

@@ -224,7 +224,6 @@ Variables that Change Behavior
/variable/CMAKE_ECLIPSE_MAKE_ARGUMENTS
/variable/CMAKE_ECLIPSE_RESOURCE_ENCODING
/variable/CMAKE_ECLIPSE_VERSION
/variable/CMAKE_ERROR_DEPRECATED
/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
/variable/CMAKE_EXECUTE_PROCESS_COMMAND_ECHO
/variable/CMAKE_EXECUTE_PROCESS_COMMAND_ERROR_IS_FATAL
@@ -318,7 +317,6 @@ Variables that Change Behavior
/variable/CMAKE_TLS_VERIFY
/variable/CMAKE_TLS_VERSION
/variable/CMAKE_USER_MAKE_RULES_OVERRIDE
/variable/CMAKE_WARN_DEPRECATED
/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
/variable/CMAKE_XCODE_GENERATE_SCHEME
/variable/CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY
@@ -878,8 +876,10 @@ Deprecated Variables that Change Behavior
/variable/CMAKE_AUTOMOC_RELAXED_MODE
/variable/CMAKE_BACKWARDS_COMPATIBILITY
/variable/CMAKE_ERROR_DEPRECATED
/variable/CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
/variable/CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
/variable/CMAKE_WARN_DEPRECATED
Deprecated Variables that Describe the System
=============================================

35
Help/policy/CMP0218.rst Normal file
View File

@@ -0,0 +1,35 @@
CMP0218
-------
.. versionadded:: 4.4
The :variable:`CMAKE_WARN_DEPRECATED` and :variable:`CMAKE_ERROR_DEPRECATED`
variables are ignored.
In CMake 4.3 and below, these variables controlled whether deprecation messages
resulted in warnings, errors, or were suppressed.
CMake 4.4 introduced a new, unified system for managing
:manual:`diagnostics <cmake-diagnostics(7)>` that prefers the
:command:`cmake_diagnostic` command for manipulating diagnostic actions.
This policy provides compatibility with projects that relied on these variables
and have not been updated to be aware of the change.
The ``OLD`` behavior for this policy is to use the variables to control
deprecation messages which existed prior to CMake 4.4.
The ``NEW`` behavior does not ascribe any special meaning to these variables
and uses the :diagnostic:`CMD_DEPRECATED` diagnostic state to control all
deprecation messages.
Any deprecation messages introduced in CMake 4.4 or later are controlled by the
:diagnostic:`CMD_DEPRECATED` diagnostic regardless of the setting of this
policy.
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 4.4
.. |WARNS_OR_DOES_NOT_WARN| replace::
warns when either variable is accessed or modified
.. include:: include/STANDARD_ADVICE.rst
.. include:: include/DEPRECATED.rst

View File

@@ -5,5 +5,28 @@ CMAKE_ERROR_DEPRECATED
Whether to issue errors for deprecated functionality.
If ``TRUE``, use of deprecated functionality will issue fatal errors.
If this variable is not set, CMake behaves as if it were set to ``FALSE``.
This is a deprecated mechanism for interacting with the
:diagnostic:`CMD_DEPRECATED` :manual:`diagnostic <cmake-diagnostics(7)>`.
If policy :policy:`CMP0218` is set to ``NEW``, this variable is ignored.
If policy :policy:`CMP0218` is not set to ``NEW``, the :command:`message`
command's ``DEPRECATION`` message type will use
:variable:`CMAKE_WARN_DEPRECATED` and ``CMAKE_ERROR_DEPRECATED``
to determine the severity of a deprecation diagnostic. The severity will be:
* ``IGNORE``, if ``CMAKE_WARN_DEPRECATED`` is ``OFF`` and
``CMAKE_ERROR_DEPRECATED`` is unset or ``OFF``.
* ``WARN``, if ``CMAKE_WARN_DEPRECATED`` is unset or ``ON`` and
``CMAKE_ERROR_DEPRECATED`` is unset or ``OFF``.
* ``FATAL_ERROR`` if ``CMAKE_ERROR_DEPRECATED`` is ``ON``.
Setting ``CMAKE_ERROR_DEPRECATED`` in the cache will alter the default state of
the :diagnostic:`CMD_DEPRECATED` :manual:`diagnostic <cmake-diagnostics(7)>`;
however, the :option:`-W[no-][error=]deprecated <cmake -W>` option, and
:preset:`warnings.deprecated <configurePresets.warnings.deprecated>` and/or
:preset:`errors.deprecated <configurePresets.errors.deprecated>` preset
fields, will take precedence. CMake will also update the cached value of
``CMAKE_ERROR_DEPRECATED`` to reflect the actual state of the diagnostic as of
the start of script execution.

View File

@@ -5,9 +5,28 @@ CMAKE_WARN_DEPRECATED
Whether to issue warnings for deprecated functionality.
If not ``FALSE``, use of deprecated functionality will issue warnings.
If this variable is not set, CMake behaves as if it were set to ``TRUE``.
This is a deprecated mechanism for interacting with the
:diagnostic:`CMD_DEPRECATED` :manual:`diagnostic <cmake-diagnostics(7)>`.
If policy :policy:`CMP0218` is set to ``NEW``, this variable is ignored.
When running :manual:`cmake(1)`, this option can be enabled with the
:option:`-Wdeprecated <cmake -W>` option, or disabled with the
:option:`-Wno-deprecated <cmake -Wno->` option.
If policy :policy:`CMP0218` is not set to ``NEW``, the :command:`message`
command's ``DEPRECATION`` message type will use
``CMAKE_WARN_DEPRECATED`` and :variable:`CMAKE_ERROR_DEPRECATED`
to determine the severity of a deprecation diagnostic. The severity will be:
* ``IGNORE``, if ``CMAKE_WARN_DEPRECATED`` is ``OFF`` and
``CMAKE_ERROR_DEPRECATED`` is unset or ``OFF``.
* ``WARN``, if ``CMAKE_WARN_DEPRECATED`` is unset or ``ON`` and
``CMAKE_ERROR_DEPRECATED`` is unset or ``OFF``.
* ``FATAL_ERROR`` if ``CMAKE_ERROR_DEPRECATED`` is ``ON``.
Setting ``CMAKE_WARN_DEPRECATED`` in the cache will alter the default state of
the :diagnostic:`CMD_DEPRECATED` :manual:`diagnostic <cmake-diagnostics(7)>`;
however, the :option:`-W[no-][error=]deprecated <cmake -W>` option, and
:preset:`warnings.deprecated <configurePresets.warnings.deprecated>` and/or
:preset:`errors.deprecated <configurePresets.errors.deprecated>` preset
fields, will take precedence. CMake will also update the cached value of
``CMAKE_WARN_DEPRECATED`` to reflect the actual state of the diagnostic as of
the start of script execution.

View File

@@ -4136,6 +4136,34 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
id == cmPolicies::CMP0126 || id == cmPolicies::CMP0128 ||
id == cmPolicies::CMP0136 || id == cmPolicies::CMP0141 ||
id == cmPolicies::CMP0155))) {
std::unique_ptr<PolicyPushPop> ps;
std::unique_ptr<DiagnosticPushPop> ds;
cmPolicies::PolicyStatus const cmp0218 =
this->GetPolicyStatus(cmPolicies::CMP0218);
if (cmp0218 != cmPolicies::NEW) {
if (cmp0218 != cmPolicies::OLD) {
// Suppress warnings about using old variables.
ps = cm::make_unique<PolicyPushPop>(this);
this->SetPolicy(cmPolicies::CMP0218, cmPolicies::OLD);
}
ds = cm::make_unique<DiagnosticPushPop>(this);
// Use old variables to determine diagnostic action.
cmValue const warn = this->GetDefinition("CMAKE_WARN_DEPRECATED");
if (warn.IsSet() && !warn.IsOn()) {
this->SetDiagnostic(cmDiagnostics::CMD_DEPRECATED,
cmDiagnostics::Ignore);
} else if (this->IsOn("CMAKE_ERROR_DEPRECATED")) {
this->SetDiagnostic(cmDiagnostics::CMD_DEPRECATED,
cmDiagnostics::SendError);
} else {
this->SetDiagnostic(cmDiagnostics::CMD_DEPRECATED,
cmDiagnostics::Warn);
}
}
this->IssueDiagnostic(cmDiagnostics::CMD_DEPRECATED,
cmPolicies::GetPolicyDeprecatedWarning(id));
}

View File

@@ -3,9 +3,9 @@
#include "cmMessageCommand.h"
#include <cassert>
#include <memory>
#include <utility>
#include <cm/memory>
#include <cm/string_view>
#include <cmext/string_view>
@@ -16,9 +16,11 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmRange.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmake.h"
#ifdef CMake_ENABLE_DEBUGGER
@@ -96,6 +98,7 @@ bool cmMessageCommand(std::vector<std::string> const& args,
auto i = args.cbegin();
std::unique_ptr<cmMakefile::DiagnosticPushPop> ds;
auto category = cmDiagnostics::CMD_NONE;
auto type = MessageType::MESSAGE;
auto fatal = false;
@@ -116,7 +119,7 @@ bool cmMessageCommand(std::vector<std::string> const& args,
++i;
} else if (*i == "AUTHOR_WARNING") {
category = cmDiagnostics::CMD_AUTHOR;
switch (mf.GetDiagnosticAction(cmDiagnostics::CMD_AUTHOR)) {
switch (mf.GetDiagnosticAction(category)) {
case cmDiagnostics::Ignore:
return true;
case cmDiagnostics::FatalError:
@@ -166,7 +169,34 @@ bool cmMessageCommand(std::vector<std::string> const& args,
++i;
} else if (*i == "DEPRECATION") {
category = cmDiagnostics::CMD_DEPRECATED;
switch (mf.GetDiagnosticAction(cmDiagnostics::CMD_DEPRECATED)) {
cmPolicies::PolicyStatus const cmp0218 =
mf.GetPolicyStatus(cmPolicies::CMP0218);
if (cmp0218 != cmPolicies::NEW) {
std::unique_ptr<cmMakefile::PolicyPushPop> ps;
if (cmp0218 != cmPolicies::OLD) {
// Suppress warnings about using old variables.
ps = cm::make_unique<cmMakefile::PolicyPushPop>(&mf);
mf.SetPolicy(cmPolicies::CMP0218, cmPolicies::OLD);
}
ds = cm::make_unique<cmMakefile::DiagnosticPushPop>(&mf);
// Use old variables to determine diagnostic action.
if (mf.IsOn("CMAKE_ERROR_DEPRECATED")) {
mf.SetDiagnostic(category, cmDiagnostics::FatalError);
} else {
cmValue const warn = mf.GetDefinition("CMAKE_WARN_DEPRECATED");
if (warn.IsSet() && !warn.IsOn()) {
mf.SetDiagnostic(category, cmDiagnostics::Ignore);
} else {
mf.SetDiagnostic(category, cmDiagnostics::Warn);
}
}
}
switch (mf.GetDiagnosticAction(category)) {
case cmDiagnostics::Ignore:
return true;
case cmDiagnostics::FatalError:

View File

@@ -650,7 +650,11 @@ class cmMakefile;
0, WARN) \
SELECT(POLICY, CMP0217, \
"The MACROS directory property does not exist anymore.", 4, 4, 0, \
WARN)
WARN) \
SELECT(POLICY, CMP0218, \
"The CMAKE_WARN_DEPRECATED and CMAKE_ERROR_DEPRECATED variables " \
"are ignored.", \
4, 4, 0, WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \

View File

@@ -7,16 +7,16 @@
#include <utility>
#include <vector>
std::string const& cmVariableWatch::GetAccessAsString(int access_type)
std::string const& cmVariableWatch::GetAccessAsString(AccessType accessType)
{
static std::array<std::string, 6> const cmVariableWatchAccessStrings = {
{ "READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS",
"MODIFIED_ACCESS", "REMOVED_ACCESS", "NO_ACCESS" }
};
if (access_type < 0 || access_type >= cmVariableWatch::NO_ACCESS) {
access_type = cmVariableWatch::NO_ACCESS;
if (accessType >= cmVariableWatch::NO_ACCESS) {
accessType = cmVariableWatch::NO_ACCESS;
}
return cmVariableWatchAccessStrings[access_type];
return cmVariableWatchAccessStrings[accessType];
}
cmVariableWatch::cmVariableWatch() = default;
@@ -63,7 +63,8 @@ void cmVariableWatch::RemoveWatch(std::string const& variable,
}
bool cmVariableWatch::VariableAccessed(std::string const& variable,
int access_type, char const* newValue,
AccessType accessType,
char const* newValue,
cmMakefile const* mf) const
{
auto mit = this->WatchMap.find(variable);
@@ -77,7 +78,7 @@ bool cmVariableWatch::VariableAccessed(std::string const& variable,
// lockable, and so this ensures we don't attempt to call into freed
// memory
if (auto it = weak_it.lock()) {
it->Method(variable, access_type, it->ClientData, newValue, mf);
it->Method(variable, accessType, it->ClientData, newValue, mf);
}
}
return true;

View File

@@ -19,8 +19,21 @@ class cmMakefile;
class cmVariableWatch
{
public:
using WatchMethod = void (*)(std::string const&, int, void*, char const*,
cmMakefile const*);
/**
* Different access types.
*/
enum AccessType : unsigned
{
VARIABLE_READ_ACCESS,
UNKNOWN_VARIABLE_READ_ACCESS,
UNKNOWN_VARIABLE_DEFINED_ACCESS,
VARIABLE_MODIFIED_ACCESS,
VARIABLE_REMOVED_ACCESS,
NO_ACCESS
};
using WatchMethod = void (*)(std::string const&, AccessType, void*,
char const*, cmMakefile const*);
using DeleteData = void (*)(void*);
cmVariableWatch();
@@ -37,26 +50,13 @@ public:
/**
* This method is called when variable is accessed
*/
bool VariableAccessed(std::string const& variable, int access_type,
bool VariableAccessed(std::string const& variable, AccessType accessType,
char const* newValue, cmMakefile const* mf) const;
/**
* Different access types.
*/
enum
{
VARIABLE_READ_ACCESS,
UNKNOWN_VARIABLE_READ_ACCESS,
UNKNOWN_VARIABLE_DEFINED_ACCESS,
VARIABLE_MODIFIED_ACCESS,
VARIABLE_REMOVED_ACCESS,
NO_ACCESS
};
/**
* Return the access as string
*/
static std::string const& GetAccessAsString(int access_type);
static std::string const& GetAccessAsString(AccessType accessType);
protected:
struct Pair

View File

@@ -25,20 +25,19 @@ struct cmVariableWatchCallbackData
std::string Command;
};
void cmVariableWatchCommandVariableAccessed(std::string const& variable,
int access_type, void* client_data,
char const* newValue,
cmMakefile const* mf)
void cmVariableWatchCommandVariableAccessed(
std::string const& variable, cmVariableWatch::AccessType accessType,
void* clientData, char const* newValue, cmMakefile const* mf)
{
cmVariableWatchCallbackData* data =
static_cast<cmVariableWatchCallbackData*>(client_data);
static_cast<cmVariableWatchCallbackData*>(clientData);
if (data->InCallback) {
return;
}
data->InCallback = true;
auto accessString = cmVariableWatch::GetAccessAsString(access_type);
auto accessString = cmVariableWatch::GetAccessAsString(accessType);
/// Ultra bad!!
cmMakefile* makefile = const_cast<cmMakefile*>(mf);

View File

@@ -40,14 +40,6 @@
#include "cmCMakePresetsGraph.h"
#include "cmCommandLineArgument.h"
#include "cmCommands.h"
#ifdef CMake_ENABLE_DEBUGGER
# include "cmDebuggerAdapter.h"
# ifdef _WIN32
# include "cmDebuggerWindowsPipeConnection.h"
# else //!_WIN32
# include "cmDebuggerPosixPipeConnection.h"
# endif //_WIN32
#endif
#include "cmDocumentation.h"
#include "cmDocumentationEntry.h"
#include "cmDuration.h"
@@ -57,18 +49,13 @@
#include "cmGlobCacheEntry.h" // IWYU pragma: keep
#include "cmGlobalGenerator.h"
#include "cmGlobalGeneratorFactory.h"
#include "cmJSONState.h"
#include "cmLinkLineComputer.h"
#include "cmList.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#if !defined(CMAKE_BOOTSTRAP)
# include "cmMakefileProfilingData.h"
#endif
#include "cmJSONState.h"
#include "cmList.h"
#include "cmMessenger.h"
#ifndef CMAKE_BOOTSTRAP
# include "cmSarifLog.h"
#endif
#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStringAlgorithms.h"
@@ -80,6 +67,15 @@
#include "cmVersionConfig.h"
#include "cmWorkingDirectory.h"
#ifdef CMake_ENABLE_DEBUGGER
# include "cmDebuggerAdapter.h"
# ifdef _WIN32
# include "cmDebuggerWindowsPipeConnection.h"
# else //!_WIN32
# include "cmDebuggerPosixPipeConnection.h"
# endif //_WIN32
#endif
#if !defined(CMAKE_BOOTSTRAP)
# include <unordered_map>
@@ -92,6 +88,8 @@
# include "cmGraphVizWriter.h"
# include "cmInstrumentation.h"
# include "cmInstrumentationQuery.h"
# include "cmMakefileProfilingData.h"
# include "cmSarifLog.h"
# include "cmVariableWatch.h"
#endif
@@ -169,13 +167,25 @@ using CommandArgument =
cmCommandLineArgument<bool(std::string const& value, cmake* state)>;
#ifndef CMAKE_BOOTSTRAP
void cmWarnUnusedCliWarning(std::string const& variable, int /*unused*/,
void* ctx, char const* /*unused*/,
void cmWarnUnusedCliWarning(std::string const& variable,
cmVariableWatch::AccessType /*unused*/, void* ctx,
char const* /*unused*/,
cmMakefile const* /*unused*/)
{
cmake* cm = reinterpret_cast<cmake*>(ctx);
cm->MarkCliAsUsed(variable);
}
void cmDeprecatedWatch(std::string const& /*unused*/,
cmVariableWatch::AccessType /*unused*/,
void* /*unused*/, char const* /*unused*/,
cmMakefile const* mf)
{
if (mf->GetPolicyStatus(cmPolicies::CMP0218) == cmPolicies::WARN) {
mf->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0218));
}
}
#endif
void warnDeprecated(cm::string_view oldOption, cm::string_view newOption)
@@ -832,6 +842,15 @@ void cmake::ProcessCacheArg(std::string const& var, std::string const& value,
}
}
// See also CMP0218.
if (var == "CMAKE_WARN_DEPRECATED") {
std::cerr << "The CMAKE_WARN_DEPRECATED variable is deprecated. "
"Use -W[no-]deprecated instead.\n"_s;
} else if (var == "CMAKE_ERROR_DEPRECATED") {
std::cerr << "The CMAKE_ERROR_DEPRECATED variable is deprecated. "
"Use -W[no-]error=deprecated instead.\n"_s;
}
this->AddCacheEntry(
var, value, "No help, variable specified on the command line.", type);
@@ -2441,8 +2460,6 @@ int cmake::Configure()
cmValue cachedWarnDeprecated =
this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
if (cachedWarnDeprecated) {
std::cerr << "The CMAKE_WARN_DEPRECATED variable is deprecated. "
"Use CMAKE_DIAGNOSTIC_INIT instead.\n"_s;
if (cachedWarnDeprecated.IsOn()) {
deprecated = cmDiagnostics::Warn;
} else {
@@ -2453,8 +2470,6 @@ int cmake::Configure()
cmValue cachedErrorDeprecated =
this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
if (cachedErrorDeprecated) {
std::cerr << "The CMAKE_ERROR_DEPRECATED variable is deprecated. "
"Use CMAKE_DIAGNOSTIC_INIT instead.\n"_s;
if (cachedErrorDeprecated.IsOn()) {
deprecated = cmDiagnostics::SendError;
}
@@ -2478,22 +2493,16 @@ int cmake::Configure()
cmDiagnostics::GetActionString(action)));
if (category == cmDiagnostics::CMD_DEPRECATED) {
// Set deprecated CMAKE_{WARN,ERROR}_DEPRECATED, but only in the cache,
// and only if they were already set in the cache.
if (cachedWarnDeprecated) {
std::string const value =
(action >= cmDiagnostics::Warn ? "ON" : "OFF");
this->AddCacheEntry("CMAKE_WARN_DEPRECATED", value,
"Deprecated. Use CMAKE_DIAGNOSTIC_INIT instead.",
cmStateEnums::INTERNAL);
}
if (cachedErrorDeprecated) {
std::string const value =
(action >= cmDiagnostics::SendError ? "ON" : "OFF");
this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", value,
"Deprecated. Use CMAKE_DIAGNOSTIC_INIT instead.",
cmStateEnums::INTERNAL);
}
std::string const warnValue =
(action >= cmDiagnostics::Warn ? "ON" : "OFF");
this->AddCacheEntry("CMAKE_WARN_DEPRECATED", warnValue,
"Deprecated. Use -W[no-]deprecated instead.",
cmStateEnums::INTERNAL);
std::string const errorValue =
(action >= cmDiagnostics::SendError ? "ON" : "OFF");
this->AddCacheEntry("CMAKE_ERROR_DEPRECATED", errorValue,
"Deprecated. Use -W[no-]error=deprecated instead.",
cmStateEnums::INTERNAL);
}
}
@@ -3059,6 +3068,9 @@ int cmake::Run(std::vector<std::string> const& args, bool noconfigure)
if (!sarifLogFileWriter.ConfigureForCMakeRun(*this)) {
return -1;
}
this->VariableWatch->AddWatch("CMAKE_WARN_DEPRECATED", cmDeprecatedWatch);
this->VariableWatch->AddWatch("CMAKE_ERROR_DEPRECATED", cmDeprecatedWatch);
#endif
// Log the trace format version to the desired output

View File

@@ -0,0 +1,72 @@
cmake_policy(SET CMP0218 NEW)
function(expect NAME ACTUAL EXPECTED)
if(NOT "${ACTUAL}" STREQUAL "${EXPECTED}")
message(SEND_ERROR "${NAME} is '${ACTUAL}'; should be '${EXPECTED}'")
endif()
endfunction()
if(DEFINED CMAKE_WARN_DEPRECATED)
message(SEND_ERROR "CMAKE_WARN_DEPRECATED should not be defined")
endif()
if(DEFINED CMAKE_ERROR_DEPRECATED)
message(SEND_ERROR "CMAKE_ERROR_DEPRECATED should not be defined")
endif()
cmake_diagnostic(GET CMD_DEPRECATED action)
if(NOT "${action}" STREQUAL "WARN")
message(SEND_ERROR "CMD_DEPRECATED is ${action}; should be WARN")
endif()
# -----------------------------------------------------------------------------
# Setting CMAKE_WARN_DEPRECATED should have no effect on CMD_DEPRECATED
block()
set(CMAKE_WARN_DEPRECATED OFF)
cmake_diagnostic(GET CMD_DEPRECATED action)
if(NOT "${action}" STREQUAL "WARN")
message(SEND_ERROR "CMD_DEPRECATED is ${action}; should be WARN")
endif()
endblock()
# -----------------------------------------------------------------------------
# Setting CMAKE_ERROR_DEPRECATED should have no effect on CMD_DEPRECATED
block()
set(CMAKE_ERROR_DEPRECATED ON)
cmake_diagnostic(GET CMD_DEPRECATED action)
if(NOT "${action}" STREQUAL "WARN")
message(SEND_ERROR "CMD_DEPRECATED is ${action}; should be WARN")
endif()
endblock()
# -----------------------------------------------------------------------------
# Changing CMD_DEPRECATED should have no effect on variables
block()
cmake_diagnostic(SET CMD_DEPRECATED IGNORE)
if(DEFINED CMAKE_WARN_DEPRECATED)
message(SEND_ERROR "CMAKE_WARN_DEPRECATED should not be defined")
endif()
if(DEFINED CMAKE_ERROR_DEPRECATED)
message(SEND_ERROR "CMAKE_ERROR_DEPRECATED should not be defined")
endif()
expect(CMAKE_WARN_DEPRECATED "${CMAKE_WARN_DEPRECATED}" "")
expect(CMAKE_ERROR_DEPRECATED "${CMAKE_ERROR_DEPRECATED}" "")
cmake_diagnostic(SET CMD_DEPRECATED SEND_ERROR)
if(DEFINED CMAKE_WARN_DEPRECATED)
message(SEND_ERROR "CMAKE_WARN_DEPRECATED should not be defined")
endif()
if(DEFINED CMAKE_ERROR_DEPRECATED)
message(SEND_ERROR "CMAKE_ERROR_DEPRECATED should not be defined")
endif()
expect(CMAKE_WARN_DEPRECATED "${CMAKE_WARN_DEPRECATED}" "")
expect(CMAKE_ERROR_DEPRECATED "${CMAKE_ERROR_DEPRECATED}" "")
endblock()

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,14 @@
CMake Warning \(deprecated\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0153 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
CMake Error \(deprecated\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-OLD\.cmake:[0-9]+ \(message\):
Test

View File

@@ -0,0 +1,15 @@
cmake_diagnostic(SET CMD_DEPRECATED IGNORE)
# Note: We're using the deprecation warning from cmMakefile::SetPolicy as a
# test, which requires use of policies within the deprecation window (as of
# CMake 4.4, CMP0066...CMP0155). These will likely need to be rotated to newer
# policies when that window changes.
cmake_policy(SET CMP0218 NEW)
cmake_policy(SET CMP0152 OLD) # should be silent
cmake_policy(SET CMP0218 OLD)
cmake_policy(SET CMP0153 OLD) # should NOT be silent
set(CMAKE_ERROR_DEPRECATED ON)
message(DEPRECATION "Test") # should be error

View File

@@ -0,0 +1,31 @@
CMake Warning \(author\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-WARN\.cmake:[0-9]+ \(set\):
Policy CMP0218 is not set: The CMAKE_WARN_DEPRECATED and
CMAKE_ERROR_DEPRECATED variables are ignored\. Run "cmake --help-policy
CMP0218" for policy details\. Use the cmake_policy command to set the
policy and suppress this warning\.
This warning is for project developers\. Use -Wno-author to suppress it\.
CMake Warning \(author\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-WARN\.cmake:[0-9]+ \(set\):
Policy CMP0218 is not set: The CMAKE_WARN_DEPRECATED and
CMAKE_ERROR_DEPRECATED variables are ignored\. Run "cmake --help-policy
CMP0218" for policy details\. Use the cmake_policy command to set the
policy and suppress this warning\.
This warning is for project developers\. Use -Wno-author to suppress it\.
CMake Warning \(author\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-WARN\.cmake:[0-9]+ \(set\):
Policy CMP0218 is not set: The CMAKE_WARN_DEPRECATED and
CMAKE_ERROR_DEPRECATED variables are ignored\. Run "cmake --help-policy
CMP0218" for policy details\. Use the cmake_policy command to set the
policy and suppress this warning\.
This warning is for project developers\. Use -Wno-author to suppress it\.
CMake Warning \(author\) at [^
]+/Tests/RunCMake/CMP0218/CMP0218-WARN\.cmake:[0-9]+ \(set\):
Policy CMP0218 is not set: The CMAKE_WARN_DEPRECATED and
CMAKE_ERROR_DEPRECATED variables are ignored\. Run "cmake --help-policy
CMP0218" for policy details\. Use the cmake_policy command to set the
policy and suppress this warning\.
This warning is for project developers\. Use -Wno-author to suppress it\.

View File

@@ -0,0 +1,8 @@
# Test warning when setting deprecated variables.
set(CMAKE_WARN_DEPRECATED OFF)
message(DEPRECATION "Test")
set(CMAKE_ERROR_DEPRECATED ON)
# Test warning when reading deprecated variables.
set(warn "${CMAKE_WARN_DEPRECATED}")
set(error "${CMAKE_ERROR_DEPRECATED}")

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 4.3) # Must be < 4.4 to test WARN
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1 @@
^The CMAKE_ERROR_DEPRECATED variable is deprecated\. Use -W\[no-\]error=deprecated instead\.$

View File

@@ -0,0 +1,4 @@
cmake_diagnostic(GET CMD_DEPRECATED action)
if(NOT "${action}" STREQUAL "SEND_ERROR")
message(SEND_ERROR "CMD_DEPRECATED is ${action}; should be SEND_ERROR")
endif()

View File

@@ -0,0 +1 @@
^The CMAKE_WARN_DEPRECATED variable is deprecated\. Use -W\[no-\]deprecated instead\.$

View File

@@ -0,0 +1,4 @@
cmake_diagnostic(GET CMD_DEPRECATED action)
if(NOT "${action}" STREQUAL "IGNORE")
message(SEND_ERROR "CMD_DEPRECATED is ${action}; should be IGNORE")
endif()

View File

@@ -0,0 +1,8 @@
include(RunCMake)
run_cmake_script(CMP0218-WARN)
run_cmake_script(CMP0218-OLD)
run_cmake_script(CMP0218-NEW)
run_cmake_with_options(ExpectIgnore -DCMAKE_WARN_DEPRECATED=OFF)
run_cmake_with_options(ExpectError -DCMAKE_ERROR_DEPRECATED=ON)

View File

@@ -190,6 +190,8 @@ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
add_RunCMake_test(CMP0194 -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION})
endif()
add_RunCMake_test(CMP0218)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
# generators ignore. The policy will have no effect on those generators.

View File

@@ -1,4 +1,5 @@
# Test add_compiler_export_flags without deprecation warning.
cmake_policy(SET CMP0218 NEW)
cmake_diagnostic(SET CMD_DEPRECATED IGNORE)
project(GenerateExportHeader)

View File

@@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 4.0...4.4)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)