cmGlobalXCodeGenerator.h 11 KB

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