[Cmake-commits] CMake branch, next, updated. v2.8.3-1558-gabed95d

David Cole david.cole at kitware.com
Thu Feb 3 07:38:02 EST 2011


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  abed95d8e5af35d2c46434245b31eba01910ceb0 (commit)
       via  106958c047c9af783b0216916c8e0d8c52595ff6 (commit)
       via  94d1684a8fd0de4310874cd582636a8e26402da2 (commit)
      from  4d4d51e1f9b2e195855939fb4cfb4dc18551dfbe (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=abed95d8e5af35d2c46434245b31eba01910ceb0
commit abed95d8e5af35d2c46434245b31eba01910ceb0
Merge: 4d4d51e 106958c
Author:     David Cole <david.cole at kitware.com>
AuthorDate: Thu Feb 3 07:37:59 2011 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Feb 3 07:37:59 2011 -0500

    Merge topic 'fix-2828-more-info-in-script-mode' into next
    
    106958c Add CMAKE_ARGC and CMAKE_ARGV0..N-1 variables (#2828)
    94d1684 Add CMAKE_SCRIPT_MODE_FILE variable (#2828)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=106958c047c9af783b0216916c8e0d8c52595ff6
commit 106958c047c9af783b0216916c8e0d8c52595ff6
Author:     David Cole <david.cole at kitware.com>
AuthorDate: Wed Feb 2 21:17:23 2011 -0500
Commit:     David Cole <david.cole at kitware.com>
CommitDate: Wed Feb 2 21:19:01 2011 -0500

    Add CMAKE_ARGC and CMAKE_ARGV0..N-1 variables (#2828)
    
    For now, these variables are only available in -P script mode.

diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 897881c..a08f95c 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -105,6 +105,22 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "Variables that Provide Information");
 
   cm->DefineProperty
+    ("CMAKE_ARGC", cmProperty::VARIABLE,
+     "Number of command line arguments passed to CMake in script mode. ",
+     "When run in -P script mode, CMake sets this variable to the number "
+     "of command line arguments. See also CMAKE_ARGV0, 1, 2 ... ", false,
+     "Variables that Provide Information");
+
+  cm->DefineProperty
+    ("CMAKE_ARGV0", cmProperty::VARIABLE,
+     "Command line argument passed to CMake in script mode. ",
+     "When run in -P script mode, CMake sets this variable to "
+     "the first command line argument. It then also sets CMAKE_ARGV1, "
+     "CMAKE_ARGV2, ... and so on, up to the number of command line arguments "
+     "given. See also CMAKE_ARGC.", false,
+     "Variables that Provide Information");
+
+  cm->DefineProperty
     ("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
      "Tool used for the actual build process.",
      "This variable is set to the program that will be"
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index daea7bf..3fa846a 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2749,6 +2749,22 @@ void cmMakefile::SetScriptModeFile(const char* scriptfile)
   this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
 }
 
+void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
+{
+  cmOStringStream strStream;
+  strStream << args.size();
+  this->AddDefinition("CMAKE_ARGC", strStream.str().c_str());
+  //this->MarkVariableAsUsed("CMAKE_ARGC");
+
+  for (unsigned int t = 0; t < args.size(); ++t)
+  {
+    cmOStringStream tmpStream;
+    tmpStream << "CMAKE_ARGV" << t;
+    this->AddDefinition(tmpStream.str().c_str(), args[t].c_str());
+    //this->MarkVariableAsUsed(tmpStream.str().c_str());
+  }
+}
+
 //----------------------------------------------------------------------------
 cmSourceFile* cmMakefile::GetSource(const char* sourceName)
 {
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index ebe2801..1c1aef3 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -417,6 +417,11 @@ public:
    */
   void SetScriptModeFile(const char* scriptfile);
 
+  /**
+   * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
+   */
+  void SetArgcArgv(const std::vector<std::string>& args);
+
   //@{
   /**
    * Set/Get the start directory (or output directory). The start directory
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index e063ea6..215971f 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -462,7 +462,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
           }
         }
       std::cerr << "loading initial cache file " << path.c_str() << "\n";
-      this->ReadListFile(path.c_str());
+      this->ReadListFile(args, path.c_str());
       }
     else if(arg.find("-P",0) == 0)
       {
@@ -478,13 +478,13 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         cmSystemTools::Error("No cmake script provided.");
         return false;
         }
-      this->ReadListFile(path.c_str());
+      this->ReadListFile(args, path.c_str());
       }
     }
   return true;
 }
 
-void cmake::ReadListFile(const char *path)
+void cmake::ReadListFile(const std::vector<std::string>& args, const char *path)
 {
   // if a generator was not yet created, temporarily create one
   cmGlobalGenerator *gg = this->GetGlobalGenerator();
@@ -515,6 +515,8 @@ void cmake::ReadListFile(const char *path)
       std::string file(cmSystemTools::CollapseFullPath(path));
       cmSystemTools::ConvertToUnixSlashes(file);
       lg->GetMakefile()->SetScriptModeFile(file.c_str());
+
+      lg->GetMakefile()->SetArgcArgv(args);
       }
     if (!lg->GetMakefile()->ReadListFile(0, path))
       {
@@ -2203,13 +2205,14 @@ int cmake::ActualConfigure()
 
 void cmake::PreLoadCMakeFiles()
 {
+  std::vector<std::string> args;
   std::string pre_load = this->GetHomeDirectory();
   if ( pre_load.size() > 0 )
     {
     pre_load += "/PreLoad.cmake";
     if ( cmSystemTools::FileExists(pre_load.c_str()) )
       {
-      this->ReadListFile(pre_load.c_str());
+      this->ReadListFile(args, pre_load.c_str());
       }
     }
   pre_load = this->GetHomeOutputDirectory();
@@ -2218,7 +2221,7 @@ void cmake::PreLoadCMakeFiles()
     pre_load += "/PreLoad.cmake";
     if ( cmSystemTools::FileExists(pre_load.c_str()) )
       {
-      this->ReadListFile(pre_load.c_str());
+      this->ReadListFile(args, pre_load.c_str());
       }
     }
 }
diff --git a/Source/cmake.h b/Source/cmake.h
index 1bb42d3..7c75c2f 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -406,7 +406,7 @@ protected:
   bool DoSuppressDevWarnings;
 
   ///! read in a cmake list file to initialize the cache
-  void ReadListFile(const char *path);
+  void ReadListFile(const std::vector<std::string>& args, const char *path);
 
   ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
   ///  If it is set, truncate it to 50kb

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=94d1684a8fd0de4310874cd582636a8e26402da2
commit 94d1684a8fd0de4310874cd582636a8e26402da2
Author:     David Cole <david.cole at kitware.com>
AuthorDate: Wed Feb 2 18:18:14 2011 -0500
Commit:     David Cole <david.cole at kitware.com>
CommitDate: Wed Feb 2 18:18:14 2011 -0500

    Add CMAKE_SCRIPT_MODE_FILE variable (#2828)
    
    New CMake variable is set when processing a -P script file,
    but not when configuring a project.

diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 6fffecb..897881c 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -97,6 +97,14 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "Variables that Provide Information");
 
   cm->DefineProperty
+    ("CMAKE_SCRIPT_MODE_FILE", cmProperty::VARIABLE,
+     "Full path to the -P script file currently being processed. ",
+     "When run in -P script mode, CMake sets this variable to the full "
+     "path of the script file. When run to configure a CMakeLists.txt "
+     "file, this variable is not set.", false,
+     "Variables that Provide Information");
+
+  cm->DefineProperty
     ("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
      "Tool used for the actual build process.",
      "This variable is set to the program that will be"
diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx
index e3448de..8bb5487 100644
--- a/Source/cmGetCMakePropertyCommand.cxx
+++ b/Source/cmGetCMakePropertyCommand.cxx
@@ -22,21 +22,22 @@ bool cmGetCMakePropertyCommand
     this->SetError("called with incorrect number of arguments");
     return false;
     }
-  
+
   std::vector<std::string>::size_type cc;
   std::string variable = args[0];
   std::string output = "NOTFOUND";
 
-  if ( args[1] == "VARIABLES")
+  if ( args[1] == "VARIABLES" )
     {
     int cacheonly = 0;
     std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
-    for ( cc = 0; cc < vars.size(); cc ++ )
+    if (vars.size()>0)
       {
-      if ( cc > 0 )
-        {
-        output += ";";
-        }
+      output = vars[0];
+      }
+    for ( cc = 1; cc < vars.size(); ++cc )
+      {
+      output += ";";
       output += vars[cc];
       }
     }
@@ -62,15 +63,15 @@ bool cmGetCMakePropertyCommand
     }
   else
     {
-    const char *prop = 
+    const char *prop =
       this->Makefile->GetCMakeInstance()->GetProperty(args[1].c_str());
     if (prop)
       {
       output = prop;
       }
     }
+
   this->Makefile->AddDefinition(variable.c_str(), output.c_str());
-  
+
   return true;
 }
-
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index e14e44d..daea7bf 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -2744,6 +2744,11 @@ void cmMakefile::SetHomeOutputDirectory(const char* lib)
     }
 }
 
+void cmMakefile::SetScriptModeFile(const char* scriptfile)
+{
+  this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
+}
+
 //----------------------------------------------------------------------------
 cmSourceFile* cmMakefile::GetSource(const char* sourceName)
 {
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 837a352..ebe2801 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -411,7 +411,12 @@ public:
       return this->HomeOutputDirectory.c_str();
     }
   //@}
-  
+
+  /**
+   * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
+   */
+  void SetScriptModeFile(const char* scriptfile);
+
   //@{
   /**
    * Set/Get the start directory (or output directory). The start directory
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index bab0aaf..e063ea6 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -510,6 +510,12 @@ void cmake::ReadListFile(const char *path)
       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
     lg->GetMakefile()->SetStartDirectory
       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
+    if (this->GetScriptMode())
+      {
+      std::string file(cmSystemTools::CollapseFullPath(path));
+      cmSystemTools::ConvertToUnixSlashes(file);
+      lg->GetMakefile()->SetScriptModeFile(file.c_str());
+      }
     if (!lg->GetMakefile()->ReadListFile(0, path))
       {
       cmSystemTools::Error("Error processing file:", path);
diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake
index 3703856..d1db2ee 100644
--- a/Tests/CMakeTests/StringTestScript.cmake
+++ b/Tests/CMakeTests/StringTestScript.cmake
@@ -194,6 +194,8 @@ elseif(testname STREQUAL random_with_various_alphabets) # pass
   string(RANDOM LENGTH 78 ALPHABET "~`!@#$%^&*()_-+={}[]\\|:\\;'\",.<>/?" v)
   message(STATUS "v='${v}'")
 
+  message(STATUS "CMAKE_SCRIPT_MODE_FILE='${CMAKE_SCRIPT_MODE_FILE}'")
+
 else() # fail
   message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")
 

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

Summary of changes:
 Source/cmDocumentVariables.cxx          |   24 ++++++++++++++++++++++++
 Source/cmGetCMakePropertyCommand.cxx    |   21 +++++++++++----------
 Source/cmMakefile.cxx                   |   21 +++++++++++++++++++++
 Source/cmMakefile.h                     |   12 +++++++++++-
 Source/cmake.cxx                        |   19 ++++++++++++++-----
 Source/cmake.h                          |    2 +-
 Tests/CMakeTests/StringTestScript.cmake |    2 ++
 7 files changed, 84 insertions(+), 17 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list