cmGlobalXCodeGenerator.h 11 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Bill Hoffman's avatar
Bill Hoffman committed
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
Bill Hoffman's avatar
Bill Hoffman committed
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
Bill Hoffman's avatar
Bill Hoffman committed
12
13
14
15
16
#ifndef cmGlobalXCodeGenerator_h
#define cmGlobalXCodeGenerator_h

#include "cmGlobalGenerator.h"
#include "cmXCodeObject.h"
17
#include "cmCustomCommand.h"
18
class cmGlobalGeneratorFactory;
Bill Hoffman's avatar
Bill Hoffman committed
19
class cmTarget;
Bill Hoffman's avatar
Bill Hoffman committed
20
class cmSourceFile;
Bill Hoffman's avatar
Bill Hoffman committed
21
22
class cmSourceGroup;

Bill Hoffman's avatar
Bill Hoffman committed
23
24
25
26
27
28
29
30
31

/** \class cmGlobalXCodeGenerator
 * \brief Write a Unix makefiles.
 *
 * cmGlobalXCodeGenerator manages UNIX build process for a tree
 */
class cmGlobalXCodeGenerator : public cmGlobalGenerator
{
public:
32
  cmGlobalXCodeGenerator(std::string const& version);
33
  static cmGlobalGeneratorFactory* NewFactory();
Bill Hoffman's avatar
Bill Hoffman committed
34

Bill Hoffman's avatar
Bill Hoffman committed
35
  ///! Get the name for the generator.
36
  virtual std::string GetName() const {
Bill Hoffman's avatar
Bill Hoffman committed
37
    return cmGlobalXCodeGenerator::GetActualName();}
38
  static std::string GetActualName() {return "Xcode";}
Bill Hoffman's avatar
Bill Hoffman committed
39
40

  /** Get the documentation entry for this generator.  */
41
  static void GetDocumentation(cmDocumentationEntry& entry);
42

Bill Hoffman's avatar
Bill Hoffman committed
43
44
45
46
47
  ///! Create a local generator appropriate to this Global Generator
  virtual cmLocalGenerator *CreateLocalGenerator();

  /**
   * Try to determine system infomation such as shared library
48
   * extension, pthreads, byte order etc.
Bill Hoffman's avatar
Bill Hoffman committed
49
   */
50
  virtual void EnableLanguage(std::vector<std::string>const& languages,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
51
                              cmMakefile *, bool optional);
Bill Hoffman's avatar
Bill Hoffman committed
52
53
54
55
  /**
   * Try running cmake and building a file. This is used for dynalically
   * loaded commands, not as part of the usual build process.
   */
56
57
  virtual void GenerateBuildCommand(
    std::vector<std::string>& makeCommand,
58
    const std::string& makeProgram,
59
    const std::string& projectName,
60
    const std::string& projectDir,
61
    const std::string& targetName,
62
    const std::string& config,
63
64
65
    bool fast,
    std::vector<std::string> const& makeOptions = std::vector<std::string>()
    );
Bill Hoffman's avatar
Bill Hoffman committed
66
67
68
69

  /**
   * Generate the all required files for building this project/tree. This
   * basically creates a series of LocalGenerators for each directory and
70
   * requests that they Generate.
Bill Hoffman's avatar
Bill Hoffman committed
71
72
73
   */
  virtual void Generate();

74
  /** Append the subdirectory for the given configuration.  */
75
  virtual void AppendDirectoryForConfig(const std::string& prefix,
76
                                        const std::string& config,
77
                                        const std::string& suffix,
78
                                        std::string& dir);
79

80
  ///! What is the configurations directory variable called?
81
  virtual const char* GetCMakeCFGIntDir() const;
82
83
84
  ///! expand CFGIntDir
  virtual std::string ExpandCFGIntDir(const std::string& str,
                                      const std::string& config) const;
85

86
  void SetCurrentLocalGenerator(cmLocalGenerator*);
87
88
89
90
91

  /** Return true if the generated build tree may contain multiple builds.
      i.e. "Can I build Debug and Release in the same tree?" */
  virtual bool IsMultiConfig();

92
  virtual bool SetGeneratorToolset(std::string const& ts);
93
  void AppendFlag(std::string& flags, std::string const& flag);
94
private:
Bill Hoffman's avatar
Bill Hoffman committed
95
96
  cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
                                     cmSourceGroup* sg);
97
  cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent,
98
                                std::string name);
Bill Hoffman's avatar
Bill Hoffman committed
99
100
101
  void CreateGroups(cmLocalGenerator* root,
                    std::vector<cmLocalGenerator*>&
                    generators);
102
  std::string XCodeEscapePath(const char* p);
103
104
  std::string RelativeToSource(const char* p);
  std::string RelativeToBinary(const char* p);
105
106
  std::string ConvertToRelativeForXCode(const char* p);
  std::string ConvertToRelativeForMake(const char* p);
107
108
109
  void CreateCustomCommands(cmXCodeObject* buildPhases,
                            cmXCodeObject* sourceBuildPhase,
                            cmXCodeObject* headerBuildPhase,
110
111
                            cmXCodeObject* resourceBuildPhase,
                            std::vector<cmXCodeObject*> contentBuildPhases,
112
113
                            cmXCodeObject* frameworkBuildPhase,
                            cmTarget& cmtarget);
114

115
116
  std::string ComputeInfoPListLocation(cmTarget& target);

117
118
  void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
                               cmTarget& target,
119
                               std::vector<cmCustomCommand>
120
121
                               const & commands,
                               const char* commandFileName);
122
123

  void CreateCustomRulesMakefile(const char* makefileBasename,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
124
                                 cmTarget& target,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
125
                                 std::vector<cmCustomCommand> const & commands,
126
                                 const std::string& configName,
127
                                 bool& haveMultipleOutputPairs);
128

129
  cmXCodeObject* FindXCodeTarget(cmTarget const*);
130
  std::string GetOrCreateId(const std::string& name, const std::string& id);
131

132
  // create cmXCodeObject from these functions so that memory can be managed
Ken Martin's avatar
Ken Martin committed
133
  // correctly.  All objects created are stored in this->XCodeObjects.
Bill Hoffman's avatar
Bill Hoffman committed
134
135
  cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
  cmXCodeObject* CreateObject(cmXCodeObject::Type type);
136
  cmXCodeObject* CreateString(const std::string& s);
Bill Hoffman's avatar
Bill Hoffman committed
137
  cmXCodeObject* CreateObjectReference(cmXCodeObject*);
Bill Hoffman's avatar
Bill Hoffman committed
138
139
  cmXCodeObject* CreateXCodeTarget(cmTarget& target,
                                   cmXCodeObject* buildPhases);
Brad King's avatar
Brad King committed
140
141
  void ForceLinkerLanguages();
  void ForceLinkerLanguage(cmTarget& cmtarget);
142
143
  const char* GetTargetFileType(cmTarget& cmtarget);
  const char* GetTargetProductType(cmTarget& cmtarget);
144
  std::string AddConfigurations(cmXCodeObject* target, cmTarget& cmtarget);
145
  void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
146
                               const char* value);
147
  void AppendBuildSettingAttribute(cmXCodeObject* target, const char* attr,
148
149
                                   const char* value,
                                   const std::string& configName);
150
151
  cmXCodeObject* CreateUtilityTarget(cmTarget& target);
  void AddDependAndLinkInformation(cmXCodeObject* target);
Bill Hoffman's avatar
Bill Hoffman committed
152
153
  void CreateBuildSettings(cmTarget& target,
                           cmXCodeObject* buildSettings,
154
                           const std::string& buildType);
155
  std::string ExtractFlag(const char* flag, std::string& flags);
Ken Martin's avatar
Ken Martin committed
156
  // delete all objects in the this->XCodeObjects vector.
Bill Hoffman's avatar
Bill Hoffman committed
157
158
159
160
161
  void ClearXCodeObjects();
  void CreateXCodeObjects(cmLocalGenerator* root,
                          std::vector<cmLocalGenerator*>& generators);
  void OutputXCodeProject(cmLocalGenerator* root,
                          std::vector<cmLocalGenerator*>& generators);
162
163
  void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
                         std::vector<cmLocalGenerator*>& generators);
164
165
  cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath,
                                                  cmTarget& cmtarget,
166
167
                                                  const std::string &lang,
                                                  cmSourceFile* sf);
168
169
  cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath,
                                               cmTarget& cmtarget,
170
171
                                               const std::string &lang,
                                               cmSourceFile* sf);
Brad King's avatar
Brad King committed
172
173
  cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
                                          cmTarget& cmtarget);
174
  cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen,
175
176
                                       cmSourceFile* sf,
                                       cmTarget& cmtarget);
177
  void CreateXCodeTargets(cmLocalGenerator* gen,
Ken Martin's avatar
Ken Martin committed
178
                          std::vector<cmXCodeObject*>&);
179
  bool IsHeaderFile(cmSourceFile*);
180
181
  void AddDependTarget(cmXCodeObject* target,
                       cmXCodeObject* dependTarget);
182
  void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
183
  bool SpecialTargetEmitted(std::string const& tname);
184
  void SetGenerationRoot(cmLocalGenerator* root);
185
  void AddExtraTargets(cmLocalGenerator* root,
186
                       std::vector<cmLocalGenerator*>& gens);
187
  cmXCodeObject* CreateBuildPhase(const char* name,
188
189
190
                                  const char* name2,
                                  cmTarget& cmtarget,
                                  const std::vector<cmCustomCommand>&);
191
192
  void CreateReRunCMakeFile(cmLocalGenerator* root,
                            std::vector<cmLocalGenerator*> const& gens);
193

194
195
196
197
  std::string LookupFlags(const std::string& varNamePrefix,
                          const std::string& varNameLang,
                          const std::string& varNameSuffix,
                          const std::string& default_flags);
198

199
  class Factory;
200
201
202
203
  class BuildObjectListOrString;
  friend class BuildObjectListOrString;

  void AppendDefines(BuildObjectListOrString& defs, const char* defines_list,
204
                     bool dflag = false);
205
206
207
  void AppendDefines(BuildObjectListOrString& defs,
                     std::vector<std::string> const& defines,
                     bool dflag = false);
208

209
  void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
210
protected:
211
212
  virtual const char* GetInstallTargetName() const { return "install"; }
  virtual const char* GetPackageTargetName() const { return "package"; }
213

214
215
  unsigned int XcodeVersion;
  std::string VersionString;
216
  std::set<std::string> XCodeObjectIDs;
Ken Martin's avatar
Ken Martin committed
217
218
  std::vector<cmXCodeObject*> XCodeObjects;
  cmXCodeObject* RootObject;
219
private:
220
221
  void PrintCompilerAdvice(std::ostream&, std::string const&,
                           const char*) const {}
222

223
224
225
226
227
  std::string GetObjectsNormalDirectory(
    const std::string &projName,
    const std::string &configName,
    const cmTarget *t) const;

228
  void addObject(cmXCodeObject *obj);
229
230
  std::string PostBuildMakeTarget(std::string const& tName,
                                  std::string const& configName);
Ken Martin's avatar
Ken Martin committed
231
232
  cmXCodeObject* MainGroupChildren;
  cmXCodeObject* SourcesGroupChildren;
233
  cmXCodeObject* ResourcesGroupChildren;
Ken Martin's avatar
Ken Martin committed
234
235
236
237
238
239
  cmMakefile* CurrentMakefile;
  cmLocalGenerator* CurrentLocalGenerator;
  std::vector<std::string> CurrentConfigurationTypes;
  std::string CurrentReRunCMakeMakefile;
  std::string CurrentXCodeHackMakefile;
  std::string CurrentProject;
240
  std::set<std::string> TargetDoneSet;
Ken Martin's avatar
Ken Martin committed
241
  std::vector<std::string> CurrentOutputDirectoryComponents;
242
  std::vector<std::string> ProjectSourceDirectoryComponents;
Ken Martin's avatar
Ken Martin committed
243
  std::vector<std::string> ProjectOutputDirectoryComponents;
244
245
246
247
  std::map<std::string, cmXCodeObject* > GroupMap;
  std::map<std::string, cmXCodeObject* > GroupNameMap;
  std::map<std::string, cmXCodeObject* > TargetGroup;
  std::map<std::string, cmXCodeObject* > FileRefs;
248
  std::vector<std::string> Architectures;
249
  std::string GeneratorToolset;
Bill Hoffman's avatar
Bill Hoffman committed
250
251
252
};

#endif