Diagnostics: Handle CMAKE_{WARN,ERROR}_DEPRECATED

Update documentation for aforementioned variables, as their use is
deprecated under the new diagnostic system. Introduce a policy which
reintroduces their use to control specific deprecation diagnostics if
the policy is not NEW.

Note that this means there is NO synchronization between the variables
and the new diagnostic state.
This commit is contained in:
Matthew Woehlke
2026-05-06 13:06:18 -04:00
parent be057c5a01
commit 72e7305c3e
26 changed files with 363 additions and 38 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

@@ -55,6 +55,7 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStringAlgorithms.h"
@@ -174,6 +175,17 @@ void cmWarnUnusedCliWarning(std::string const& variable,
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)
@@ -830,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);
@@ -2439,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 {
@@ -2451,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;
}
@@ -2476,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);
}
}
@@ -3057,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)