1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmIncludeCommand.h"
17 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 if (args.size()< 1 || args.size() > 4)
21 this->SetError("called with wrong number of arguments. "
22 "Include only takes one file.");
25 bool optional = false;
26 bool noPolicyScope = false;
27 std::string fname = args[0];
28 std::string resultVarName;
30 for (unsigned int i=1; i<args.size(); i++)
32 if (args[i] == "OPTIONAL")
36 this->SetError("called with invalid arguments: OPTIONAL used twice");
41 else if(args[i] == "RESULT_VARIABLE")
43 if (resultVarName.size() > 0)
45 this->SetError("called with invalid arguments: "
46 "only one result variable allowed");
51 resultVarName = args[i];
55 this->SetError("called with no value for RESULT_VARIABLE.");
59 else if(args[i] == "NO_POLICY_SCOPE")
63 else if(i > 1) // compat.: in previous cmake versions the second
64 // parameter was ignored if it wasn't "OPTIONAL"
66 std::string errorText = "called with invalid argument: ";
68 this->SetError(errorText.c_str());
75 this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
76 "include() given empty file name (ignored).");
80 if(!cmSystemTools::FileIsFullPath(fname.c_str()))
82 // Not a path. Maybe module.
83 std::string module = fname;
85 std::string mfile = this->Makefile->GetModulesFile(module.c_str());
88 fname = mfile.c_str();
91 std::string fullFilePath;
93 this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
94 fname.c_str(), &fullFilePath,
97 // add the location of the included file if a result variable was given
98 if (resultVarName.size())
100 this->Makefile->AddDefinition(resultVarName.c_str(),
101 readit?fullFilePath.c_str():"NOTFOUND");
104 if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
107 "could not find load file:\n"
110 this->SetError(m.c_str());