cmLocalGenerator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. bool filter_system_dirs = true);
  145. /** Compute the language used to compile the given source file. */
  146. const char* GetSourceFileLanguage(const cmSourceFile& source);
  147. // Create a struct to hold the varibles passed into
  148. // ExpandRuleVariables
  149. struct RuleVariables
  150. {
  151. RuleVariables()
  152. {
  153. memset(this, 0, sizeof(*this));
  154. }
  155. const char* TargetPDB;
  156. const char* TargetVersionMajor;
  157. const char* TargetVersionMinor;
  158. const char* Language;
  159. const char* Objects;
  160. const char* Target;
  161. const char* LinkLibraries;
  162. const char* Source;
  163. const char* AssemblySource;
  164. const char* PreprocessedSource;
  165. const char* Object;
  166. const char* ObjectDir;
  167. const char* Flags;
  168. const char* ObjectsQuoted;
  169. const char* TargetSOName;
  170. const char* TargetInstallNameDir;
  171. const char* LinkFlags;
  172. const char* LanguageCompileFlags;
  173. };
  174. /** Escape the given string to be used as a command line argument in
  175. the native build system shell. Optionally allow the build
  176. system to replace make variable references. Optionally adjust
  177. escapes for the special case of passing to the native echo
  178. command. */
  179. std::string EscapeForShell(const char* str, bool makeVars = false,
  180. bool forEcho = false);
  181. /** Backwards-compatibility version of EscapeForShell. */
  182. std::string EscapeForShellOldStyle(const char* str);
  183. protected:
  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. // Compute object file names.
  220. std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source);
  221. std::string& CreateSafeUniqueObjectFileName(const char* sin);
  222. cmMakefile *Makefile;
  223. cmGlobalGenerator *GlobalGenerator;
  224. // members used for relative path function ConvertToMakefilePath
  225. std::string RelativePathToSourceDir;
  226. std::string RelativePathToBinaryDir;
  227. std::vector<std::string> HomeDirectoryComponents;
  228. std::vector<std::string> StartDirectoryComponents;
  229. std::vector<std::string> HomeOutputDirectoryComponents;
  230. std::vector<std::string> StartOutputDirectoryComponents;
  231. bool ExcludeFromAll;
  232. cmLocalGenerator* Parent;
  233. std::vector<cmLocalGenerator*> Children;
  234. std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
  235. std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
  236. bool WindowsShell;
  237. bool WindowsVSIDE;
  238. bool ForceUnixPath;
  239. bool MSYSShell;
  240. bool UseRelativePaths;
  241. bool IgnoreLibPrefix;
  242. bool Configured;
  243. bool EmitUniversalBinaryFlags;
  244. // Hack for ExpandRuleVariable until object-oriented version is
  245. // committed.
  246. std::string TargetImplib;
  247. };
  248. #endif