cmGlobalXCodeGenerator.h 11 KB

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