Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmIncludeCommand.cxx
blob395a9d770cbeeb96142b18c36bcf1592a6bfe794
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIncludeCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.20 $
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"
20 // cmIncludeCommand
21 bool cmIncludeCommand
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.");
28 return false;
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")
38 if (optional)
40 this->SetError("called with invalid arguments: OPTIONAL used twice");
41 return false;
43 optional = true;
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");
51 return false;
53 if(++i < args.size())
55 resultVarName = args[i];
57 else
59 this->SetError("called with no value for RESULT_VARIABLE.");
60 return false;
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: ";
67 errorText += args[i];
68 this->SetError(errorText.c_str());
69 return false;
73 if(!cmSystemTools::FileIsFullPath(fname.c_str()))
75 // Not a path. Maybe module.
76 std::string module = fname;
77 module += ".cmake";
78 std::string mfile = this->Makefile->GetModulesFile(module.c_str());
79 if ( mfile.size() )
81 fname = mfile.c_str();
84 std::string fullFilePath;
85 bool readit =
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())
98 std::string m = "Could not find include file: ";
99 m += fname;
100 this->SetError(m.c_str());
101 return false;
103 return true;