cmLocalGenerator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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(const char* /* tgtInfo */) { 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. /** Compute the language used to compile the given source file. */
  145. const char* GetSourceFileLanguage(const cmSourceFile& source);
  146. // Create a struct to hold the varibles passed into
  147. // ExpandRuleVariables
  148. struct RuleVariables
  149. {
  150. RuleVariables()
  151. {
  152. memset(this, 0, sizeof(*this));
  153. }
  154. const char* TargetPDB;
  155. const char* Language;
  156. const char* Objects;
  157. const char* Target;
  158. const char* LinkLibraries;
  159. const char* Source;
  160. const char* AssemblySource;
  161. const char* PreprocessedSource;
  162. const char* Object;
  163. const char* ObjectDir;
  164. const char* Flags;
  165. const char* ObjectsQuoted;
  166. const char* TargetSOName;
  167. const char* TargetInstallNameDir;
  168. const char* LinkFlags;
  169. const char* LanguageCompileFlags;
  170. };
  171. protected:
  172. /** Escape the given string to be used as a command line argument in
  173. the native build system shell. */
  174. std::string EscapeForShell(const char* str);
  175. /** Construct a comment for a custom command. */
  176. std::string ConstructComment(const cmCustomCommand& cc,
  177. const char* default_comment = "");
  178. /** Fill out these strings for the given target. Libraries to link,
  179. * flags, and linkflags. */
  180. void GetTargetFlags(std::string& linkLibs,
  181. std::string& flags,
  182. std::string& linkFlags,
  183. cmTarget&target);
  184. ///! put all the libraries for a target on into the given stream
  185. virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
  186. // Expand rule variables in CMake of the type found in language rules
  187. void ExpandRuleVariables(std::string& string,
  188. const RuleVariables& replaceValues);
  189. // Expand rule variables in a single string
  190. std::string ExpandRuleVariable(std::string const& variable,
  191. const RuleVariables& replaceValues);
  192. /** Convert a target to a utility target for unsupported
  193. * languages of a generator */
  194. void AddBuildTargetRule(const char* llang, cmTarget& target);
  195. ///! add a custom command to build a .o file that is part of a target
  196. void AddCustomCommandToCreateObject(const char* ofname,
  197. const char* lang,
  198. cmSourceFile& source,
  199. cmTarget& target);
  200. // Create Custom Targets and commands for unsupported languages
  201. // The set passed in should contain the languages supported by the
  202. // generator directly. Any targets containing files that are not
  203. // of the types listed will be compiled as custom commands and added
  204. // to a custom target.
  205. void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
  206. // Handle old-style install rules stored in the targets.
  207. void GenerateTargetInstallRules(
  208. std::ostream& os, const char* config,
  209. std::vector<std::string> const& configurationTypes);
  210. // Compute object file names.
  211. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source);
  212. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  213. cmMakefile *Makefile;
  214. cmGlobalGenerator *GlobalGenerator;
  215. // members used for relative path function ConvertToMakefilePath
  216. std::string RelativePathToSourceDir;
  217. std::string RelativePathToBinaryDir;
  218. std::vector<std::string> HomeDirectoryComponents;
  219. std::vector<std::string> StartDirectoryComponents;
  220. std::vector<std::string> HomeOutputDirectoryComponents;
  221. std::vector<std::string> StartOutputDirectoryComponents;
  222. bool ExcludeFromAll;
  223. cmLocalGenerator* Parent;
  224. std::vector<cmLocalGenerator*> Children;
  225. std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
  226. std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
  227. bool WindowsShell;
  228. bool ForceUnixPath;
  229. bool UseRelativePaths;
  230. bool IgnoreLibPrefix;
  231. bool Configured;
  232. bool EmitUniversalBinaryFlags;
  233. // Hack for ExpandRuleVariable until object-oriented version is
  234. // committed.
  235. std::string TargetImplib;
  236. };
  237. #endif