cmLocalGenerator.h 9.6 KB

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