From 98a59ba8ad842e95af9963f57e671337defd177c Mon Sep 17 00:00:00 2001 From: Brad King Date: Sun, 17 Nov 2024 10:12:00 -0500 Subject: CMP0012: Remove support for OLD behavior --- Help/policy/CMP0012.rst | 9 ++-- Modules/FindLua.cmake | 1 - Modules/FindOpenMP.cmake | 1 - Modules/FindPackageHandleStandardArgs.cmake | 2 - Modules/FindPython.cmake | 2 - Modules/FindPython/Support.cmake | 2 - Modules/UseSWIG.cmake | 2 - Source/cmConditionEvaluator.cxx | 81 +++-------------------------- Source/cmConditionEvaluator.h | 9 ---- Source/cmPolicies.h | 2 +- Tests/CMakeTests/IfTest.cmake.in | 54 ------------------- 11 files changed, 14 insertions(+), 151 deletions(-) diff --git a/Help/policy/CMP0012.rst b/Help/policy/CMP0012.rst index dd889d2..24cc20b 100644 --- a/Help/policy/CMP0012.rst +++ b/Help/policy/CMP0012.rst @@ -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 diff --git a/Modules/FindLua.cmake b/Modules/FindLua.cmake index b4106c4..0461cbb 100644 --- a/Modules/FindLua.cmake +++ b/Modules/FindLua.cmake @@ -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_ unset(_lua_include_subdirs) diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 674b161..3c6149f 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -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_ diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index 3360cb2..0b7325d 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -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) diff --git a/Modules/FindPython.cmake b/Modules/FindPython.cmake index d2a1457..4a1b061 100644 --- a/Modules/FindPython.cmake +++ b/Modules/FindPython.cmake @@ -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) diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake index 9cc8703..c647315 100644 --- a/Modules/FindPython/Support.cmake +++ b/Modules/FindPython/Support.cmake @@ -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 diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index bc4de91..d6510f3 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -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 diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index e5b079b..5603fb0 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -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 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< diff --git a/Source/cmConditionEvaluator.h b/Source/cmConditionEvaluator.h index 4f42206..796f38c 100644 --- a/Source/cmConditionEvaluator.h +++ b/Source/cmConditionEvaluator.h @@ -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 matchKeysImpl(const cmExpandedCommandArgument&); @@ -75,7 +67,6 @@ private: cmMakefile& Makefile; cmListFileBacktrace Backtrace; - cmPolicies::PolicyStatus Policy12Status; cmPolicies::PolicyStatus Policy54Status; cmPolicies::PolicyStatus Policy57Status; cmPolicies::PolicyStatus Policy64Status; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 95ee434..d8e30cc 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -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, \ diff --git a/Tests/CMakeTests/IfTest.cmake.in b/Tests/CMakeTests/IfTest.cmake.in index e5211b4..e783d8d 100644 --- a/Tests/CMakeTests/IfTest.cmake.in +++ b/Tests/CMakeTests/IfTest.cmake.in @@ -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}) -- cgit v0.12 < WR>Е ӘY\H0:ȋkeg\r[5"09\zo.)ce`uBJ:oR= j^B~wH3mwہxuJޠ+݇$%lI8:6s Kx>۴#|]+9RvMuHU78h)' ,Y;4+قXt%KD\7YvQBI>\S dz_?L{R韑HP"e|̭RVe!e鼊:WW,ёx>ڈ\\Hnk[Z=}A,^4z`׳t]~k]/ -]>v':<?U~ߧh/^|1m֯ 8ZwQy{f t|zc*P{Ew{!”F/5:WrYԹEUmt?CfcɔW< D e6͟"%E'W*wգ5kMTGXטN+e.iё<Ǣ&5%k*,[hf|!.+8c] F#&ĝ0tO'\;LSZ/p{zƄmHru [W7GHϩ/޵ckac„My<;|aFd_:`A"!$y)NzL}?\pl ;(<\閶j1SyhG2=[NQۤɖ(`panUEUNFBTID4W0 6K]Y`a.J0Y$=ʟQ@׼ ֘c=by>ӱe֫iB9f+wivipuCs@L?Wuy>/]Tڕ 4x+ $ՌWT}%!y6ǃlf|\Tgw\v,EWqWJ?zxN󢛗n1??Ƨ@qrɲ[e:.nqin{IDb|k"m^bߕmAW!_!׸âL%1iq &6>htgr56tTQD)lp ,\Ў<7,@IM:J.P#8/@Yb̮q;,pVzJSr6z-9r>/i g!ʕ$5sbc}&֙FrPI[ $0.!i:'! 0]gJ,qS ( OLT*?9W8d \}K}1@X3`\L}hY HDOV{ӫE}jRtfҨM]:'UJ3QNQcA` (Y)$?ɰ(F\,<0xխ!-ƔȬB8H!4v(SND\XAܗ`"E5K":W<>7?h-Rӣd5MzҰ*ѠX^+Xis\a $%O.cYL4bH@TR\3aD |S5-mϹIn{r%Vti1YH 'a"3I[Qg!L's5p'&I6g7 ~H4nfbJ,Q]ik%>^f͵\\)' uLrCY 5qHV4n3of+}".̥8wy@hX,dلdJ= __y2؎&izETuu"37&dt{2̴`|U,F\{`x3-:ѕKu:bFh+K.ؕ$Kso.Y14^>&4n>}PXBkv5'">ۡ#S"v;eJhLn@:eD/xY?;:+o(752AGB~`