Merge topic 'fix-2828-more-info-in-script-mode'

a58ace6 Fix KWStyle line-too-long complaint (#2828)
106958c Add CMAKE_ARGC and CMAKE_ARGV0..N-1 variables (#2828)
94d1684 Add CMAKE_SCRIPT_MODE_FILE variable (#2828)
This commit is contained in:
Brad King 2011-02-22 14:32:48 -05:00 committed by CMake Topic Stage
commit 6250c7324f
7 changed files with 85 additions and 17 deletions

View File

@ -96,6 +96,30 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
"See also CMAKE_CURRENT_LIST_FILE.",false, "See also CMAKE_CURRENT_LIST_FILE.",false,
"Variables that Provide Information"); "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_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 cm->DefineProperty
("CMAKE_BUILD_TOOL", cmProperty::VARIABLE, ("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
"Tool used for the actual build process.", "Tool used for the actual build process.",

View File

@ -22,21 +22,22 @@ bool cmGetCMakePropertyCommand
this->SetError("called with incorrect number of arguments"); this->SetError("called with incorrect number of arguments");
return false; return false;
} }
std::vector<std::string>::size_type cc; std::vector<std::string>::size_type cc;
std::string variable = args[0]; std::string variable = args[0];
std::string output = "NOTFOUND"; std::string output = "NOTFOUND";
if ( args[1] == "VARIABLES") if ( args[1] == "VARIABLES" )
{ {
int cacheonly = 0; int cacheonly = 0;
std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly); std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
for ( cc = 0; cc < vars.size(); cc ++ ) if (vars.size()>0)
{ {
if ( cc > 0 ) output = vars[0];
{ }
output += ";"; for ( cc = 1; cc < vars.size(); ++cc )
} {
output += ";";
output += vars[cc]; output += vars[cc];
} }
} }
@ -62,15 +63,15 @@ bool cmGetCMakePropertyCommand
} }
else else
{ {
const char *prop = const char *prop =
this->Makefile->GetCMakeInstance()->GetProperty(args[1].c_str()); this->Makefile->GetCMakeInstance()->GetProperty(args[1].c_str());
if (prop) if (prop)
{ {
output = prop; output = prop;
} }
} }
this->Makefile->AddDefinition(variable.c_str(), output.c_str()); this->Makefile->AddDefinition(variable.c_str(), output.c_str());
return true; return true;
} }

View File

@ -2744,6 +2744,27 @@ void cmMakefile::SetHomeOutputDirectory(const char* lib)
} }
} }
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) cmSourceFile* cmMakefile::GetSource(const char* sourceName)
{ {

View File

@ -411,7 +411,17 @@ public:
return this->HomeOutputDirectory.c_str(); return this->HomeOutputDirectory.c_str();
} }
//@} //@}
/**
* Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
*/
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 * Set/Get the start directory (or output directory). The start directory

View File

@ -462,7 +462,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
} }
} }
std::cerr << "loading initial cache file " << path.c_str() << "\n"; 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) else if(arg.find("-P",0) == 0)
{ {
@ -478,13 +478,14 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
cmSystemTools::Error("No cmake script provided."); cmSystemTools::Error("No cmake script provided.");
return false; return false;
} }
this->ReadListFile(path.c_str()); this->ReadListFile(args, path.c_str());
} }
} }
return true; 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 // if a generator was not yet created, temporarily create one
cmGlobalGenerator *gg = this->GetGlobalGenerator(); cmGlobalGenerator *gg = this->GetGlobalGenerator();
@ -510,6 +511,14 @@ void cmake::ReadListFile(const char *path)
(cmSystemTools::GetCurrentWorkingDirectory().c_str()); (cmSystemTools::GetCurrentWorkingDirectory().c_str());
lg->GetMakefile()->SetStartDirectory lg->GetMakefile()->SetStartDirectory
(cmSystemTools::GetCurrentWorkingDirectory().c_str()); (cmSystemTools::GetCurrentWorkingDirectory().c_str());
if (this->GetScriptMode())
{
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)) if (!lg->GetMakefile()->ReadListFile(0, path))
{ {
cmSystemTools::Error("Error processing file:", path); cmSystemTools::Error("Error processing file:", path);
@ -2223,13 +2232,14 @@ int cmake::ActualConfigure()
void cmake::PreLoadCMakeFiles() void cmake::PreLoadCMakeFiles()
{ {
std::vector<std::string> args;
std::string pre_load = this->GetHomeDirectory(); std::string pre_load = this->GetHomeDirectory();
if ( pre_load.size() > 0 ) if ( pre_load.size() > 0 )
{ {
pre_load += "/PreLoad.cmake"; pre_load += "/PreLoad.cmake";
if ( cmSystemTools::FileExists(pre_load.c_str()) ) if ( cmSystemTools::FileExists(pre_load.c_str()) )
{ {
this->ReadListFile(pre_load.c_str()); this->ReadListFile(args, pre_load.c_str());
} }
} }
pre_load = this->GetHomeOutputDirectory(); pre_load = this->GetHomeOutputDirectory();
@ -2238,7 +2248,7 @@ void cmake::PreLoadCMakeFiles()
pre_load += "/PreLoad.cmake"; pre_load += "/PreLoad.cmake";
if ( cmSystemTools::FileExists(pre_load.c_str()) ) if ( cmSystemTools::FileExists(pre_load.c_str()) )
{ {
this->ReadListFile(pre_load.c_str()); this->ReadListFile(args, pre_load.c_str());
} }
} }
} }

View File

@ -406,7 +406,7 @@ protected:
bool DoSuppressDevWarnings; bool DoSuppressDevWarnings;
///! read in a cmake list file to initialize the cache ///! 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. ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
/// If it is set, truncate it to 50kb /// If it is set, truncate it to 50kb

View File

@ -194,6 +194,8 @@ elseif(testname STREQUAL random_with_various_alphabets) # pass
string(RANDOM LENGTH 78 ALPHABET "~`!@#$%^&*()_-+={}[]\\|:\\;'\",.<>/?" v) string(RANDOM LENGTH 78 ALPHABET "~`!@#$%^&*()_-+={}[]\\|:\\;'\",.<>/?" v)
message(STATUS "v='${v}'") message(STATUS "v='${v}'")
message(STATUS "CMAKE_SCRIPT_MODE_FILE='${CMAKE_SCRIPT_MODE_FILE}'")
else() # fail else() # fail
message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'") message(FATAL_ERROR "testname='${testname}' - error: no such test in '${CMAKE_CURRENT_LIST_FILE}'")