cmLocalGenerator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmLocalGenerator_h
  14. #define cmLocalGenerator_h
  15. #include "cmStandardIncludes.h"
  16. class cmMakefile;
  17. class cmGlobalGenerator;
  18. class cmTarget;
  19. class cmTargetManifest;
  20. class cmSourceFile;
  21. class cmCustomCommand;
  22. /** \class cmLocalGenerator
  23. * \brief Create required build files for a directory.
  24. *
  25. * Subclasses of this abstract class generate makefiles, DSP, etc for various
  26. * platforms. This class should never be constructued directly. A
  27. * GlobalGenerator will create it and invoke the appropriate commands on it.
  28. */
  29. class cmLocalGenerator
  30. {
  31. public:
  32. cmLocalGenerator();
  33. virtual ~cmLocalGenerator();
  34. /**
  35. * Generate the makefile for this directory.
  36. */
  37. virtual void Generate() {};
  38. /**
  39. * Process the CMakeLists files for this directory to fill in the
  40. * Makefile ivar
  41. */
  42. virtual void Configure();
  43. /**
  44. * Perform any final calculations prior to generation
  45. */
  46. virtual void ConfigureFinalPass();
  47. /**
  48. * Generate the install rules files in this directory.
  49. */
  50. virtual void GenerateInstallRules();
  51. /**
  52. * Generate the test files for tests.
  53. */
  54. virtual void GenerateTestFiles();
  55. /**
  56. * Generate a manifest of target files that will be built.
  57. */
  58. virtual void GenerateTargetManifest(cmTargetManifest&);
  59. ///! Get the makefile for this generator
  60. cmMakefile *GetMakefile() {
  61. return this->Makefile; };
  62. ///! Get the GlobalGenerator this is associated with
  63. cmGlobalGenerator *GetGlobalGenerator() {
  64. return this->GlobalGenerator; };
  65. ///! Set the Global Generator, done on creation by the GlobalGenerator
  66. void SetGlobalGenerator(cmGlobalGenerator *gg);
  67. /**
  68. * Convert something to something else. This is a centralized coversion
  69. * routine used by the generators to handle relative paths and the like.
  70. * The flags determine what is actually done.
  71. *
  72. * relative: treat the argument as a directory and convert it to make it
  73. * relative or full or unchanged. If relative (HOME, START etc) then that
  74. * specifies what it should be relative to.
  75. *
  76. * output: make the result suitable for output to a...
  77. *
  78. * optional: should any relative path operation be controlled by the rel
  79. * path setting
  80. */
  81. enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
  82. enum OutputFormat { UNCHANGED, MAKEFILE, SHELL };
  83. std::string Convert(const char* source,
  84. RelativeRoot relative,
  85. OutputFormat output = UNCHANGED,
  86. bool optional = false);
  87. ///! Call this prior to using Convert
  88. void SetupPathConversions();
  89. /**
  90. * Convert the given path to an output path that is optionally
  91. * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
  92. * remote path must use forward slashes and not already be escaped
  93. * or quoted.
  94. */
  95. std::string ConvertToOptionallyRelativeOutputPath(const char* remote);
  96. // flag to determine if this project should be included in a parent project
  97. bool GetExcludeAll()
  98. {
  99. return this->ExcludeFromAll;
  100. }
  101. void SetExcludeAll(bool b)
  102. {
  103. this->ExcludeFromAll = b;
  104. }
  105. ///! set/get the parent generator
  106. cmLocalGenerator* GetParent(){return this->Parent;}
  107. void SetParent(cmLocalGenerator* g) { this->Parent = g; g->AddChild(this); }
  108. ///! set/get the children
  109. void AddChild(cmLocalGenerator* g) { this->Children.push_back(g); }
  110. std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; };
  111. void AddLanguageFlags(std::string& flags, const char* lang,
  112. const char* config);
  113. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  114. void AddConfigVariableFlags(std::string& flags, const char* var,
  115. const char* config);
  116. void AppendFlags(std::string& flags, const char* newFlags);
  117. ///! Get the include flags for the current makefile and language
  118. const char* GetIncludeFlags(const char* lang);
  119. /** Translate a dependency as given in CMake code to the name to
  120. appear in a generated build file. If the given name is that of
  121. a CMake target it will be transformed to the real output
  122. location of that target for the given configuration. If the
  123. given name is the full path to a file it will be returned.
  124. Otherwise the name is treated as a relative path with respect to
  125. the source directory of this generator. This should only be
  126. used for dependencies of custom commands. */
  127. std::string GetRealDependency(const char* name, const char* config);
  128. ///! for existing files convert to output path and short path if spaces
  129. std::string ConvertToOutputForExisting(const char* p);
  130. /** Called from command-line hook to check dependencies. */
  131. virtual void CheckDependencies(cmMakefile* /* mf */,
  132. bool /* verbose */,
  133. bool /* clear */) {};
  134. /** Called from command-line hook to scan dependencies. */
  135. virtual bool ScanDependencies(std::vector<std::string> const& /* args */)
  136. {return true;};
  137. /** Compute the list of link libraries and directories for the given
  138. target and configuration. */
  139. void ComputeLinkInformation(cmTarget& target, const char* config,
  140. std::vector<cmStdString>& outLibs,
  141. std::vector<cmStdString>& outDirs,
  142. std::vector<cmStdString>* fullPathLibs=0);
  143. /** Get the include flags for the current makefile and language. */
  144. void GetIncludeDirectories(std::vector<std::string>& dirs);
  145. // Create a struct to hold the varibles passed into
  146. // ExpandRuleVariables
  147. struct RuleVariables
  148. {
  149. RuleVariables()
  150. {
  151. this->Language= 0;
  152. this->Objects= 0;
  153. this->Target= 0;
  154. this->LinkLibraries= 0;
  155. this->Source= 0;
  156. this->Object= 0;
  157. this->ObjectDir= 0;
  158. this->Flags= 0;
  159. this->ObjectsQuoted= 0;
  160. this->TargetSOName= 0;
  161. this->TargetInstallNameDir = 0;
  162. this->LinkFlags= 0;
  163. }
  164. const char* TargetPDB;
  165. const char* Language;
  166. const char* Objects;
  167. const char* Target;
  168. const char* LinkLibraries;
  169. const char* Source;
  170. const char* Object;
  171. const char* ObjectDir;
  172. const char* Flags;
  173. const char* ObjectsQuoted;
  174. const char* TargetSOName;
  175. const char* TargetInstallNameDir;
  176. const char* LinkFlags;
  177. const char* LanguageCompileFlags;
  178. };
  179. protected:
  180. /** Construct a script from the given list of command lines. */
  181. std::string ConstructScript(const cmCustomCommandLines& commandLines,
  182. const char* workingDirectory,
  183. const char* newline = "\n");
  184. /** Construct a comment for a custom command. */
  185. std::string ConstructComment(const cmCustomCommand& cc,
  186. const char* default_comment = "");
  187. /** Fill out these strings for the given target. Libraries to link,
  188. * flags, and linkflags. */
  189. void GetTargetFlags(std::string& linkLibs,
  190. std::string& flags,
  191. std::string& linkFlags,
  192. cmTarget&target);
  193. ///! put all the libraries for a target on into the given stream
  194. virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
  195. // Expand rule variables in CMake of the type found in language rules
  196. void ExpandRuleVariables(std::string& string,
  197. const RuleVariables& replaceValues);
  198. // Expand rule variables in a single string
  199. std::string ExpandRuleVariable(std::string const& variable,
  200. const RuleVariables& replaceValues);
  201. /** Convert a target to a utility target for unsupported
  202. * languages of a generator */
  203. void AddBuildTargetRule(const char* llang, cmTarget& target);
  204. ///! add a custom command to build a .o file that is part of a target
  205. void AddCustomCommandToCreateObject(const char* ofname,
  206. const char* lang,
  207. cmSourceFile& source,
  208. cmTarget& target);
  209. // Create Custom Targets and commands for unsupported languages
  210. // The set passed in should contain the languages supported by the
  211. // generator directly. Any targets containing files that are not
  212. // of the types listed will be compiled as custom commands and added
  213. // to a custom target.
  214. void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
  215. // Handle old-style install rules stored in the targets.
  216. void GenerateTargetInstallRules(
  217. std::ostream& os, const char* config,
  218. std::vector<std::string> const& configurationTypes);
  219. cmMakefile *Makefile;
  220. cmGlobalGenerator *GlobalGenerator;
  221. // members used for relative path function ConvertToMakefilePath
  222. std::string RelativePathToSourceDir;
  223. std::string RelativePathToBinaryDir;
  224. std::vector<std::string> HomeDirectoryComponents;
  225. std::vector<std::string> StartDirectoryComponents;
  226. std::vector<std::string> HomeOutputDirectoryComponents;
  227. std::vector<std::string> StartOutputDirectoryComponents;
  228. bool ExcludeFromAll;
  229. cmLocalGenerator* Parent;
  230. std::vector<cmLocalGenerator*> Children;
  231. std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
  232. bool WindowsShell;
  233. bool ForceUnixPath;
  234. bool UseRelativePaths;
  235. bool IgnoreLibPrefix;
  236. bool Configured;
  237. bool EmitUniversalBinaryFlags;
  238. // Hack for ExpandRuleVariable until object-oriented version is
  239. // committed.
  240. std::string TargetImplib;
  241. };
  242. #endif