1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2013 Stephen Kelly <steveire@gmail.com>
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 ============================================================================*/
13 #include "cmTargetPropCommandBase.h"
15 #include "cmGlobalGenerator.h"
17 //----------------------------------------------------------------------------
18 bool cmTargetPropCommandBase
19 ::HandleArguments(std::vector<std::string> const& args, const char *prop,
24 this->SetError("called with incorrect number of arguments");
28 // Lookup the target for which libraries are specified.
29 if (this->Makefile->IsAlias(args[0].c_str()))
31 this->SetError("can not be used on an ALIAS target.");
35 this->Makefile->GetCMakeInstance()
36 ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
39 this->Target = this->Makefile->FindTargetToUse(args[0].c_str());
43 this->HandleMissingTarget(args[0]);
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))
52 this->SetError("called with non-compilable target type");
57 unsigned int argIndex = 1;
59 if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM")
63 this->SetError("called with incorrect number of arguments");
71 if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE")
75 this->SetError("called with incorrect number of arguments");
82 this->Property = prop;
84 while (argIndex < args.size())
86 if (!this->ProcessContentArgs(args, argIndex, prepend, system))
94 //----------------------------------------------------------------------------
95 bool cmTargetPropCommandBase
96 ::ProcessContentArgs(std::vector<std::string> const& args,
97 unsigned int &argIndex, bool prepend, bool system)
99 const std::string scope = args[argIndex];
102 && scope != "PRIVATE"
103 && scope != "INTERFACE" )
105 this->SetError("called with invalid arguments");
109 if(this->Target->IsImported())
111 this->HandleImportedTarget(args[0]);
117 std::vector<std::string> content;
119 for(unsigned int i=argIndex; i < args.size(); ++i, ++argIndex)
121 if(args[i] == "PUBLIC"
122 || args[i] == "PRIVATE"
123 || args[i] == "INTERFACE" )
125 this->PopulateTargetProperies(scope, content, prepend, system);
128 content.push_back(args[i]);
130 this->PopulateTargetProperies(scope, content, prepend, system);
134 //----------------------------------------------------------------------------
135 void cmTargetPropCommandBase
136 ::PopulateTargetProperies(const std::string &scope,
137 const std::vector<std::string> &content,
138 bool prepend, bool system)
140 if (scope == "PRIVATE" || scope == "PUBLIC")
142 this->HandleDirectContent(this->Target, content, prepend, system);
144 if (scope == "INTERFACE" || scope == "PUBLIC")
146 this->HandleInterfaceContent(this->Target, content, prepend, system);
150 //----------------------------------------------------------------------------
151 void cmTargetPropCommandBase::HandleInterfaceContent(cmTarget *tgt,
152 const std::vector<std::string> &content,
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
162 tgt->SetProperty(propName.c_str(), totalContent.c_str());
166 tgt->AppendProperty(("INTERFACE_" + this->Property).c_str(),
167 this->Join(content).c_str());