packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmTargetPropCommandBase.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2013 Stephen Kelly <steveire@gmail.com>
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
13 #include "cmTargetPropCommandBase.h"
14
15 #include "cmGlobalGenerator.h"
16
17 //----------------------------------------------------------------------------
18 bool cmTargetPropCommandBase
19 ::HandleArguments(std::vector<std::string> const& args, const char *prop,
20                  ArgumentFlags flags)
21 {
22   if(args.size() < 2)
23     {
24     this->SetError("called with incorrect number of arguments");
25     return false;
26     }
27
28   // Lookup the target for which libraries are specified.
29   if (this->Makefile->IsAlias(args[0].c_str()))
30     {
31     this->SetError("can not be used on an ALIAS target.");
32     return false;
33     }
34   this->Target =
35     this->Makefile->GetCMakeInstance()
36     ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
37   if(!this->Target)
38     {
39     this->Target = this->Makefile->FindTargetToUse(args[0].c_str());
40     }
41   if(!this->Target)
42     {
43     this->HandleMissingTarget(args[0]);
44     return false;
45     }
46   if ((this->Target->GetType() != cmTarget::SHARED_LIBRARY)
47     && (this->Target->GetType() != cmTarget::STATIC_LIBRARY)
48     && (this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
49     && (this->Target->GetType() != cmTarget::MODULE_LIBRARY)
50     && (this->Target->GetType() != cmTarget::EXECUTABLE))
51     {
52     this->SetError("called with non-compilable target type");
53     return false;
54     }
55
56   bool system = false;
57   unsigned int argIndex = 1;
58
59   if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
60     {
61     if (args.size() < 3)
62       {
63       this->SetError("called with incorrect number of arguments");
64       return false;
65       }
66     system = true;
67     ++argIndex;
68     }
69
70   bool prepend = false;
71   if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
72     {
73     if (args.size() < 3)
74       {
75       this->SetError("called with incorrect number of arguments");
76       return false;
77       }
78     prepend = true;
79     ++argIndex;
80     }
81
82   this->Property = prop;
83
84   while (argIndex < args.size())
85     {
86     if (!this->ProcessContentArgs(args, argIndex, prepend, system))
87       {
88       return false;
89       }
90     }
91   return true;
92 }
93
94 //----------------------------------------------------------------------------
95 bool cmTargetPropCommandBase
96 ::ProcessContentArgs(std::vector<std::string> const& args,
97                      unsigned int &argIndex, bool prepend, bool system)
98 {
99   const std::string scope = args[argIndex];
100
101   if(scope != "PUBLIC"
102       && scope != "PRIVATE"
103       && scope != "INTERFACE" )
104     {
105     this->SetError("called with invalid arguments");
106     return false;
107     }
108
109   if(this->Target->IsImported())
110     {
111     this->HandleImportedTarget(args[0]);
112     return false;
113     }
114
115   ++argIndex;
116
117   std::vector<std::string> content;
118
119   for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
120     {
121     if(args[i] == "PUBLIC"
122         || args[i] == "PRIVATE"
123         || args[i] == "INTERFACE" )
124       {
125       this->PopulateTargetProperies(scope, content, prepend, system);
126       return true;
127       }
128     content.push_back(args[i]);
129     }
130   this->PopulateTargetProperies(scope, content, prepend, system);
131   return true;
132 }
133
134 //----------------------------------------------------------------------------
135 void cmTargetPropCommandBase
136 ::PopulateTargetProperies(const std::string &scope,
137                           const std::vector<std::string> &content,
138                           bool prepend, bool system)
139 {
140   if (scope == "PRIVATE" || scope == "PUBLIC")
141     {
142     this->HandleDirectContent(this->Target, content, prepend, system);
143     }
144   if (scope == "INTERFACE" || scope == "PUBLIC")
145     {
146     this->HandleInterfaceContent(this->Target, content, prepend, system);
147     }
148 }
149
150 //----------------------------------------------------------------------------
151 void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
152                                   const std::vector<std::string> &content,
153                                   bool prepend, bool)
154 {
155   if (prepend)
156     {
157     const std::string propName = std::string("INTERFACE_") + this->Property;
158     const char *propValue = tgt->GetProperty(propName.c_str());
159     const std::string totalContent = this->Join(content) + (propValue
160                                               ? std::string(";") + propValue
161                                               : std::string());
162     tgt->SetProperty(propName.c_str(), totalContent.c_str());
163     }
164   else
165     {
166     tgt->AppendProperty(("INTERFACE_" + this->Property).c_str(),
167                           this->Join(content).c_str());
168     }
169 }