cmGlobalXCodeGenerator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 UseEffectivePlatformName(cmMakefile* mf) const CM_OVERRIDE;
  76. bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) CM_OVERRIDE;
  77. void AppendFlag(std::string& flags, std::string const& flag);
  78. protected:
  79. void AddExtraIDETargets() CM_OVERRIDE;
  80. void Generate() CM_OVERRIDE;
  81. private:
  82. cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
  83. cmSourceGroup* sg);
  84. cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name);
  85. bool CreateGroups(std::vector<cmLocalGenerator*>& generators);
  86. std::string XCodeEscapePath(const std::string& p);
  87. std::string RelativeToSource(const char* p);
  88. std::string RelativeToBinary(const char* p);
  89. std::string ConvertToRelativeForMake(const char* p);
  90. void CreateCustomCommands(cmXCodeObject* buildPhases,
  91. cmXCodeObject* sourceBuildPhase,
  92. cmXCodeObject* headerBuildPhase,
  93. cmXCodeObject* resourceBuildPhase,
  94. std::vector<cmXCodeObject*> contentBuildPhases,
  95. cmXCodeObject* frameworkBuildPhase,
  96. cmGeneratorTarget* gtgt);
  97. std::string ComputeInfoPListLocation(cmGeneratorTarget* target);
  98. void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  99. cmGeneratorTarget* target,
  100. std::vector<cmCustomCommand> const& commands,
  101. const char* commandFileName);
  102. void CreateCustomRulesMakefile(const char* makefileBasename,
  103. cmGeneratorTarget* target,
  104. std::vector<cmCustomCommand> const& commands,
  105. const std::string& configName);
  106. cmXCodeObject* FindXCodeTarget(const cmGeneratorTarget*);
  107. std::string GetOrCreateId(const std::string& name, const std::string& id);
  108. // create cmXCodeObject from these functions so that memory can be managed
  109. // correctly. All objects created are stored in this->XCodeObjects.
  110. cmXCodeObject* CreateObject(cmXCodeObject::PBXType ptype);
  111. cmXCodeObject* CreateObject(cmXCodeObject::Type type);
  112. cmXCodeObject* CreateString(const std::string& s);
  113. cmXCodeObject* CreateObjectReference(cmXCodeObject*);
  114. cmXCodeObject* CreateFlatClone(cmXCodeObject*);
  115. cmXCodeObject* CreateXCodeTarget(cmGeneratorTarget* gtgt,
  116. cmXCodeObject* buildPhases);
  117. void ForceLinkerLanguages() CM_OVERRIDE;
  118. void ForceLinkerLanguage(cmGeneratorTarget* gtgt);
  119. const char* GetTargetLinkFlagsVar(const cmGeneratorTarget* target) const;
  120. const char* GetTargetFileType(cmGeneratorTarget* target);
  121. const char* GetTargetProductType(cmGeneratorTarget* target);
  122. std::string AddConfigurations(cmXCodeObject* target,
  123. cmGeneratorTarget* gtgt);
  124. void AppendOrAddBuildSetting(cmXCodeObject* settings, const char* attr,
  125. const char* value);
  126. void AppendBuildSettingAttribute(cmXCodeObject* target, const char* attr,
  127. const char* value,
  128. const std::string& configName);
  129. cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget* gtgt);
  130. void AddDependAndLinkInformation(cmXCodeObject* target);
  131. void CreateBuildSettings(cmGeneratorTarget* gtgt,
  132. cmXCodeObject* buildSettings,
  133. const std::string& buildType);
  134. std::string ExtractFlag(const char* flag, std::string& flags);
  135. std::string ExtractFlagRegex(const char* exp, int matchIndex,
  136. std::string& flags);
  137. void FilterConfigurationAttribute(std::string const& configName,
  138. std::string& attribute);
  139. void SortXCodeObjects();
  140. // delete all objects in the this->XCodeObjects vector.
  141. void ClearXCodeObjects();
  142. bool CreateXCodeObjects(cmLocalGenerator* root,
  143. std::vector<cmLocalGenerator*>& generators);
  144. void OutputXCodeProject(cmLocalGenerator* root,
  145. std::vector<cmLocalGenerator*>& generators);
  146. void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
  147. std::vector<cmLocalGenerator*>& generators);
  148. cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string& fullpath,
  149. cmGeneratorTarget* target,
  150. const std::string& lang,
  151. cmSourceFile* sf);
  152. cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string& fullpath,
  153. cmGeneratorTarget* target,
  154. const std::string& lang,
  155. cmSourceFile* sf);
  156. cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf,
  157. cmGeneratorTarget* target);
  158. cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf,
  159. cmGeneratorTarget* gtgt);
  160. bool CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
  161. bool IsHeaderFile(cmSourceFile*);
  162. void AddDependTarget(cmXCodeObject* target, cmXCodeObject* dependTarget);
  163. void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
  164. bool SpecialTargetEmitted(std::string const& tname);
  165. void SetGenerationRoot(cmLocalGenerator* root);
  166. void AddExtraTargets(cmLocalGenerator* root,
  167. std::vector<cmLocalGenerator*>& gens);
  168. cmXCodeObject* CreateBuildPhase(const char* name, const char* name2,
  169. cmGeneratorTarget* target,
  170. const std::vector<cmCustomCommand>&);
  171. void CreateReRunCMakeFile(cmLocalGenerator* root,
  172. std::vector<cmLocalGenerator*> const& gens);
  173. std::string LookupFlags(const std::string& varNamePrefix,
  174. const std::string& varNameLang,
  175. const std::string& varNameSuffix,
  176. const std::string& default_flags);
  177. class Factory;
  178. class BuildObjectListOrString;
  179. friend class BuildObjectListOrString;
  180. void AppendDefines(BuildObjectListOrString& defs, const char* defines_list,
  181. bool dflag = false);
  182. void AppendDefines(BuildObjectListOrString& defs,
  183. std::vector<std::string> const& defines,
  184. bool dflag = false);
  185. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE;
  186. protected:
  187. const char* GetInstallTargetName() const CM_OVERRIDE { return "install"; }
  188. const char* GetPackageTargetName() const CM_OVERRIDE { return "package"; }
  189. unsigned int XcodeVersion;
  190. std::string VersionString;
  191. std::set<std::string> XCodeObjectIDs;
  192. std::vector<cmXCodeObject*> XCodeObjects;
  193. cmXCodeObject* RootObject;
  194. private:
  195. std::string const& GetXcodeBuildCommand();
  196. std::string FindXcodeBuildCommand();
  197. std::string XcodeBuildCommand;
  198. bool XcodeBuildCommandInitialized;
  199. void PrintCompilerAdvice(std::ostream&, std::string const&,
  200. const char*) const CM_OVERRIDE
  201. {
  202. }
  203. std::string GetObjectsNormalDirectory(const std::string& projName,
  204. const std::string& configName,
  205. const cmGeneratorTarget* t) const;
  206. void addObject(cmXCodeObject* obj);
  207. std::string PostBuildMakeTarget(std::string const& tName,
  208. std::string const& configName);
  209. cmXCodeObject* MainGroupChildren;
  210. cmXCodeObject* SourcesGroupChildren;
  211. cmXCodeObject* ResourcesGroupChildren;
  212. cmMakefile* CurrentMakefile;
  213. cmLocalGenerator* CurrentLocalGenerator;
  214. std::vector<std::string> CurrentConfigurationTypes;
  215. std::string CurrentReRunCMakeMakefile;
  216. std::string CurrentXCodeHackMakefile;
  217. std::string CurrentProject;
  218. std::set<std::string> TargetDoneSet;
  219. std::vector<std::string> ProjectSourceDirectoryComponents;
  220. std::vector<std::string> ProjectOutputDirectoryComponents;
  221. std::map<std::string, cmXCodeObject*> GroupMap;
  222. std::map<std::string, cmXCodeObject*> GroupNameMap;
  223. std::map<std::string, cmXCodeObject*> TargetGroup;
  224. std::map<std::string, cmXCodeObject*> FileRefs;
  225. std::map<cmGeneratorTarget const*, cmXCodeObject*> XCodeObjectMap;
  226. std::vector<std::string> Architectures;
  227. std::string GeneratorToolset;
  228. };
  229. #endif