1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIncludeCommand.cxx,v $
6 Date: $Date: 2009-01-22 18:18:39 $
7 Version: $Revision: 1.22 $
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 bool noPolicyScope
= false;
32 std::string fname
= args
[0];
33 std::string resultVarName
;
35 for (unsigned int i
=1; i
<args
.size(); i
++)
37 if (args
[i
] == "OPTIONAL")
41 this->SetError("called with invalid arguments: OPTIONAL used twice");
46 else if(args
[i
] == "RESULT_VARIABLE")
48 if (resultVarName
.size() > 0)
50 this->SetError("called with invalid arguments: "
51 "only one result variable allowed");
56 resultVarName
= args
[i
];
60 this->SetError("called with no value for RESULT_VARIABLE.");
64 else if(args
[i
] == "NO_POLICY_SCOPE")
68 else if(i
> 1) // compat.: in previous cmake versions the second
69 // parameter was ignore if it wasn't "OPTIONAL"
71 std::string errorText
= "called with invalid argument: ";
73 this->SetError(errorText
.c_str());
78 if(!cmSystemTools::FileIsFullPath(fname
.c_str()))
80 // Not a path. Maybe module.
81 std::string module
= fname
;
83 std::string mfile
= this->Makefile
->GetModulesFile(module
.c_str());
86 fname
= mfile
.c_str();
89 std::string fullFilePath
;
91 this->Makefile
->ReadListFile( this->Makefile
->GetCurrentListFile(),
92 fname
.c_str(), &fullFilePath
,
95 // add the location of the included file if a result variable was given
96 if (resultVarName
.size())
98 this->Makefile
->AddDefinition(resultVarName
.c_str(),
99 readit
?fullFilePath
.c_str():"NOTFOUND");
102 if(!optional
&& !readit
&& !cmSystemTools::GetFatalErrorOccured())
105 "could not find load file:\n"
108 this->SetError(m
.c_str());