cmGlobalXCodeGenerator.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 "cmXCodeObject.h"
  14. #include "cmCustomCommand.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. return cmGlobalXCodeGenerator::GetActualName();}
  31. static std::string GetActualName() {return "Xcode";}
  32. /** Get the documentation entry for this generator. */
  33. static void GetDocumentation(cmDocumentationEntry& entry);
  34. ///! Create a local generator appropriate to this Global Generator
  35. virtual cmLocalGenerator *CreateLocalGenerator(cmMakefile *mf);
  36. /**
  37. * Try to determine system information such as shared library
  38. * extension, pthreads, byte order etc.
  39. */
  40. virtual void EnableLanguage(std::vector<std::string>const& languages,
  41. cmMakefile *, bool optional);
  42. /**
  43. * Try running cmake and building a file. This is used for dynalically
  44. * loaded commands, not as part of the usual build process.
  45. */
  46. virtual void GenerateBuildCommand(
  47. std::vector<std::string>& makeCommand,
  48. const std::string& makeProgram,
  49. const std::string& projectName,
  50. const std::string& projectDir,
  51. const std::string& targetName,
  52. const std::string& config,
  53. bool fast, bool verbose,
  54. std::vector<std::string> const& makeOptions = std::vector<std::string>()
  55. );
  56. /** Append the subdirectory for the given configuration. */
  57. virtual void AppendDirectoryForConfig(const std::string& prefix,
  58. const std::string& config,
  59. const std::string& suffix,
  60. std::string& dir);
  61. virtual void FindMakeProgram(cmMakefile*);
  62. ///! What is the configurations directory variable called?
  63. virtual const char* GetCMakeCFGIntDir() const;
  64. ///! expand CFGIntDir
  65. virtual std::string ExpandCFGIntDir(const std::string& str,
  66. const std::string& config) const;
  67. void SetCurrentLocalGenerator(cmLocalGenerator*);
  68. /** Return true if the generated build tree may contain multiple builds.
  69. i.e. "Can I build Debug and Release in the same tree?" */
  70. virtual bool IsMultiConfig();
  71. virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf);
  72. void AppendFlag(std::string& flags, std::string const& flag);
  73. protected:
  74. virtual void AddExtraIDETargets();
  75. virtual void Generate();
  76. private:
  77. cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
  78. cmSourceGroup* sg);
  79. cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent,
  80. std::string name);
  81. bool CreateGroups(cmLocalGenerator* root,
  82. std::vector<cmLocalGenerator*>&
  83. generators);
  84. std::string XCodeEscapePath(const std::string& p);
  85. std::string RelativeToSource(const char* p);
  86. std::string RelativeToBinary(const char* p);
  87. std::string ConvertToRelativeForMake(const char* p);
  88. void CreateCustomCommands(cmXCodeObject* buildPhases,
  89. cmXCodeObject* sourceBuildPhase,
  90. cmXCodeObject* headerBuildPhase,
  91. cmXCodeObject* resourceBuildPhase,
  92. std::vector<cmXCodeObject*> contentBuildPhases,
  93. cmXCodeObject* frameworkBuildPhase,
  94. cmGeneratorTarget *gtgt);
  95. std::string ComputeInfoPListLocation(cmGeneratorTarget *target);
  96. void AddCommandsToBuildPhase(cmXCodeObject* buildphase,
  97. cmGeneratorTarget *target,
  98. std::vector<cmCustomCommand>
  99. 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();
  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,
  158. cmSourceFile* sf,
  159. cmGeneratorTarget *gtgt);
  160. bool CreateXCodeTargets(cmLocalGenerator* gen,
  161. std::vector<cmXCodeObject*>&);
  162. bool IsHeaderFile(cmSourceFile*);
  163. void AddDependTarget(cmXCodeObject* target,
  164. cmXCodeObject* dependTarget);
  165. void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
  166. bool SpecialTargetEmitted(std::string const& tname);
  167. void SetGenerationRoot(cmLocalGenerator* root);
  168. void AddExtraTargets(cmLocalGenerator* root,
  169. std::vector<cmLocalGenerator*>& gens);
  170. cmXCodeObject* CreateBuildPhase(const char* name,
  171. const char* name2,
  172. cmGeneratorTarget *target,
  173. const std::vector<cmCustomCommand>&);
  174. void CreateReRunCMakeFile(cmLocalGenerator* root,
  175. std::vector<cmLocalGenerator*> const& gens);
  176. std::string LookupFlags(const std::string& varNamePrefix,
  177. const std::string& varNameLang,
  178. const std::string& varNameSuffix,
  179. const std::string& default_flags);
  180. class Factory;
  181. class BuildObjectListOrString;
  182. friend class BuildObjectListOrString;
  183. void AppendDefines(BuildObjectListOrString& defs, const char* defines_list,
  184. bool dflag = false);
  185. void AppendDefines(BuildObjectListOrString& defs,
  186. std::vector<std::string> const& defines,
  187. bool dflag = false);
  188. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  189. protected:
  190. virtual const char* GetInstallTargetName() const { return "install"; }
  191. virtual const char* GetPackageTargetName() const { return "package"; }
  192. unsigned int XcodeVersion;
  193. std::string VersionString;
  194. std::set<std::string> XCodeObjectIDs;
  195. std::vector<cmXCodeObject*> XCodeObjects;
  196. cmXCodeObject* RootObject;
  197. private:
  198. std::string const& GetXcodeBuildCommand();
  199. std::string FindXcodeBuildCommand();
  200. std::string XcodeBuildCommand;
  201. bool XcodeBuildCommandInitialized;
  202. void PrintCompilerAdvice(std::ostream&, std::string const&,
  203. const char*) const {}
  204. std::string GetObjectsNormalDirectory(const std::string &projName,
  205. const std::string &configName,
  206. const cmGeneratorTarget *t) const;
  207. void addObject(cmXCodeObject *obj);
  208. std::string PostBuildMakeTarget(std::string const& tName,
  209. std::string const& configName);
  210. cmXCodeObject* MainGroupChildren;
  211. cmXCodeObject* SourcesGroupChildren;
  212. cmXCodeObject* ResourcesGroupChildren;
  213. cmMakefile* CurrentMakefile;
  214. cmLocalGenerator* CurrentLocalGenerator;
  215. std::vector<std::string> CurrentConfigurationTypes;
  216. std::string CurrentReRunCMakeMakefile;
  217. std::string CurrentXCodeHackMakefile;
  218. std::string CurrentProject;
  219. std::set<std::string> TargetDoneSet;
  220. std::vector<std::string> CurrentOutputDirectoryComponents;
  221. std::vector<std::string> ProjectSourceDirectoryComponents;
  222. std::vector<std::string> ProjectOutputDirectoryComponents;
  223. std::map<std::string, cmXCodeObject* > GroupMap;
  224. std::map<std::string, cmXCodeObject* > GroupNameMap;
  225. std::map<std::string, cmXCodeObject* > TargetGroup;
  226. std::map<std::string, cmXCodeObject* > FileRefs;
  227. std::map<cmGeneratorTarget const*, cmXCodeObject* > XCodeObjectMap;
  228. std::vector<std::string> Architectures;
  229. std::string GeneratorToolset;
  230. };
  231. #endif