ENH: add optional include and only allow one file per INCLUDE

This commit is contained in:
Bill Hoffman 2001-06-21 10:36:01 -04:00
parent 3221b4e3fe
commit 43c2a89568
2 changed files with 17 additions and 8 deletions

View File

@ -20,18 +20,26 @@
// cmIncludeCommand // cmIncludeCommand
bool cmIncludeCommand::InitialPass(std::vector<std::string>& args) bool cmIncludeCommand::InitialPass(std::vector<std::string>& args)
{ {
if (args.size()< 1) if (args.size()< 1 || args.size() > 2)
{ {
this->SetError("called with wrong number of arguments."); this->SetError("called with wrong number of arguments. "
"Include only takes one file.");
} }
for( unsigned int i=0; i< args.size(); i++) m_Makefile->ExpandVariablesInString( args[0]);
bool exists = cmSystemTools::FileExists(args[0].c_str());
if(args.size() == 2 && args[1] == "OPTIONAL" && !exists)
{ {
m_Makefile->ExpandVariablesInString( args[i]); return true;
m_Makefile->ReadListFile( m_Makefile->GetCurrentListFile(),
args[i].c_str());
} }
if(!exists)
{
std::string error = "Include file not found: " + args[0];
this->SetError(error.c_str());
return false;
}
m_Makefile->ReadListFile( m_Makefile->GetCurrentListFile(),
args[0].c_str());
return true; return true;
} }

View File

@ -69,7 +69,8 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"INCLUDE(file1 file2)\n"; "INCLUDE(file1 [OPTIONAL])\nIf OPTIONAL is present, then do not complain "
"if the file does not exist.";
} }
cmTypeMacro(cmIncludeCommand, cmCommand); cmTypeMacro(cmIncludeCommand, cmCommand);