cmLocalGenerator.h 9.7 KB

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