[Cmake-commits] CMake branch, next, updated. v3.1.0-rc2-968-g120e11f

Ben Boeckel ben.boeckel at kitware.com
Mon Dec 1 10:55:30 EST 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  120e11fe8cde02a574eb972c8f98cfb6d7a67648 (commit)
       via  ae676e46af6dab626a76c61a7be8ddd158535fa2 (commit)
       via  789d893af26dd8ef5e3a7de01b3a66767bb3b811 (commit)
      from  21e224e818871f074ba134faed05409c36ad613b (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=120e11fe8cde02a574eb972c8f98cfb6d7a67648
commit 120e11fe8cde02a574eb972c8f98cfb6d7a67648
Merge: 21e224e ae676e4
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Mon Dec 1 10:55:28 2014 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Dec 1 10:55:28 2014 -0500

    Merge topic 'cached-regex-clear-fixed' into next
    
    ae676e46 cmMakefile: store the number of last matches in a CMake var
    789d893a test: add a test for clearing regex results


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ae676e46af6dab626a76c61a7be8ddd158535fa2
commit ae676e46af6dab626a76c61a7be8ddd158535fa2
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Mon Dec 1 10:51:49 2014 -0500
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Mon Dec 1 10:55:15 2014 -0500

    cmMakefile: store the number of last matches in a CMake var
    
    With PushScope and PopScope, keeping track of another bit of data for
    each scope isn't easy. Instead, store it as another CMake variable so it
    gets implicitly tracked along with everything else.
    
    This works in a revert of commit
    7d674b5f0b28a610333644d417c2e8cb796cc9e4.

diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 99088e0..2de4103 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -47,6 +47,7 @@ Variables that Provide Information
    /variable/CMAKE_LINK_LIBRARY_SUFFIX
    /variable/CMAKE_MAJOR_VERSION
    /variable/CMAKE_MAKE_PROGRAM
+   /variable/CMAKE_MATCH_COUNT
    /variable/CMAKE_MINIMUM_REQUIRED_VERSION
    /variable/CMAKE_MINOR_VERSION
    /variable/CMAKE_PARENT_LIST_FILE
diff --git a/Help/variable/CMAKE_MATCH_COUNT.rst b/Help/variable/CMAKE_MATCH_COUNT.rst
new file mode 100644
index 0000000..4f7b9ab
--- /dev/null
+++ b/Help/variable/CMAKE_MATCH_COUNT.rst
@@ -0,0 +1,8 @@
+CMAKE_MATCH_COUNT
+-----------------
+
+The number of matches with the last regular expression.
+
+When a regular expression match is used, CMake fills in `CMAKE_MATCH_<n>`
+variables with the match contents. The `CMAKE_MATCH_COUNT` variable holds the
+number of match expressions when these are filled.
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index 6065b8a..aba26de 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -11,7 +11,6 @@
 ============================================================================*/
 
 #include "cmConditionEvaluator.h"
-#include "cmStringCommand.h"
 
 cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile):
   Makefile(makefile),
@@ -556,7 +555,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
         {
         def = this->GetVariableOrString(*arg);
         const char* rex = argP2->c_str();
-        cmStringCommand::ClearMatches(&this->Makefile);
+        this->Makefile.ClearMatches();
         cmsys::RegularExpression regEntry;
         if ( !regEntry.compile(rex) )
           {
@@ -568,7 +567,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList &newArgs,
           }
         if (regEntry.find(def))
           {
-          cmStringCommand::StoreMatches(&this->Makefile, regEntry);
+          this->Makefile.StoreMatches(regEntry);
           *arg = cmExpandedCommandArgument("1", true);
           }
         else
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 53fd56f..2a8bbd4 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4841,6 +4841,64 @@ std::vector<cmSourceFile*> cmMakefile::GetQtUiFilesWithOptions() const
   return this->QtUiFilesWithOptions;
 }
 
+static std::string matchVariables[] = {
+  "CMAKE_MATCH_0",
+  "CMAKE_MATCH_1",
+  "CMAKE_MATCH_2",
+  "CMAKE_MATCH_3",
+  "CMAKE_MATCH_4",
+  "CMAKE_MATCH_5",
+  "CMAKE_MATCH_6",
+  "CMAKE_MATCH_7",
+  "CMAKE_MATCH_8",
+  "CMAKE_MATCH_9"
+};
+
+static std::string nMatchesVariable = "CMAKE_MATCH_COUNT";
+
+//----------------------------------------------------------------------------
+void cmMakefile::ClearMatches()
+{
+  const char* nMatchesStr = this->GetDefinition(nMatchesVariable);
+  if (!nMatchesStr)
+    {
+    return;
+    }
+  int nMatches = atoi(nMatchesStr);
+  for (int i=0; i<nMatches; i++)
+    {
+    std::string const& var = matchVariables[i];
+    std::string const& s = this->GetSafeDefinition(var);
+    if(!s.empty())
+      {
+      this->AddDefinition(var, "");
+      this->MarkVariableAsUsed(var);
+      }
+    }
+  this->AddDefinition(nMatchesVariable, "0");
+  this->MarkVariableAsUsed(nMatchesVariable);
+}
+
+//----------------------------------------------------------------------------
+void cmMakefile::StoreMatches(cmsys::RegularExpression& re)
+{
+  char highest = 0;
+  for (unsigned int i=0; i<10; i++)
+    {
+    std::string const& m = re.match(i);
+    if(!m.empty())
+      {
+      std::string const& var = matchVariables[i];
+      this->AddDefinition(var, m.c_str());
+      this->MarkVariableAsUsed(var);
+      highest = '0' + i + 1;
+      }
+    }
+  char nMatches[] = {highest, '\0'};
+  this->AddDefinition(nMatchesVariable, nMatches);
+  this->MarkVariableAsUsed(nMatchesVariable);
+}
+
 //----------------------------------------------------------------------------
 cmPolicies::PolicyStatus
 cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 05b7a37..fcfec8d 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -976,6 +976,9 @@ public:
   void PopLoopBlock();
   bool IsLoopBlock() const;
 
+  void ClearMatches();
+  void StoreMatches(cmsys::RegularExpression& re);
+
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const std::string& name, cmTarget& target);
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 9827c62..8341027 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -310,7 +310,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
     input += args[i];
     }
 
-  this->ClearMatches(this->Makefile);
+  this->Makefile->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -325,7 +325,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
   std::string output;
   if(re.find(input.c_str()))
     {
-    this->StoreMatches(this->Makefile, re);
+    this->Makefile->StoreMatches(re);
     std::string::size_type l = re.start();
     std::string::size_type r = re.end();
     if(r-l == 0)
@@ -359,7 +359,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
     input += args[i];
     }
 
-  this->ClearMatches(this->Makefile);
+  this->Makefile->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -376,7 +376,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
   const char* p = input.c_str();
   while(re.find(p))
     {
-    this->StoreMatches(this->Makefile, re);
+    this->Makefile->StoreMatches(re);
     std::string::size_type l = re.start();
     std::string::size_type r = re.end();
     if(r-l == 0)
@@ -463,7 +463,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
     input += args[i];
     }
 
-  this->ClearMatches(this->Makefile);
+  this->Makefile->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -480,7 +480,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
   std::string::size_type base = 0;
   while(re.find(input.c_str()+base))
     {
-    this->StoreMatches(this->Makefile, re);
+    this->Makefile->StoreMatches(re);
     std::string::size_type l2 = re.start();
     std::string::size_type r = re.end();
 
@@ -541,38 +541,6 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
 }
 
 //----------------------------------------------------------------------------
-void cmStringCommand::ClearMatches(cmMakefile* mf)
-{
-  for (unsigned int i=0; i<10; i++)
-    {
-    char name[128];
-    sprintf(name, "CMAKE_MATCH_%d", i);
-    const char* s = mf->GetDefinition(name);
-    if(s && *s != 0)
-      {
-      mf->AddDefinition(name, "");
-      mf->MarkVariableAsUsed(name);
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
-void cmStringCommand::StoreMatches(cmMakefile* mf,cmsys::RegularExpression& re)
-{
-  for (unsigned int i=0; i<10; i++)
-    {
-    std::string m = re.match(i);
-    if(m.size() > 0)
-      {
-      char name[128];
-      sprintf(name, "CMAKE_MATCH_%d", i);
-      mf->AddDefinition(name, re.match(i).c_str());
-      mf->MarkVariableAsUsed(name);
-      }
-    }
-}
-
-//----------------------------------------------------------------------------
 bool cmStringCommand::HandleFindCommand(std::vector<std::string> const&
                                            args)
 {
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
index a5fe893..9c75095 100644
--- a/Source/cmStringCommand.h
+++ b/Source/cmStringCommand.h
@@ -53,8 +53,6 @@ public:
   virtual std::string GetName() const { return "string";}
 
   cmTypeMacro(cmStringCommand, cmCommand);
-  static void ClearMatches(cmMakefile* mf);
-  static void StoreMatches(cmMakefile* mf, cmsys::RegularExpression& re);
 protected:
   bool HandleConfigureCommand(std::vector<std::string> const& args);
   bool HandleAsciiCommand(std::vector<std::string> const& args);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=789d893af26dd8ef5e3a7de01b3a66767bb3b811
commit 789d893af26dd8ef5e3a7de01b3a66767bb3b811
Author:     Ben Boeckel <ben.boeckel at kitware.com>
AuthorDate: Wed Nov 26 12:46:55 2014 -0500
Commit:     Ben Boeckel <ben.boeckel at kitware.com>
CommitDate: Mon Dec 1 10:51:12 2014 -0500

    test: add a test for clearing regex results

diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index c9d9568..6ed3f0a 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -271,6 +271,7 @@ if(BUILD_TESTING)
   ADD_TEST_MACRO(MacroTest miniMacroTest)
   ADD_TEST_MACRO(FunctionTest miniFunctionTest)
   ADD_TEST_MACRO(ReturnTest ReturnTest)
+  ADD_TEST_MACRO(RegexClear RegexClear)
   ADD_TEST_MACRO(Properties Properties)
   ADD_TEST_MACRO(Assembler HelloAsm)
   ADD_TEST_MACRO(SourceGroups SourceGroups)
diff --git a/Tests/RegexClear/CMakeLists.txt b/Tests/RegexClear/CMakeLists.txt
new file mode 100644
index 0000000..5911b42
--- /dev/null
+++ b/Tests/RegexClear/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required (VERSION 3.0)
+project (RegexClear C)
+
+function (check_for_success)
+  if (CMAKE_MATCH_1 STREQUAL "0" AND
+      CMAKE_MATCH_2 STREQUAL "1")
+    message("Matched string properly")
+  else ()
+    message(FATAL_ERROR "Failed to match properly")
+  endif ()
+endfunction ()
+
+function (check_for_failure)
+  if (CMAKE_MATCH_1 STREQUAL "" AND
+      CMAKE_MATCH_2 STREQUAL "")
+    message("Matched nothing properly")
+  else ()
+    message(FATAL_ERROR "Found a match where there should be none")
+  endif ()
+endfunction ()
+
+macro (do_regex_success)
+  string(REGEX MATCH "(0)(1)" output "01")
+  check_for_success()
+endmacro ()
+
+macro (do_regex_failure)
+  string(REGEX MATCH "(0)(1)" output "12")
+  check_for_failure()
+endmacro ()
+
+do_regex_success()
+
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+find_package(dummy) # Ensure cmMakefile::PushScope/PopScope work.
+
+check_for_failure()
+do_regex_failure()
+do_regex_success()
+
+add_subdirectory(subdir)
+
+check_for_success() # Ensure that the subdir didn't mess with this scope.
+
+add_executable(RegexClear RegexClear.c)
diff --git a/Tests/RegexClear/RegexClear.c b/Tests/RegexClear/RegexClear.c
new file mode 100644
index 0000000..d123e09
--- /dev/null
+++ b/Tests/RegexClear/RegexClear.c
@@ -0,0 +1,4 @@
+int main(int argc, char** argv)
+{
+  return 0;
+}
diff --git a/Tests/RegexClear/cmake/Finddummy.cmake b/Tests/RegexClear/cmake/Finddummy.cmake
new file mode 100644
index 0000000..635e362
--- /dev/null
+++ b/Tests/RegexClear/cmake/Finddummy.cmake
@@ -0,0 +1,4 @@
+check_for_success()
+do_regex_failure()
+
+set(dummy_FOUND 1)
diff --git a/Tests/RegexClear/subdir/CMakeLists.txt b/Tests/RegexClear/subdir/CMakeLists.txt
new file mode 100644
index 0000000..2ed176a
--- /dev/null
+++ b/Tests/RegexClear/subdir/CMakeLists.txt
@@ -0,0 +1,2 @@
+check_for_success()
+do_regex_failure()

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

Summary of changes:
 Help/manual/cmake-variables.7.rst      |    1 +
 Help/variable/CMAKE_MATCH_COUNT.rst    |    8 +++++
 Source/cmConditionEvaluator.cxx        |    5 ++-
 Source/cmMakefile.cxx                  |   58 ++++++++++++++++++++++++++++++++
 Source/cmMakefile.h                    |    3 ++
 Source/cmStringCommand.cxx             |   44 ++++--------------------
 Source/cmStringCommand.h               |    2 --
 Tests/CMakeLists.txt                   |    1 +
 Tests/RegexClear/CMakeLists.txt        |   46 +++++++++++++++++++++++++
 Tests/RegexClear/RegexClear.c          |    4 +++
 Tests/RegexClear/cmake/Finddummy.cmake |    4 +++
 Tests/RegexClear/subdir/CMakeLists.txt |    2 ++
 12 files changed, 135 insertions(+), 43 deletions(-)
 create mode 100644 Help/variable/CMAKE_MATCH_COUNT.rst
 create mode 100644 Tests/RegexClear/CMakeLists.txt
 create mode 100644 Tests/RegexClear/RegexClear.c
 create mode 100644 Tests/RegexClear/cmake/Finddummy.cmake
 create mode 100644 Tests/RegexClear/subdir/CMakeLists.txt


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list