CMP0012: Remove support for OLD behavior
This commit is contained in:
parent
3c0dbb66f5
commit
98a59ba8ad
@ -1,6 +1,9 @@
|
||||
CMP0012
|
||||
-------
|
||||
|
||||
.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
|
||||
.. include:: REMOVED_PROLOGUE.txt
|
||||
|
||||
:command:`if` recognizes numbers and boolean constants.
|
||||
|
||||
In CMake versions 2.6.4 and lower the :command:`if` command implicitly
|
||||
@ -22,7 +25,5 @@ for this policy is to recognize numbers and boolean constants without
|
||||
dereferencing variables with such names.
|
||||
|
||||
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.8.0
|
||||
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
||||
.. include:: STANDARD_ADVICE.txt
|
||||
|
||||
.. include:: DEPRECATED.txt
|
||||
.. |WARNED_OR_DID_NOT_WARN| replace:: warned
|
||||
.. include:: REMOVED_EPILOGUE.txt
|
||||
|
@ -44,7 +44,6 @@ locations other than lua/
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_policy(PUSH) # Policies apply to functions at definition-time
|
||||
cmake_policy(SET CMP0012 NEW) # For while(TRUE)
|
||||
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
|
||||
|
||||
unset(_lua_include_subdirs)
|
||||
|
@ -111,7 +111,6 @@ to know what include directories are needed.
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0012 NEW) # if() recognizes numbers and booleans
|
||||
cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
|
||||
cmake_policy(SET CMP0057 NEW) # if IN_LIST
|
||||
cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
|
||||
|
@ -215,8 +215,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageMessage.cmake)
|
||||
|
||||
|
||||
cmake_policy(PUSH)
|
||||
# numbers and boolean constants
|
||||
cmake_policy(SET CMP0012 NEW)
|
||||
# IN_LIST operator
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
|
||||
|
@ -623,8 +623,6 @@ If the library type is not specified, ``MODULE`` is assumed.
|
||||
|
||||
|
||||
cmake_policy(PUSH)
|
||||
# numbers and boolean constants
|
||||
cmake_policy (SET CMP0012 NEW)
|
||||
# foreach loop variable scope
|
||||
cmake_policy (SET CMP0124 NEW)
|
||||
|
||||
|
@ -10,8 +10,6 @@
|
||||
#
|
||||
|
||||
cmake_policy(PUSH)
|
||||
# numbers and boolean constants
|
||||
cmake_policy (SET CMP0012 NEW)
|
||||
# IN_LIST operator
|
||||
cmake_policy (SET CMP0057 NEW)
|
||||
# foreach loop variable scope
|
||||
|
@ -394,8 +394,6 @@ Deprecated Commands
|
||||
#]=======================================================================]
|
||||
|
||||
cmake_policy(PUSH)
|
||||
# numbers and boolean constants
|
||||
cmake_policy (SET CMP0012 NEW)
|
||||
# IN_LIST operator
|
||||
cmake_policy (SET CMP0057 NEW)
|
||||
# Ninja generator normalizes custom command depfile paths
|
||||
|
@ -219,7 +219,6 @@ cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
|
||||
cmListFileBacktrace bt)
|
||||
: Makefile(makefile)
|
||||
, Backtrace(std::move(bt))
|
||||
, Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012))
|
||||
, Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
|
||||
, Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057))
|
||||
, Policy64Status(makefile.GetPolicyStatus(cmPolicies::CMP0064))
|
||||
@ -292,8 +291,7 @@ bool cmConditionEvaluator::IsTrue(
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->GetBooleanValueWithAutoDereference(newArgs.front(), errorString,
|
||||
status, true);
|
||||
return this->GetBooleanValue(newArgs.front());
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
@ -402,64 +400,6 @@ bool cmConditionEvaluator::GetBooleanValue(
|
||||
return !def.IsOff();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Boolean value behavior from CMake 2.6.4 and below.
|
||||
bool cmConditionEvaluator::GetBooleanValueOld(
|
||||
cmExpandedCommandArgument const& arg, bool const one) const
|
||||
{
|
||||
if (one) {
|
||||
// Old IsTrue behavior for single argument.
|
||||
if (arg == "0") {
|
||||
return false;
|
||||
}
|
||||
if (arg == "1") {
|
||||
return true;
|
||||
}
|
||||
cmValue def = this->GetDefinitionIfUnquoted(arg);
|
||||
return !def.IsOff();
|
||||
}
|
||||
// Old GetVariableOrNumber behavior.
|
||||
cmValue def = this->GetDefinitionIfUnquoted(arg);
|
||||
if (!def && std::atoi(arg.GetValue().c_str())) {
|
||||
def = cmValue(arg.GetValue());
|
||||
}
|
||||
return !def.IsOff();
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// returns the resulting boolean value
|
||||
bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
|
||||
cmExpandedCommandArgument& newArg, std::string& errorString,
|
||||
MessageType& status, bool const oneArg) const
|
||||
{
|
||||
// Use the policy if it is set.
|
||||
if (this->Policy12Status == cmPolicies::NEW) {
|
||||
return this->GetBooleanValue(newArg);
|
||||
}
|
||||
if (this->Policy12Status == cmPolicies::OLD) {
|
||||
return this->GetBooleanValueOld(newArg, oneArg);
|
||||
}
|
||||
|
||||
// Check policy only if old and new results differ.
|
||||
const auto newResult = this->GetBooleanValue(newArg);
|
||||
const auto oldResult = this->GetBooleanValueOld(newArg, oneArg);
|
||||
if (newResult != oldResult) {
|
||||
switch (this->Policy12Status) {
|
||||
case cmPolicies::WARN:
|
||||
errorString = "An argument named \"" + newArg.GetValue() +
|
||||
"\" appears in a conditional statement. " +
|
||||
cmPolicies::GetPolicyWarning(cmPolicies::CMP0012);
|
||||
status = MessageType::AUTHOR_WARNING;
|
||||
CM_FALLTHROUGH;
|
||||
case cmPolicies::OLD:
|
||||
return oldResult;
|
||||
case cmPolicies::NEW:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return newResult;
|
||||
}
|
||||
|
||||
template <int N>
|
||||
inline int cmConditionEvaluator::matchKeysImpl(
|
||||
const cmExpandedCommandArgument&)
|
||||
@ -823,15 +763,13 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
|
||||
|
||||
//=========================================================================
|
||||
// level 3 handles NOT
|
||||
bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
|
||||
std::string& errorString,
|
||||
MessageType& status)
|
||||
bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs, std::string&,
|
||||
MessageType&)
|
||||
{
|
||||
for (auto args = newArgs.make2ArgsIterator(); args.next != newArgs.end();
|
||||
args.advance(newArgs)) {
|
||||
if (this->IsKeyword(keyNOT, *args.current)) {
|
||||
const auto rhs = this->GetBooleanValueWithAutoDereference(
|
||||
*args.next, errorString, status);
|
||||
const auto rhs = this->GetBooleanValue(*args.next);
|
||||
newArgs.ReduceOneArg(!rhs, args);
|
||||
}
|
||||
}
|
||||
@ -840,9 +778,8 @@ bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
|
||||
|
||||
//=========================================================================
|
||||
// level 4 handles AND OR
|
||||
bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
|
||||
std::string& errorString,
|
||||
MessageType& status)
|
||||
bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs, std::string&,
|
||||
MessageType&)
|
||||
{
|
||||
for (auto args = newArgs.make3ArgsIterator(); args.nextnext != newArgs.end();
|
||||
args.advance(newArgs)) {
|
||||
@ -850,10 +787,8 @@ bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
|
||||
int matchNo;
|
||||
|
||||
if ((matchNo = this->matchKeys(*args.next, keyAND, keyOR))) {
|
||||
const auto lhs = this->GetBooleanValueWithAutoDereference(
|
||||
*args.current, errorString, status);
|
||||
const auto rhs = this->GetBooleanValueWithAutoDereference(
|
||||
*args.nextnext, errorString, status);
|
||||
const auto lhs = this->GetBooleanValue(*args.current);
|
||||
const auto rhs = this->GetBooleanValue(*args.nextnext);
|
||||
// clang-format off
|
||||
const auto result =
|
||||
cmRt2CtSelector<
|
||||
|
@ -42,14 +42,6 @@ private:
|
||||
|
||||
bool GetBooleanValue(cmExpandedCommandArgument& arg) const;
|
||||
|
||||
bool GetBooleanValueOld(cmExpandedCommandArgument const& arg,
|
||||
bool one) const;
|
||||
|
||||
bool GetBooleanValueWithAutoDereference(cmExpandedCommandArgument& newArg,
|
||||
std::string& errorString,
|
||||
MessageType& status,
|
||||
bool oneArg = false) const;
|
||||
|
||||
template <int N>
|
||||
int matchKeysImpl(const cmExpandedCommandArgument&);
|
||||
|
||||
@ -75,7 +67,6 @@ private:
|
||||
|
||||
cmMakefile& Makefile;
|
||||
cmListFileBacktrace Backtrace;
|
||||
cmPolicies::PolicyStatus Policy12Status;
|
||||
cmPolicies::PolicyStatus Policy54Status;
|
||||
cmPolicies::PolicyStatus Policy57Status;
|
||||
cmPolicies::PolicyStatus Policy64Status;
|
||||
|
@ -49,7 +49,7 @@ class cmMakefile;
|
||||
"Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \
|
||||
NEW) \
|
||||
SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \
|
||||
2, 8, 0, WARN) \
|
||||
2, 8, 0, NEW) \
|
||||
SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \
|
||||
8, 0, WARN) \
|
||||
SELECT(POLICY, CMP0014, "Input directories must have CMakeLists.txt.", 2, \
|
||||
|
@ -40,60 +40,6 @@ macro(test_vars _old)
|
||||
endmacro()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Test the OLD behavior of CMP0012.
|
||||
cmake_policy(SET CMP0012 OLD)
|
||||
|
||||
# False constants not recognized (still false).
|
||||
foreach(_false "" ${FALSE_NAMES})
|
||||
if("${_false}")
|
||||
message(FATAL_ERROR "OLD if(${_false}) is true!")
|
||||
else()
|
||||
message(STATUS "OLD if(${_false}) is false")
|
||||
endif()
|
||||
|
||||
if(NOT "${_false}")
|
||||
message(STATUS "OLD if(NOT ${_false}) is true")
|
||||
else()
|
||||
message(FATAL_ERROR "OLD if(NOT ${_false}) is false!")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# True constants not recognized.
|
||||
foreach(_false ${TRUE_NAMES})
|
||||
if(${_false})
|
||||
message(FATAL_ERROR "OLD if(${_false}) is true!")
|
||||
else()
|
||||
message(STATUS "OLD if(${_false}) is false")
|
||||
endif()
|
||||
|
||||
if(NOT ${_false})
|
||||
message(STATUS "OLD if(NOT ${_false}) is true")
|
||||
else()
|
||||
message(FATAL_ERROR "OLD if(NOT ${_false}) is false!")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Numbers not recognized properly.
|
||||
foreach(_num 2 -2 2.0 -2.0 2x -2x)
|
||||
if(${_num})
|
||||
message(FATAL_ERROR "OLD if(${_num}) is true!")
|
||||
else()
|
||||
message(STATUS "OLD if(${_num}) is false")
|
||||
endif()
|
||||
|
||||
if(NOT ${_num})
|
||||
message(FATAL_ERROR "OLD if(NOT ${_num}) is true!")
|
||||
else()
|
||||
message(STATUS "OLD if(NOT ${_num}) is false")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
test_vars("OLD ")
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Test the NEW behavior of CMP0012.
|
||||
cmake_policy(SET CMP0012 NEW)
|
||||
|
||||
# Test false constants.
|
||||
foreach(_false "" 0 ${FALSE_NAMES})
|
||||
|
Loading…
Reference in New Issue
Block a user