summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2011-02-03 02:17:23 (GMT)
committerDavid Cole <david.cole@kitware.com>2011-02-03 02:19:01 (GMT)
commit106958c047c9af783b0216916c8e0d8c52595ff6 (patch)
treebf0cf3c08822dda3fe0cdf360128f971e89d3e4f /Source
parent94d1684a8fd0de4310874cd582636a8e26402da2 (diff)
downloadCMake-106958c047c9af783b0216916c8e0d8c52595ff6.zip
CMake-106958c047c9af783b0216916c8e0d8c52595ff6.tar.gz
CMake-106958c047c9af783b0216916c8e0d8c52595ff6.tar.bz2
Add CMAKE_ARGC and CMAKE_ARGV0..N-1 variables (#2828)
For now, these variables are only available in -P script mode.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDocumentVariables.cxx16
-rw-r--r--Source/cmMakefile.cxx16
-rw-r--r--Source/cmMakefile.h5
-rw-r--r--Source/cmake.cxx13
-rw-r--r--Source/cmake.h2
5 files changed, 46 insertions, 6 deletions
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