packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmIncludeCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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"
13
14
15 // cmIncludeCommand
16 bool cmIncludeCommand
17 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
18 {
19   if (args.size()< 1 || args.size() > 4)
20     {
21       this->SetError("called with wrong number of arguments.  "
22                      "Include only takes one file.");
23       return false;
24     }
25   bool optional = false;
26   bool noPolicyScope = false;
27   std::string fname = args[0];
28   std::string resultVarName;
29
30   for (unsigned int i=1; i<args.size(); i++)
31     {
32     if (args[i] == "OPTIONAL")
33       {
34       if (optional)
35         {
36         this->SetError("called with invalid arguments: OPTIONAL used twice");
37         return false;
38         }
39       optional = true;
40       }
41     else if(args[i] == "RESULT_VARIABLE")
42       {
43       if (resultVarName.size() > 0)
44         {
45         this->SetError("called with invalid arguments: "
46             "only one result variable allowed");
47         return false;
48         }
49       if(++i < args.size())
50         {
51         resultVarName = args[i];
52         }
53       else
54         {
55         this->SetError("called with no value for RESULT_VARIABLE.");
56         return false;
57         }
58       }
59     else if(args[i] == "NO_POLICY_SCOPE")
60       {
61       noPolicyScope = true;
62       }
63       else if(i > 1)  // compat.: in previous cmake versions the second
64                       // parameter was ignored if it wasn't "OPTIONAL"
65         {
66         std::string errorText = "called with invalid argument: ";
67         errorText += args[i];
68         this->SetError(errorText.c_str());
69         return false;
70         }
71     }
72
73   if(fname.empty())
74     {
75     this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
76                                  "include() given empty file name (ignored).");
77     return true;
78     }
79
80   if(!cmSystemTools::FileIsFullPath(fname.c_str()))
81     {
82     // Not a path. Maybe module.
83     std::string module = fname;
84     module += ".cmake";
85     std::string mfile = this->Makefile->GetModulesFile(module.c_str());
86     if ( mfile.size() )
87       {
88       fname = mfile.c_str();
89       }
90     }
91   std::string fullFilePath;
92   bool readit =
93     this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(),
94                                   fname.c_str(), &fullFilePath,
95                                   noPolicyScope);
96
97   // add the location of the included file if a result variable was given
98   if (resultVarName.size())
99     {
100       this->Makefile->AddDefinition(resultVarName.c_str(),
101                                     readit?fullFilePath.c_str():"NOTFOUND");
102     }
103
104   if(!optional && !readit && !cmSystemTools::GetFatalErrorOccured())
105     {
106     std::string m =
107       "could not find load file:\n"
108       "  ";
109     m += fname;
110     this->SetError(m.c_str());
111     return false;
112     }
113   return true;
114 }
115
116