~ubuntu-branches/ubuntu/trusty/cmake3/trusty-updates

« back to all changes in this revision

Viewing changes to Source/cmXCodeObject.cxx

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2017-02-23 17:55:24 UTC
  • Revision ID: package-import@ubuntu.com-20170223175524-5nh7s4pu97fsa0t7
Tags: upstream-3.5.1
ImportĀ upstreamĀ versionĀ 3.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "cmXCodeObject.h"
 
13
#include "cmSystemTools.h"
 
14
 
 
15
#include <CoreFoundation/CoreFoundation.h> // CFUUIDCreate
 
16
 
 
17
//----------------------------------------------------------------------------
 
18
const char* cmXCodeObject::PBXTypeNames[] = {
 
19
    "PBXGroup", "PBXBuildStyle", "PBXProject", "PBXHeadersBuildPhase",
 
20
    "PBXSourcesBuildPhase", "PBXFrameworksBuildPhase", "PBXNativeTarget",
 
21
    "PBXFileReference", "PBXBuildFile", "PBXContainerItemProxy",
 
22
    "PBXTargetDependency", "PBXShellScriptBuildPhase",
 
23
    "PBXResourcesBuildPhase", "PBXApplicationReference",
 
24
    "PBXExecutableFileReference", "PBXLibraryReference", "PBXToolTarget",
 
25
    "PBXLibraryTarget", "PBXAggregateTarget", "XCBuildConfiguration",
 
26
    "XCConfigurationList",
 
27
    "PBXCopyFilesBuildPhase",
 
28
    "None"
 
29
  };
 
30
 
 
31
//----------------------------------------------------------------------------
 
32
cmXCodeObject::~cmXCodeObject()
 
33
{
 
34
  this->Version = 15;
 
35
}
 
36
 
 
37
//----------------------------------------------------------------------------
 
38
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
 
39
{
 
40
  this->Version = 15;
 
41
  this->Target = 0;
 
42
  this->Object =0;
 
43
 
 
44
  this->IsA = ptype;
 
45
 
 
46
  if(type == OBJECT)
 
47
    {
 
48
    // Set the Id of an Xcode object to a unique string for each instance.
 
49
    // However the Xcode user file references certain Ids: for those cases,
 
50
    // override the generated Id using SetId().
 
51
    //
 
52
    char cUuid[40] = {0};
 
53
    CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
 
54
    CFStringRef s = CFUUIDCreateString(kCFAllocatorDefault, uuid);
 
55
    CFStringGetCString(s, cUuid, sizeof(cUuid), kCFStringEncodingUTF8);
 
56
    this->Id = cUuid;
 
57
    CFRelease(s);
 
58
    CFRelease(uuid);
 
59
    }
 
60
  else
 
61
    {
 
62
    this->Id =
 
63
      "Temporary cmake object, should not be referred to in Xcode file";
 
64
    }
 
65
 
 
66
  cmSystemTools::ReplaceString(this->Id, "-", "");
 
67
  if(this->Id.size() > 24)
 
68
    {
 
69
    this->Id = this->Id.substr(0, 24);
 
70
    }
 
71
 
 
72
  this->TypeValue = type;
 
73
  if(this->TypeValue == OBJECT)
 
74
    {
 
75
    this->AddAttribute("isa", 0);
 
76
    }
 
77
}
 
78
 
 
79
//----------------------------------------------------------------------------
 
80
void cmXCodeObject::Indent(int level, std::ostream& out)
 
81
{
 
82
  while(level)
 
83
    {
 
84
    out << "\t";
 
85
    level--;
 
86
    }
 
87
}
 
88
 
 
89
//----------------------------------------------------------------------------
 
90
void cmXCodeObject::Print(std::ostream& out)
 
91
{
 
92
  std::string separator = "\n";
 
93
  int indentFactor = 1;
 
94
  cmXCodeObject::Indent(2*indentFactor, out);
 
95
  if(this->Version > 15
 
96
     && (this->IsA == PBXFileReference || this->IsA == PBXBuildFile))
 
97
    {
 
98
    separator = " ";
 
99
    indentFactor = 0;
 
100
    }
 
101
  out << this->Id;
 
102
  this->PrintComment(out);
 
103
  out << " = {";
 
104
  if(separator == "\n")
 
105
    {
 
106
    out << separator;
 
107
    }
 
108
  std::map<std::string, cmXCodeObject*>::iterator i;
 
109
  cmXCodeObject::Indent(3*indentFactor, out);
 
110
  out << "isa = " << PBXTypeNames[this->IsA]  << ";" << separator;
 
111
  for(i = this->ObjectAttributes.begin();
 
112
      i != this->ObjectAttributes.end(); ++i)
 
113
    {
 
114
    cmXCodeObject* object = i->second;
 
115
    if(i->first != "isa")
 
116
      {
 
117
      cmXCodeObject::Indent(3*indentFactor, out);
 
118
      }
 
119
    else
 
120
      {
 
121
      continue;
 
122
      }
 
123
    if(object->TypeValue == OBJECT_LIST)
 
124
      {
 
125
      out << i->first << " = (" << separator;
 
126
      for(unsigned int k = 0; k < i->second->List.size(); k++)
 
127
        {
 
128
        cmXCodeObject::Indent(4*indentFactor, out);
 
129
        out << i->second->List[k]->Id;
 
130
        i->second->List[k]->PrintComment(out);
 
131
        out << "," << separator;
 
132
        }
 
133
      cmXCodeObject::Indent(3*indentFactor, out);
 
134
      out << ");" << separator;
 
135
      }
 
136
    else if(object->TypeValue == ATTRIBUTE_GROUP)
 
137
      {
 
138
      std::map<std::string, cmXCodeObject*>::iterator j;
 
139
      out << i->first << " = {";
 
140
      if(separator == "\n")
 
141
        {
 
142
        out << separator;
 
143
        }
 
144
      for(j = object->ObjectAttributes.begin(); j !=
 
145
            object->ObjectAttributes.end(); ++j)
 
146
        {
 
147
        cmXCodeObject::Indent(4 *indentFactor, out);
 
148
 
 
149
        if(j->second->TypeValue == STRING)
 
150
          {
 
151
          cmXCodeObject::PrintString(out,j->first);
 
152
          out << " = ";
 
153
          j->second->PrintString(out);
 
154
          out << ";";
 
155
          }
 
156
        else if(j->second->TypeValue == OBJECT_LIST)
 
157
          {
 
158
          cmXCodeObject::PrintString(out,j->first);
 
159
          out << " = (";
 
160
          for(unsigned int k = 0; k < j->second->List.size(); k++)
 
161
            {
 
162
            if(j->second->List[k]->TypeValue == STRING)
 
163
              {
 
164
              j->second->List[k]->PrintString(out);
 
165
              out << ", ";
 
166
              }
 
167
            else
 
168
              {
 
169
              out << "List_" << k << "_TypeValue_IS_NOT_STRING, ";
 
170
              }
 
171
            }
 
172
          out << ");";
 
173
          }
 
174
        else
 
175
          {
 
176
          cmXCodeObject::PrintString(out,j->first);
 
177
          out << " = error_unexpected_TypeValue_" <<
 
178
            j->second->TypeValue << ";";
 
179
          }
 
180
 
 
181
        out << separator;
 
182
        }
 
183
      cmXCodeObject::Indent(3 *indentFactor, out);
 
184
      out << "};" << separator;
 
185
      }
 
186
    else if(object->TypeValue == OBJECT_REF)
 
187
      {
 
188
      cmXCodeObject::PrintString(out,i->first);
 
189
      out << " = " << object->Object->Id;
 
190
      if(object->Object->HasComment() && i->first != "remoteGlobalIDString")
 
191
        {
 
192
        object->Object->PrintComment(out);
 
193
        }
 
194
      out << ";" << separator;
 
195
      }
 
196
    else if(object->TypeValue == STRING)
 
197
      {
 
198
      cmXCodeObject::PrintString(out,i->first);
 
199
      out << " = ";
 
200
      object->PrintString(out);
 
201
      out << ";" << separator;
 
202
      }
 
203
    else
 
204
      {
 
205
      out << "what is this?? " << i->first << "\n";
 
206
      }
 
207
    }
 
208
  cmXCodeObject::Indent(2*indentFactor, out);
 
209
  out << "};\n";
 
210
}
 
211
 
 
212
//----------------------------------------------------------------------------
 
213
void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
 
214
                              std::ostream& out)
 
215
{
 
216
  cmXCodeObject::Indent(1, out);
 
217
  out << "objects = {\n";
 
218
  for(unsigned int i = 0; i < objs.size(); ++i)
 
219
    {
 
220
    if(objs[i]->TypeValue == OBJECT)
 
221
      {
 
222
      objs[i]->Print(out);
 
223
      }
 
224
    }
 
225
  cmXCodeObject::Indent(1, out);
 
226
  out << "};\n";
 
227
}
 
228
 
 
229
//----------------------------------------------------------------------------
 
230
void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
 
231
{
 
232
  this->ObjectAttributes = copy->ObjectAttributes;
 
233
  this->List = copy->List;
 
234
  this->String = copy->String;
 
235
  this->Object = copy->Object;
 
236
}
 
237
 
 
238
//----------------------------------------------------------------------------
 
239
void cmXCodeObject::PrintString(std::ostream& os,std::string String)
 
240
{
 
241
  // The string needs to be quoted if it contains any characters
 
242
  // considered special by the Xcode project file parser.
 
243
  bool needQuote =
 
244
    (String.empty() ||
 
245
     String.find("//") != String.npos ||
 
246
     String.find_first_not_of(
 
247
       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
248
       "abcdefghijklmnopqrstuvwxyz"
 
249
       "0123456789"
 
250
       "$_./") != String.npos);
 
251
  const char* quote = needQuote? "\"" : "";
 
252
 
 
253
  // Print the string, quoted and escaped as necessary.
 
254
  os << quote;
 
255
  for(std::string::const_iterator i = String.begin();
 
256
      i != String.end(); ++i)
 
257
    {
 
258
    if(*i == '"' || *i == '\\')
 
259
      {
 
260
      // Escape double-quotes and backslashes.
 
261
      os << '\\';
 
262
      }
 
263
    os << *i;
 
264
    }
 
265
  os << quote;
 
266
}
 
267
 
 
268
void cmXCodeObject::PrintString(std::ostream& os) const
 
269
{
 
270
  cmXCodeObject::PrintString(os,this->String);
 
271
}
 
272
 
 
273
//----------------------------------------------------------------------------
 
274
void cmXCodeObject::SetString(const std::string& s)
 
275
{
 
276
  this->String = s;
 
277
}