[Cmake-commits] CMake branch, next, updated. v3.0.1-5176-g32480ab

Nils Gladitz nilsgladitz at gmail.com
Fri Sep 5 17:54:59 EDT 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  32480abdc3be86fedbfd3c5eff3994e9631c2e71 (commit)
       via  30db90019bd6689ba0d774dbc346dd454445b32a (commit)
      from  54e59c854510fc67e77f6f82483f755531d348a3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=32480abdc3be86fedbfd3c5eff3994e9631c2e71
commit 32480abdc3be86fedbfd3c5eff3994e9631c2e71
Merge: 54e59c8 30db900
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Sep 5 17:54:58 2014 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Fri Sep 5 17:54:58 2014 -0400

    Merge topic 'if-sanity' into next
    
    30db9001 If: Incorporate CMP0054 suggestions


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=30db90019bd6689ba0d774dbc346dd454445b32a
commit 30db90019bd6689ba0d774dbc346dd454445b32a
Author:     Nils Gladitz <nilsgladitz at gmail.com>
AuthorDate: Fri Sep 5 19:18:36 2014 +0200
Commit:     Nils Gladitz <nilsgladitz at gmail.com>
CommitDate: Fri Sep 5 23:51:46 2014 +0200

    If: Incorporate CMP0054 suggestions

diff --git a/Help/command/if.rst b/Help/command/if.rst
index 3e4178d..541b995 100644
--- a/Help/command/if.rst
+++ b/Help/command/if.rst
@@ -200,6 +200,7 @@ above-documented signature accepts ``<variable|string>``:
   tested to see if they are boolean constants, if so they are used as
   such, otherwise they are assumed to be variables and are dereferenced.
 
-To prevent ambiguity potential variables names can be quoted.
-A quoted variable name will be interpreted as a string and not dereferenced.
+To prevent ambiguity, potential variable or keyword names can be
+quoted or bracketed.  A quoted or bracketed variable or keyword will be
+interpreted as a string and not dereferenced or interpreted.
 See CMake Policy :policy:`CMP0054`.
diff --git a/Help/policy/CMP0054.rst b/Help/policy/CMP0054.rst
index bf0e95f..778eb83 100644
--- a/Help/policy/CMP0054.rst
+++ b/Help/policy/CMP0054.rst
@@ -1,14 +1,16 @@
 CMP0054
 -------
 
-Don't dereference quoted variables in if() arguments.
+Only interpret if() arguments as variables or keywords when unquoted.
 
-CMake 3.1 no longer dereferences variables in if() arguments when
-they are quoted.
+CMake 3.1 no longer dereferences variables or interprets keywords in if()
+arguments when they are quoted :ref:`Quoted Argument` or
+bracketed :ref:`Bracket Argument`.
 
-The ``OLD`` behavior for this policy is to dereference variables even
-if they are quoted.  The ``NEW`` behavior is to omit dereferencing
-of variables that are quoted.
+The ``OLD`` behavior for this policy is to dereference variables and
+interpret keywords even if they are quoted or bracketed.
+The ``NEW`` behavior is to not dereference variables or interpret keywords
+that have been quoted or bracketed.
 
 This policy was introduced in CMake version 3.1.
 CMake version |release| warns when the policy is not set and uses
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 8c92a6a..3cb463e 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -228,6 +228,47 @@ namespace
   typedef std::list<cmExpandedCommandArgument> cmArgumentList;
 
   //=========================================================================
+  bool IsKeyword(std::string const& keyword,
+    cmExpandedCommandArgument& argument,
+    cmMakefile* mf)
+  {
+    bool isKeyword = argument.GetValue() == keyword;
+
+    if(isKeyword && argument.WasQuoted())
+      {
+      cmOStringStream e;
+      switch(mf->GetPolicyStatus(cmPolicies::CMP0054))
+        {
+        case cmPolicies::WARN:
+          {
+          bool hasBeenReported = mf->HasCMP0054AlreadyBeenReported(
+            mf->GetBacktrace()[0], argument.GetValue());
+
+          if(!hasBeenReported)
+            {
+            e << (mf->GetPolicies()->GetPolicyWarning(
+              cmPolicies::CMP0054)) << "\n";
+            e << "Quoted keywords like '" << argument.GetValue() <<
+              "' are no longer interpreted as keywords.";
+
+            mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+            }
+          }
+          break;
+        case cmPolicies::OLD:
+          break;
+        case cmPolicies::REQUIRED_ALWAYS:
+        case cmPolicies::REQUIRED_IF_USED:
+        case cmPolicies::NEW:
+          isKeyword = false;
+          break;
+        }
+      }
+
+    return isKeyword;
+  }
+
+  //=========================================================================
   bool GetBooleanValue(cmExpandedCommandArgument& arg, cmMakefile* mf)
   {
   // Check basic constants.
@@ -425,7 +466,7 @@ namespace
     cmArgumentList::iterator arg = newArgs.begin();
     while (arg != newArgs.end())
       {
-      if (*arg == "(")
+      if (IsKeyword("(", *arg, makefile))
         {
         // search for the closing paren for this opening one
         cmArgumentList::iterator argClose;
@@ -434,11 +475,11 @@ namespace
         unsigned int depth = 1;
         while (argClose != newArgs.end() && depth)
           {
-          if (*argClose == "(")
+          if (IsKeyword("(", *argClose, makefile))
             {
               depth++;
             }
-          if (*argClose == ")")
+          if (IsKeyword(")", *argClose, makefile))
             {
               depth--;
             }
@@ -503,42 +544,42 @@ namespace
       argP1 = arg;
       IncrementArguments(newArgs,argP1,argP2);
       // does a file exist
-      if (*arg == "EXISTS" && argP1  != newArgs.end())
+      if (IsKeyword("EXISTS", *arg, makefile) && argP1  != newArgs.end())
         {
         HandlePredicate(
           cmSystemTools::FileExists(argP1->c_str()),
           reducible, arg, newArgs, argP1, argP2);
         }
       // does a directory with this name exist
-      if (*arg == "IS_DIRECTORY" && argP1  != newArgs.end())
+      if (IsKeyword("IS_DIRECTORY", *arg, makefile) && argP1  != newArgs.end())
         {
         HandlePredicate(
           cmSystemTools::FileIsDirectory(argP1->c_str()),
           reducible, arg, newArgs, argP1, argP2);
         }
       // does a symlink with this name exist
-      if (*arg == "IS_SYMLINK" && argP1  != newArgs.end())
+      if (IsKeyword("IS_SYMLINK", *arg, makefile) && argP1  != newArgs.end())
         {
         HandlePredicate(
           cmSystemTools::FileIsSymlink(argP1->c_str()),
           reducible, arg, newArgs, argP1, argP2);
         }
       // is the given path an absolute path ?
-      if (*arg == "IS_ABSOLUTE" && argP1  != newArgs.end())
+      if (IsKeyword("IS_ABSOLUTE", *arg, makefile) && argP1  != newArgs.end())
         {
         HandlePredicate(
           cmSystemTools::FileIsFullPath(argP1->c_str()),
           reducible, arg, newArgs, argP1, argP2);
         }
       // does a command exist
-      if (*arg == "COMMAND" && argP1  != newArgs.end())
+      if (IsKeyword("COMMAND", *arg, makefile) && argP1  != newArgs.end())
         {
         HandlePredicate(
           makefile->CommandExists(argP1->c_str()),
           reducible, arg, newArgs, argP1, argP2);
         }
       // does a policy exist
-      if (*arg == "POLICY" && argP1 != newArgs.end())
+      if (IsKeyword("POLICY", *arg, makefile) && argP1 != newArgs.end())
         {
         cmPolicies::PolicyID pid;
         HandlePredicate(
@@ -547,14 +588,14 @@ namespace
             reducible, arg, newArgs, argP1, argP2);
         }
       // does a target exist
-      if (*arg == "TARGET" && argP1 != newArgs.end())
+      if (IsKeyword("TARGET", *arg, makefile) && argP1 != newArgs.end())
         {
         HandlePredicate(
           makefile->FindTargetToUse(argP1->GetValue())?true:false,
           reducible, arg, newArgs, argP1, argP2);
         }
       // is a variable defined
-      if (*arg == "DEFINED" && argP1  != newArgs.end())
+      if (IsKeyword("DEFINED", *arg, makefile) && argP1  != newArgs.end())
         {
         size_t argP1len = argP1->GetValue().size();
         bool bdef = false;
@@ -598,7 +639,7 @@ namespace
       argP1 = arg;
       IncrementArguments(newArgs,argP1,argP2);
       if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
-        *(argP1) == "MATCHES")
+        IsKeyword("MATCHES", *argP1, makefile))
         {
         def = cmIfCommand::GetVariableOrString(*arg, makefile);
         const char* rex = argP2->c_str();
@@ -628,7 +669,7 @@ namespace
         reducible = 1;
         }
 
-      if (argP1 != newArgs.end() && *arg == "MATCHES")
+      if (argP1 != newArgs.end() && IsKeyword("MATCHES", *arg, makefile))
         {
         *arg = cmExpandedCommandArgument("0", true);
         newArgs.erase(argP1);
@@ -638,8 +679,9 @@ namespace
         }
 
       if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
-        (*(argP1) == "LESS" || *(argP1) == "GREATER" ||
-         *(argP1) == "EQUAL"))
+        (IsKeyword("LESS", *argP1, makefile) ||
+         IsKeyword("GREATER", *argP1, makefile) ||
+         IsKeyword("EQUAL", *argP1, makefile)))
         {
         def = cmIfCommand::GetVariableOrString(*arg, makefile);
         def2 = cmIfCommand::GetVariableOrString(*argP2, makefile);
@@ -668,9 +710,9 @@ namespace
         }
 
       if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
-        (*(argP1) == "STRLESS" ||
-         *(argP1) == "STREQUAL" ||
-         *(argP1) == "STRGREATER"))
+        (IsKeyword("STRLESS", *argP1, makefile) ||
+         IsKeyword("STREQUAL", *argP1, makefile) ||
+         IsKeyword("STRGREATER", *argP1, makefile)))
         {
         def = cmIfCommand::GetVariableOrString(*arg, makefile);
         def2 = cmIfCommand::GetVariableOrString(*argP2, makefile);
@@ -693,8 +735,9 @@ namespace
         }
 
       if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
-        (*(argP1) == "VERSION_LESS" || *(argP1) == "VERSION_GREATER" ||
-         *(argP1) == "VERSION_EQUAL"))
+        (IsKeyword("VERSION_LESS", *argP1, makefile) ||
+         IsKeyword("VERSION_GREATER", *argP1, makefile) ||
+         IsKeyword("VERSION_EQUAL", *argP1, makefile)))
         {
         def = cmIfCommand::GetVariableOrString(*arg, makefile);
         def2 = cmIfCommand::GetVariableOrString(*argP2, makefile);
@@ -714,7 +757,7 @@ namespace
 
       // is file A newer than file B
       if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
-          *(argP1) == "IS_NEWER_THAN")
+          IsKeyword("IS_NEWER_THAN", *argP1, makefile))
         {
         int fileIsNewer=0;
         bool success=cmSystemTools::FileTimeCompare(arg->GetValue(),
@@ -751,7 +794,7 @@ namespace
       {
       argP1 = arg;
       IncrementArguments(newArgs,argP1,argP2);
-      if (argP1 != newArgs.end() && *arg == "NOT")
+      if (argP1 != newArgs.end() && IsKeyword("NOT", *arg, makefile))
         {
         bool rhs = GetBooleanValueWithAutoDereference(*argP1,
                                                       makefile,
@@ -788,7 +831,7 @@ namespace
       {
       argP1 = arg;
       IncrementArguments(newArgs,argP1,argP2);
-      if (argP1 != newArgs.end() && *(argP1) == "AND" &&
+      if (argP1 != newArgs.end() && IsKeyword("AND", *argP1, makefile) &&
         argP2 != newArgs.end())
         {
         lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
@@ -803,7 +846,7 @@ namespace
           reducible, arg, newArgs, argP1, argP2);
         }
 
-      if (argP1 != newArgs.end() && *(argP1) == "OR" &&
+      if (argP1 != newArgs.end() && IsKeyword("OR", *argP1, makefile) &&
         argP2 != newArgs.end())
         {
         lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
@@ -927,12 +970,20 @@ const char* cmIfCommand::GetDefinitionIfUnquoted(
     switch(mf->GetPolicyStatus(cmPolicies::CMP0054))
       {
       case cmPolicies::WARN:
-        e << (mf->GetPolicies()->GetPolicyWarning(
-          cmPolicies::CMP0054)) << "\n";
-        e << "Quoted variables like '" << argument.GetValue() <<
-          "' are no longer dereferenced.";
+        {
+        bool hasBeenReported = mf->HasCMP0054AlreadyBeenReported(
+          mf->GetBacktrace()[0], argument.GetValue());
+
+        if(!hasBeenReported)
+          {
+          e << (mf->GetPolicies()->GetPolicyWarning(
+            cmPolicies::CMP0054)) << "\n";
+          e << "Quoted variables like '" << argument.GetValue() <<
+            "' are no longer dereferenced.";
 
-        mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+          mf->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+          }
+        }
         break;
       case cmPolicies::OLD:
         break;
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 7c89507..4b42946 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4980,12 +4980,14 @@ void cmMakefile::PopPolicyBarrier(bool reportError)
   this->PolicyBarriers.pop_back();
 }
 
+//----------------------------------------------------------------------------
 bool cmMakefile::SetPolicyVersion(const char *version)
 {
   return this->GetCMakeInstance()->GetPolicies()->
     ApplyPolicyVersion(this,version);
 }
 
+//----------------------------------------------------------------------------
 cmPolicies *cmMakefile::GetPolicies() const
 {
   if (!this->GetCMakeInstance())
@@ -4996,6 +4998,23 @@ cmPolicies *cmMakefile::GetPolicies() const
 }
 
 //----------------------------------------------------------------------------
+bool cmMakefile::HasCMP0054AlreadyBeenReported(
+  cmListFileContext context, std::string name) const
+{
+  cmCMP0054Id id(context, name);
+
+  bool alreadyReported =
+    this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end();
+
+  if(!alreadyReported)
+    {
+    this->CMP0054ReportedIds.insert(id);
+    }
+
+  return alreadyReported;
+}
+
+//----------------------------------------------------------------------------
 void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm)
 {
   /* Record the setting of every policy.  */
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index d4df717..a304450 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -376,7 +376,40 @@ public:
   /**
     * Get the Policies Instance
     */
- cmPolicies *GetPolicies() const;
+  cmPolicies *GetPolicies() const;
+
+  struct cmCMP0054Id
+  {
+    cmCMP0054Id(cmListFileContext const& context, std::string const& name):
+        Context(context),
+        Name(name)
+    {
+
+    }
+
+    bool operator< (cmCMP0054Id const& id) const
+    {
+      if(this->Context.FilePath != id.Context.FilePath)
+        return this->Context.FilePath < id.Context.FilePath;
+
+      if(this->Context.Line != id.Context.Line)
+        return this->Context.Line < id.Context.Line;
+
+      return this->Name < id.Name;
+    }
+
+    cmListFileContext Context;
+    std::string Name;
+  };
+
+  mutable std::set<cmCMP0054Id> CMP0054ReportedIds;
+
+  /**
+   * Determine if the given context, name pair has already been reported
+   * in context of CMP0054.
+   */
+  bool HasCMP0054AlreadyBeenReported(
+    cmListFileContext context, std::string name) const;
 
   /**
    * Add an auxiliary directory to the build.
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 1b3daf1..a420f59 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -362,7 +362,7 @@ cmPolicies::cmPolicies()
 
   this->DefinePolicy(
     CMP0054, "CMP0054",
-    "Don't dereference quoted variables in if() arguments.",
+    "Only interpret if() arguments as variables or keywords when unquoted.",
     3,1,0, cmPolicies::WARN);
 }
 
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 9fefe59..7c73da8 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -109,7 +109,8 @@ public:
     /// INTERFACE_INCLUDE_DIRECTORIES
 
     CMP0053, ///< Simplify variable reference and escape sequence evaluation
-    CMP0054, ///< Don't dereference quoted variables in if() arguments
+    CMP0054, ///< Only interpret if() arguments as variables
+    /// or keywords when unquoted.
 
     /** \brief Always the last entry.
      *
diff --git a/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake b/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake
index d4f8de0..23a9124 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake
+++ b/Tests/RunCMake/CMP0054/CMP0054-NEW.cmake
@@ -1,21 +1,47 @@
 cmake_policy(SET CMP0054 NEW)
 
 set(FOO "BAR")
+set(BAZ "ZZZ")
+set(MYTRUE ON)
+set(MYNUMBER 3)
+set(MYVERSION 3.0)
 
-if("FOO" STREQUAL "BAR")
-  message(FATAL_ERROR "The given literals should not match")
-endif()
+function(assert_unquoted PREFIX FIRST)
+  string(REPLACE ";" " " ARGN_SP "${ARGN}")
+  if(${PREFIX} ${FIRST} ${ARGN})
+    message(FATAL_ERROR "Assertion failed [${PREFIX} ${FIRST} ${ARGN_SP}]")
+  endif()
+endfunction()
 
-if(NOT FOO STREQUAL "BAR")
-  message(FATAL_ERROR "The given variable should match the literal")
-endif()
+function(assert_quoted PREFIX FIRST)
+  string(REPLACE ";" " " ARGN_SP "${ARGN}")
+  if(${PREFIX} "${FIRST}" ${ARGN})
+    message(FATAL_ERROR "Assertion failed [${PREFIX} \"${FIRST}\" ${ARGN_SP}]")
+  endif()
+endfunction()
 
-set(MYTRUE ON)
+function(assert FIRST)
+  assert_unquoted(NOT ${FIRST} ${ARGN})
+  assert_quoted("" ${FIRST} ${ARGN})
+endfunction()
+
+assert(MYTRUE)
+
+assert(FOO MATCHES "^BAR$")
+
+assert(MYNUMBER LESS 4)
+assert(MYNUMBER GREATER 2)
+assert(MYNUMBER EQUAL 3)
+
+assert(FOO STRLESS CCC)
+assert(BAZ STRGREATER CCC)
+assert(FOO STREQUAL BAR)
+
+assert_unquoted(NOT MYVERSION VERSION_LESS 3.1)
+assert_unquoted("" MYVERSION VERSION_LESS 2.9)
 
-if(NOT MYTRUE)
-  message(FATAL_ERROR "Expected MYTRUE to evaluate true")
-endif()
+assert_quoted(NOT MYVERSION VERSION_LESS 2.9)
+assert_quoted(NOT MYVERSION VERSION_LESS 3.1)
 
-if("MYTRUE")
-  message(FATAL_ERROR "Expected quoted MYTRUE to evaluate false")
-endif()
+assert(MYVERSION VERSION_GREATER 2.9)
+assert(MYVERSION VERSION_EQUAL 3.0)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake b/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake
index 3730af4..0c4cede 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake
+++ b/Tests/RunCMake/CMP0054/CMP0054-OLD.cmake
@@ -1,21 +1,47 @@
 cmake_policy(SET CMP0054 OLD)
 
 set(FOO "BAR")
+set(BAZ "ZZZ")
+set(MYTRUE ON)
+set(MYNUMBER 3)
+set(MYVERSION 3.0)
 
-if(NOT "FOO" STREQUAL "BAR")
-  message(FATAL_ERROR "The given literals should match")
-endif()
+function(assert_unquoted PREFIX FIRST)
+  string(REPLACE ";" " " ARGN_SP "${ARGN}")
+  if(${PREFIX} ${FIRST} ${ARGN})
+    message(FATAL_ERROR "Assertion failed [${PREFIX} ${FIRST} ${ARGN_SP}]")
+  endif()
+endfunction()
 
-if(NOT FOO STREQUAL "BAR")
-  message(FATAL_ERROR "The given literals should match")
-endif()
+function(assert_quoted PREFIX FIRST)
+  string(REPLACE ";" " " ARGN_SP "${ARGN}")
+  if(${PREFIX} "${FIRST}" ${ARGN})
+    message(FATAL_ERROR "Assertion failed [${PREFIX} \"${FIRST}\" ${ARGN_SP}]")
+  endif()
+endfunction()
 
-set(MYTRUE ON)
+function(assert FIRST)
+  assert_unquoted(NOT ${FIRST} ${ARGN})
+  assert_quoted(NOT ${FIRST} ${ARGN})
+endfunction()
+
+assert(MYTRUE)
+
+assert(FOO MATCHES "^BAR$")
+
+assert(MYNUMBER LESS 4)
+assert(MYNUMBER GREATER 2)
+assert(MYNUMBER EQUAL 3)
+
+assert(FOO STRLESS CCC)
+assert(BAZ STRGREATER CCC)
+assert(FOO STREQUAL BAR)
+
+assert_unquoted(NOT MYVERSION VERSION_LESS 3.1)
+assert_unquoted("" MYVERSION VERSION_LESS 2.9)
 
-if(NOT MYTRUE)
-  message(FATAL_ERROR "Expected MYTRUE to evaluate true")
-endif()
+assert_quoted("" MYVERSION VERSION_LESS 2.9)
+assert_quoted(NOT MYVERSION VERSION_LESS 3.1)
 
-if(NOT "MYTRUE")
-  message(FATAL_ERROR "Expected quoted MYTRUE to evaluate true as well")
-endif()
+assert(MYVERSION VERSION_GREATER 2.9)
+assert(MYVERSION VERSION_EQUAL 3.0)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt
index d256463..d076cab 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt
@@ -1,7 +1,8 @@
 CMake Warning \(dev\) at CMP0054-WARN.cmake:3 \(if\):
-  Policy CMP0054 is not set: Don't dereference quoted variables in if\(\)
-  arguments.  Run "cmake --help-policy CMP0054" for policy details.  Use the
-  cmake_policy command to set the policy and suppress this warning.
+  Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
+  details.  Use the cmake_policy command to set the policy and suppress this
+  warning.
 
   Quoted variables like 'FOO' are no longer dereferenced.
 Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt
new file mode 100644
index 0000000..1e33cf9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt
@@ -0,0 +1,22 @@
+CMake Warning \(dev\) at CMP0054-duplicate-warnings.cmake:4 \(if\):
+  Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
+  details.  Use the cmake_policy command to set the policy and suppress this
+  warning.
+
+  Quoted variables like 'FOO' are no longer dereferenced.
+Call Stack \(most recent call first\):
+  CMP0054-duplicate-warnings.cmake:8 \(generate_warning\)
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\) at CMP0054-duplicate-warnings.cmake:11 \(if\):
+  Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
+  details.  Use the cmake_policy command to set the policy and suppress this
+  warning.
+
+  Quoted variables like 'FOO' are no longer dereferenced.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake
new file mode 100644
index 0000000..04fbe14
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake
@@ -0,0 +1,12 @@
+set(FOO "BAR")
+
+function(generate_warning)
+  if("FOO" STREQUAL "BAR")
+  endif()
+endfunction()
+
+generate_warning()
+generate_warning()
+
+if("FOO" STREQUAL "BAR")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt
new file mode 100644
index 0000000..429803e
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt
@@ -0,0 +1,8 @@
+CMake Error at CMP0054-keywords-NEW.cmake:21 \(if\):
+  if given arguments:
+
+    "NOT" "1"
+
+  Unknown arguments specified
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake
new file mode 100644
index 0000000..b60ece9
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake
@@ -0,0 +1,23 @@
+cmake_policy(SET CMP0054 NEW)
+
+function(assert KEYWORD)
+  if("${KEYWORD}" STREQUAL "${KEYWORD}")
+  else()
+    message(FATAL_ERROR
+      "Assertion failed [\"${KEYWORD}\" STREQUAL \"${KEYWORD}\"]")
+  endif()
+endfunction()
+
+assert("NOT")
+assert("COMMAND")
+assert("POLICY")
+assert("TARGET")
+assert("EXISTS")
+assert("IS_DIRECTORY")
+assert("IS_SYMLINK")
+assert("IS_ABSOLUTE")
+assert("DEFINED")
+
+if("NOT" 1)
+  message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
new file mode 100644
index 0000000..f5a8fbe
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake
new file mode 100644
index 0000000..a2a7f51
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake
@@ -0,0 +1,9 @@
+cmake_policy(SET CMP0054 OLD)
+
+if(NOT 1)
+  message(FATAL_ERROR "[NOT 1] evaluated true")
+endif()
+
+if("NOT" 1)
+  message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt
new file mode 100644
index 0000000..5952f87
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at CMP0054-keywords-WARN.cmake:1 \(if\):
+  Policy CMP0054 is not set: Only interpret if\(\) arguments as variables or
+  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
+  details.  Use the cmake_policy command to set the policy and suppress this
+  warning.
+
+  Quoted keywords like 'NOT' are no longer interpreted as keywords.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake
new file mode 100644
index 0000000..ee0a623
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake
@@ -0,0 +1,3 @@
+if("NOT" 1)
+  message(FATAL_ERROR "[\"NOT\" 1] evaluated true")
+endif()
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
new file mode 100644
index 0000000..f5a8fbe
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
@@ -0,0 +1 @@
+$^
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake
new file mode 100644
index 0000000..b6b243c
--- /dev/null
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake
@@ -0,0 +1,53 @@
+set(FOO BAR)
+
+cmake_policy(SET CMP0054 NEW)
+
+function(function_defined_new_called_old)
+  if(NOT FOO STREQUAL BAR)
+    message(FATAL_ERROR "The variable should match the string")
+  endif()
+
+  if("FOO" STREQUAL BAR)
+    message(FATAL_ERROR "The strings should not match")
+  endif()
+endfunction()
+
+macro(macro_defined_new_called_old)
+  if(NOT FOO STREQUAL BAR)
+    message(FATAL_ERROR "The variable should match the string")
+  endif()
+
+  if("FOO" STREQUAL BAR)
+    message(FATAL_ERROR "The strings should not match")
+  endif()
+endmacro()
+
+cmake_policy(SET CMP0054 OLD)
+
+function_defined_new_called_old()
+macro_defined_new_called_old()
+
+function(function_defined_old_called_new)
+  if(NOT FOO STREQUAL BAR)
+    message(FATAL_ERROR "The variable should match the string")
+  endif()
+
+  if(NOT "FOO" STREQUAL BAR)
+    message(FATAL_ERROR "The quoted variable should match the string")
+  endif()
+endfunction()
+
+macro(macro_defined_old_called_new)
+  if(NOT FOO STREQUAL BAR)
+    message(FATAL_ERROR "The variable should match the string")
+  endif()
+
+  if(NOT "FOO" STREQUAL BAR)
+    message(FATAL_ERROR "The quoted variable should match the string")
+  endif()
+endmacro()
+
+cmake_policy(SET CMP0054 NEW)
+
+function_defined_old_called_new()
+macro_defined_old_called_new()
diff --git a/Tests/RunCMake/CMP0054/RunCMakeTest.cmake b/Tests/RunCMake/CMP0054/RunCMakeTest.cmake
index 4cc7649..8df382f 100644
--- a/Tests/RunCMake/CMP0054/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMP0054/RunCMakeTest.cmake
@@ -3,3 +3,8 @@ include(RunCMake)
 run_cmake(CMP0054-OLD)
 run_cmake(CMP0054-NEW)
 run_cmake(CMP0054-WARN)
+run_cmake(CMP0054-keywords-NEW)
+run_cmake(CMP0054-keywords-OLD)
+run_cmake(CMP0054-keywords-WARN)
+run_cmake(CMP0054-duplicate-warnings)
+run_cmake(CMP0054-policy-command-scope)

-----------------------------------------------------------------------

Summary of changes:
 Help/command/if.rst                                |    5 +-
 Help/policy/CMP0054.rst                            |   14 +--
 Source/cmIfCommand.cxx                             |  109 ++++++++++++++------
 Source/cmMakefile.cxx                              |   19 ++++
 Source/cmMakefile.h                                |   35 ++++++-
 Source/cmPolicies.cxx                              |    2 +-
 Source/cmPolicies.h                                |    3 +-
 Tests/RunCMake/CMP0054/CMP0054-NEW.cmake           |   52 +++++++---
 Tests/RunCMake/CMP0054/CMP0054-OLD.cmake           |   52 +++++++---
 Tests/RunCMake/CMP0054/CMP0054-WARN-stderr.txt     |    7 +-
 .../CMP0054/CMP0054-duplicate-warnings-stderr.txt  |   22 ++++
 .../CMP0054/CMP0054-duplicate-warnings.cmake       |   12 +++
 .../CMP0054-keywords-NEW-result.txt}               |    0
 .../CMP0054/CMP0054-keywords-NEW-stderr.txt        |    8 ++
 Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake  |   23 +++++
 ...-stderr.txt => CMP0054-keywords-OLD-stderr.txt} |    0
 Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake  |    9 ++
 .../CMP0054/CMP0054-keywords-WARN-stderr.txt       |   10 ++
 Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake |    3 +
 ...txt => CMP0054-policy-command-scope-stderr.txt} |    0
 .../CMP0054/CMP0054-policy-command-scope.cmake     |   53 ++++++++++
 Tests/RunCMake/CMP0054/RunCMakeTest.cmake          |    5 +
 22 files changed, 374 insertions(+), 69 deletions(-)
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings-stderr.txt
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-duplicate-warnings.cmake
 copy Tests/RunCMake/{CMP0004/CMP0004-NEW-result.txt => CMP0054/CMP0054-keywords-NEW-result.txt} (100%)
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-keywords-NEW-stderr.txt
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-keywords-NEW.cmake
 copy Tests/RunCMake/CMP0054/{CMP0054-NEW-stderr.txt => CMP0054-keywords-OLD-stderr.txt} (100%)
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-keywords-OLD.cmake
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-keywords-WARN-stderr.txt
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-keywords-WARN.cmake
 copy Tests/RunCMake/CMP0054/{CMP0054-NEW-stderr.txt => CMP0054-policy-command-scope-stderr.txt} (100%)
 create mode 100644 Tests/RunCMake/CMP0054/CMP0054-policy-command-scope.cmake


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list