[cmake-commits] alex committed cmIncludeCommand.h 1.14 1.14.4.1
cmIncludeCommand.cxx 1.18 1.18.2.1
cmake-commits at cmake.org
cmake-commits at cmake.org
Fri May 11 11:55:03 EDT 2007
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv30495
Modified Files:
Tag: CMake-CrossCompileBasic
cmIncludeCommand.h cmIncludeCommand.cxx
Log Message:
ENH: if OPTIONAL is used, give the user a way to check whether the file was
included or not (by setting a variable to the full path or NOTFOUND)
Additionally now fail if a second argument is used and this is not
"OPTIONAL"
Alex
Index: cmIncludeCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIncludeCommand.cxx,v
retrieving revision 1.18
retrieving revision 1.18.2.1
diff -u -d -r1.18 -r1.18.2.1
--- cmIncludeCommand.cxx 11 May 2006 19:50:11 -0000 1.18
+++ cmIncludeCommand.cxx 11 May 2007 15:55:01 -0000 1.18.2.1
@@ -20,7 +20,7 @@
// cmIncludeCommand
bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args)
{
- if (args.size()< 1 || args.size() > 2)
+ if (args.size()< 1 || args.size() > 3)
{
this->SetError("called with wrong number of arguments. "
"Include only takes one file.");
@@ -28,11 +28,25 @@
}
bool optional = false;
- std::string fname = args[0].c_str();
+ std::string fname = args[0];
+ std::string resultVarName;
- if(args.size() == 2)
+ if(args.size() > 1)
{
- optional = args[1] == "OPTIONAL";
+ if (args[1] == "OPTIONAL")
+ {
+ optional = true;
+ if (args.size() == 3)
+ {
+ resultVarName = args[2];
+ }
+ }
+ else
+ {
+ this->SetError("called with invalid second argument "
+ "(must be \"OPTIONAL\")");
+ return false;
+ }
}
if(!cmSystemTools::FileIsFullPath(fname.c_str()))
@@ -49,6 +63,14 @@
bool readit =
this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
fname.c_str() );
+
+ // add the location of the included file if a result variable was given
+ if (resultVarName.size())
+ {
+ this->Makefile->AddDefinition(resultVarName.c_str(),
+ readit?fname.c_str():"NOTFOUND");
+ }
+
if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
{
std::string m = "Could not find include file: ";
Index: cmIncludeCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmIncludeCommand.h,v
retrieving revision 1.14
retrieving revision 1.14.4.1
diff -u -d -r1.14 -r1.14.4.1
--- cmIncludeCommand.h 16 Nov 2005 19:11:09 -0000 1.14
+++ cmIncludeCommand.h 11 May 2007 15:55:01 -0000 1.14.4.1
@@ -68,12 +68,14 @@
virtual const char* GetFullDocumentation()
{
return
- " INCLUDE(file1 [OPTIONAL])\n"
- " INCLUDE(module [OPTIONAL])\n"
+ " INCLUDE(file1 [OPTIONAL [<VAR>]])\n"
+ " INCLUDE(module [OPTIONAL [<VAR>]])\n"
"Reads CMake listfile code from the given file. Commands in the file "
"are processed immediately as if they were written in place of the "
"INCLUDE command. If OPTIONAL is present, then no error "
- "is raised if the file does not exist.\n"
+ "is raised if the file does not exist. If additionally to OPTIONAL "
+ "a variable is given, it will be set to the full filename which "
+ "has been included or NOTFOUND if it failed.\n"
"If a module is specified instead of a file, the file with name "
"<modulename>.cmake is searched in the CMAKE_MODULE_PATH.";
}
More information about the Cmake-commits
mailing list