1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIncludeCommand.cxx,v $
6 Date: $Date: 2008-03-08 14:27:44 $
7 Version: $Revision: 1.21 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmIncludeCommand.h"
22 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
24 if (args
.size()< 1 || args
.size() > 4)
26 this->SetError("called with wrong number of arguments. "
27 "Include only takes one file.");
30 bool optional
= false;
31 std::string fname
= args
[0];
32 std::string resultVarName
;
34 for (unsigned int i
=1; i
<args
.size(); i
++)
36 if (args
[i
] == "OPTIONAL")
40 this->SetError("called with invalid arguments: OPTIONAL used twice");
45 else if(args
[i
] == "RESULT_VARIABLE")
47 if (resultVarName
.size() > 0)
49 this->SetError("called with invalid arguments: "
50 "only one result variable allowed");
55 resultVarName
= args
[i
];
59 this->SetError("called with no value for RESULT_VARIABLE.");
63 else if(i
> 1) // compat.: in previous cmake versions the second
64 // parameter was ignore if it wasn't "OPTIONAL"
66 std::string errorText
= "called with invalid argument: ";
68 this->SetError(errorText
.c_str());
73 if(!cmSystemTools::FileIsFullPath(fname
.c_str()))
75 // Not a path. Maybe module.
76 std::string module
= fname
;
78 std::string mfile
= this->Makefile
->GetModulesFile(module
.c_str());
81 fname
= mfile
.c_str();
84 std::string fullFilePath
;
86 this->Makefile
->ReadListFile( this->Makefile
->GetCurrentListFile(),
87 fname
.c_str(), &fullFilePath
);
89 // add the location of the included file if a result variable was given
90 if (resultVarName
.size())
92 this->Makefile
->AddDefinition(resultVarName
.c_str(),
93 readit
?fullFilePath
.c_str():"NOTFOUND");
96 if(!optional
&& !readit
&& !cmSystemTools::GetFatalErrorOccured())
99 "could not find load file:\n"
102 this->SetError(m
.c_str());