cmGlobalXCodeGenerator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGlobalXCodeGenerator_h
  11. #define cmGlobalXCodeGenerator_h
  12. #include "cmGlobalGenerator.h"
  13. #include "cmCustomCommand.h"
  14. #include "cmXCodeObject.h"
  15. class cmGlobalGeneratorFactory;
  16. class cmSourceFile;
  17. class cmSourceGroup;
  18. /** \class cmGlobalXCodeGenerator
  19. * \brief Write a Unix makefiles.
  20. *
  21. * cmGlobalXCodeGenerator manages UNIX build process for a tree
  22. */
  23. class cmGlobalXCodeGenerator : public cmGlobalGenerator
  24. {
  25. public:
  26. cmGlobalXCodeGenerator(cmake* cm, std::string const& version);
  27. static cmGlobalGeneratorFactory* NewFactory();
  28. ///! Get the name for the generator.
  29. virtual std::string GetName() const
  30. {
  31. return cmGlobalXCodeGenerator::GetActualName();
  32. }
  33. static std::string GetActualName() { return "Xcode"; }
  34. /** Get the documentation entry for this generator. */
  35. static void GetDocumentation(cmDocumentationEntry& entry);
  36. ///! Create a local generator appropriate to this Global Generator
  37. virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
  38. /**
  39. * Try to determine system information such as shared library
  40. * extension, pthreads, byte order etc.
  41. */
  42. virtual void EnableLanguage(std::vector<std::string> const& languages,
  43. cmMakefile*, bool optional);
  44. /**
  45. * Try running cmake and building a file. This is used for dynalically
  46. * loaded commands, not as part of the usual build process.
  47. */
  48. virtual void GenerateBuildCommand(
  49. std::vector<std::string>& makeCommand, const std::string& makeProgram,
  50. const std::string& projectName, const std::string& projectDir,
  51. const std::string& targetName, const std::string& config, bool fast,
  52. bool verbose,
  53. std::vector<std::string> const& makeOptions = std::vector<std::string>());
  54. /** Append the subdirectory for the given configuration. */
  55. virtual void AppendDirectoryForConfig(const std::string& prefix,
  56. const std::string& config,
  57. const std::string& suffix,
  58. std::string& dir);
  59. virtual void FindMakeProgram(cmMakefile*);
  60. ///! What is the configurations directory variable called?
  61. virtual const char* GetCMakeCFGIntDir() const;
  62. ///! expand CFGIntDir
  63. virtual std::string ExpandCFGIntDir(const std::string& str,
  64. const std::string& config) const;
  65. void SetCurrentLocalGenerator(cmLocalGenerator*);
  66. /** Return true if the generated build tree may contain multiple builds.
  67. i.e. "Can I build Debug and Release in the same tree?" */
  68. virtual bool IsMultiConfig() const;
  69. virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
  70. void AppendFlag(std::string& flags, std::string const& flag);
  71. protected:
  72. virtual void AddExtraIDETargets();
  73. virtual void Generate();
  74. private:
  75. cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
  76. cmSourceGroup* sg);
  77. cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name);
  78. bool CreateGroups(std::vector<cmLocalGenerator*>& generators);
  79. std::string XCodeEscapePath(const std::string& p);
  80. std::string RelativeToSource(const char* p);
  81. std::string RelativeToBinary(const char* p);
  82. std::string ConvertToRelativeForMake(const char* p);
  83. void CreateCustomCommands(cmXCodeObject* buildPhases,
  84. cmXCodeObject* sourceBuildPhase,
  85. cmXCodeObject* headerBuildPhase,
  86. cmXCodeObject* resourceBuildPhase,
  87. std::vector<cmXCodeObject*> contentBuildPhases,
  88. cmXCodeObject* frameworkBuildPhase,
  89. cmGeneratorTarget* gtgt);
  90. std::string ComputeInfoPListLocation(cmGeneratorTarget* target);
  91. void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  92. cmGeneratorTarget* target,
  93. std::vector<cmCustomCommand> const& commands,
  94. const char* commandFileName);
  95. void CreateCustomRulesMakefile(const char* makefileBasename,
  96. cmGeneratorTarget* target,
  97. std::vector<cmCustomCommand> const& commands,
  98. const std::string& configName);
  99. cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget*);
  100. std::string GetOrCreateId(const std::string& name, const std::string& id);
  101. // create cmXCodeObject from these functions so that memory can be managed
  102. // correctly. All objects created are stored in this->XCodeObjects.
  103. cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
  104. cmXCodeObject* CreateObject(cmXCodeObject::Type type);
  105. cmXCodeObject* CreateString(const std::string& s);
  106. cmXCodeObject* CreateObjectReference(cmXCodeObject*);
  107. cmXCodeObject* CreateFlatClone(cmXCodeObject*);
  108. cmXCodeObject* CreateXCodeTarget(cmGeneratorTarget* gtgt,
  109. cmXCodeObject* buildPhases);
  110. void ForceLinkerLanguages();
  111. void ForceLinkerLanguage(cmGeneratorTarget* gtgt);
  112. const char* GetTargetLinkFlagsVar(const cmGeneratorTarget* target) const;
  113. const char* GetTargetFileType(cmGeneratorTarget* target);
  114. const char* GetTargetProductType(cmGeneratorTarget* target);
  115. std::string AddConfigurations(cmXCodeObject* target,
  116. cmGeneratorTarget* gtgt);
  117. void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
  118. const char* value);
  119. void AppendBuildSettingAttribute(cmXCodeObject* target, const char* attr,
  120. const char* value,
  121. const std::string& configName);
  122. cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget* gtgt);
  123. void AddDependAndLinkInformation(cmXCodeObject* target);
  124. void CreateBuildSettings(cmGeneratorTarget* gtgt,
  125. cmXCodeObject* buildSettings,
  126. const std::string& buildType);
  127. std::string ExtractFlag(const char* flag, std::string& flags);
  128. std::string ExtractFlagRegex(const char* exp, int matchIndex,
  129. std::string& flags);
  130. void FilterConfigurationAttribute(std::string const& configName,
  131. std::string& attribute);
  132. void SortXCodeObjects();
  133. // delete all objects in the this->XCodeObjects vector.
  134. void ClearXCodeObjects();
  135. bool CreateXCodeObjects(cmLocalGenerator* root,
  136. std::vector<cmLocalGenerator*>& generators);
  137. void OutputXCodeProject(cmLocalGenerator* root,
  138. std::vector<cmLocalGenerator*>& generators);
  139. void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
  140. std::vector<cmLocalGenerator*>& generators);
  141. cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string& fullpath,
  142. cmGeneratorTarget* target,
  143. const std::string& lang,
  144. cmSourceFile* sf);
  145. cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string& fullpath,
  146. cmGeneratorTarget* target,
  147. const std::string& lang,
  148. cmSourceFile* sf);
  149. cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
  150. cmGeneratorTarget* target);
  151. cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf,
  152. cmGeneratorTarget* gtgt);
  153. bool CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
  154. bool IsHeaderFile(cmSourceFile*);
  155. void AddDependTarget(cmXCodeObject* target, cmXCodeObject* dependTarget);
  156. void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
  157. bool SpecialTargetEmitted(std::string const& tname);
  158. void SetGenerationRoot(cmLocalGenerator* root);
  159. void AddExtraTargets(cmLocalGenerator* root,
  160. std::vector<cmLocalGenerator*>& gens);
  161. cmXCodeObject* CreateBuildPhase(const char* name, const char* name2,
  162. cmGeneratorTarget* target,
  163. const std::vector<cmCustomCommand>&);
  164. void CreateReRunCMakeFile(cmLocalGenerator* root,
  165. std::vector<cmLocalGenerator*> const& gens);
  166. std::string LookupFlags(const std::string& varNamePrefix,
  167. const std::string& varNameLang,
  168. const std::string& varNameSuffix,
  169. const std::string& default_flags);
  170. class Factory;
  171. class BuildObjectListOrString;
  172. friend class BuildObjectListOrString;
  173. void AppendDefines(BuildObjectListOrString& defs, const char* defines_list,
  174. bool dflag = false);
  175. void AppendDefines(BuildObjectListOrString& defs,
  176. std::vector<std::string> const& defines,
  177. bool dflag = false);
  178. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  179. protected:
  180. virtual const char* GetInstallTargetName() const { return "install"; }
  181. virtual const char* GetPackageTargetName() const { return "package"; }
  182. unsigned int XcodeVersion;
  183. std::string VersionString;
  184. std::set<std::string> XCodeObjectIDs;
  185. std::vector<cmXCodeObject*> XCodeObjects;
  186. cmXCodeObject* RootObject;
  187. private:
  188. std::string const& GetXcodeBuildCommand();
  189. std::string FindXcodeBuildCommand();
  190. std::string XcodeBuildCommand;
  191. bool XcodeBuildCommandInitialized;
  192. void PrintCompilerAdvice(std::ostream&, std::string const&,
  193. const char*) const
  194. {
  195. }
  196. std::string GetObjectsNormalDirectory(const std::string& projName,
  197. const std::string& configName,
  198. const cmGeneratorTarget* t) const;
  199. void addObject(cmXCodeObject* obj);
  200. std::string PostBuildMakeTarget(std::string const& tName,
  201. std::string const& configName);
  202. cmXCodeObject* MainGroupChildren;
  203. cmXCodeObject* SourcesGroupChildren;
  204. cmXCodeObject* ResourcesGroupChildren;
  205. cmMakefile* CurrentMakefile;
  206. cmLocalGenerator* CurrentLocalGenerator;
  207. std::vector<std::string> CurrentConfigurationTypes;
  208. std::string CurrentReRunCMakeMakefile;
  209. std::string CurrentXCodeHackMakefile;
  210. std::string CurrentProject;
  211. std::set<std::string> TargetDoneSet;
  212. std::vector<std::string> ProjectSourceDirectoryComponents;
  213. std::vector<std::string> ProjectOutputDirectoryComponents;
  214. std::map<std::string, cmXCodeObject*> GroupMap;
  215. std::map<std::string, cmXCodeObject*> GroupNameMap;
  216. std::map<std::string, cmXCodeObject*> TargetGroup;
  217. std::map<std::string, cmXCodeObject*> FileRefs;
  218. std::map<cmGeneratorTarget const*, cmXCodeObject*> XCodeObjectMap;
  219. std::vector<std::string> Architectures;
  220. std::string GeneratorToolset;
  221. };
  222. #endif