packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmDefinePropertyCommand.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 "cmDefinePropertyCommand.h"
13 #include "cmake.h"
14
15 // cmDefinePropertiesCommand
16 bool cmDefinePropertyCommand
17 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
18 {
19   if(args.size() < 1)
20     {
21     this->SetError("called with incorrect number of arguments");
22     return false;
23     }
24
25   // Get the scope in which to define the property.
26   cmProperty::ScopeType scope;
27   if(args[0] == "GLOBAL")
28     {
29     scope = cmProperty::GLOBAL;
30     }
31   else if(args[0] == "DIRECTORY")
32     {
33     scope = cmProperty::DIRECTORY;
34     }
35   else if(args[0] == "TARGET")
36     {
37     scope = cmProperty::TARGET;
38     }
39   else if(args[0] == "SOURCE")
40     {
41     scope = cmProperty::SOURCE_FILE;
42     }
43   else if(args[0] == "TEST")
44     {
45     scope = cmProperty::TEST;
46     }
47   else if(args[0] == "VARIABLE")
48     {
49     scope = cmProperty::VARIABLE;
50     }
51   else if (args[0] == "CACHED_VARIABLE")
52     {
53     scope = cmProperty::CACHED_VARIABLE;
54     }
55   else
56     {
57     cmOStringStream e;
58     e << "given invalid scope " << args[0] << ".  "
59       << "Valid scopes are "
60       << "GLOBAL, DIRECTORY, TARGET, SOURCE, "
61       << "TEST, VARIABLE, CACHED_VARIABLE.";
62     this->SetError(e.str().c_str());
63     return false;
64     }
65
66   // Parse remaining arguments.
67   bool inherited = false;
68   enum Doing { DoingNone, DoingProperty, DoingBrief, DoingFull };
69   Doing doing = DoingNone;
70   for(unsigned int i=1; i < args.size(); ++i)
71     {
72     if(args[i] == "PROPERTY")
73       {
74       doing = DoingProperty;
75       }
76     else if(args[i] == "BRIEF_DOCS")
77       {
78       doing = DoingBrief;
79       }
80     else if(args[i] == "FULL_DOCS")
81       {
82       doing = DoingFull;
83       }
84     else if(args[i] == "INHERITED")
85       {
86       doing = DoingNone;
87       inherited = true;
88       }
89     else if(doing == DoingProperty)
90       {
91       doing = DoingNone;
92       this->PropertyName = args[i];
93       }
94     else if(doing == DoingBrief)
95       {
96       this->BriefDocs += args[i];
97       }
98     else if(doing == DoingFull)
99       {
100       this->FullDocs += args[i];
101       }
102     else
103       {
104       cmOStringStream e;
105       e << "given invalid argument \"" << args[i] << "\".";
106       this->SetError(e.str().c_str());
107       return false;
108       }
109     }
110
111   // Make sure a property name was found.
112   if(this->PropertyName.empty())
113     {
114     this->SetError("not given a PROPERTY <name> argument.");
115     return false;
116     }
117
118   // Make sure documentation was given.
119   if(this->BriefDocs.empty())
120     {
121     this->SetError("not given a BRIEF_DOCS <brief-doc> argument.");
122     return false;
123     }
124   if(this->FullDocs.empty())
125     {
126     this->SetError("not given a FULL_DOCS <full-doc> argument.");
127     return false;
128     }
129
130   // Actually define the property.
131   this->Makefile->GetCMakeInstance()->DefineProperty
132     (this->PropertyName.c_str(), scope,
133      this->BriefDocs.c_str(), this->FullDocs.c_str(), inherited);
134
135   return true;
136 }
137