cmLocalGenerator.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. * m_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->m_Makefile; };
  56. ///! Get the GlobalGenerator this is associated with
  57. cmGlobalGenerator *GetGlobalGenerator() {
  58. return m_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. /**
  82. * Convert the given path to an output path that is optionally
  83. * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
  84. * remote path must use forward slashes and not already be escaped
  85. * or quoted.
  86. */
  87. std::string ConvertToOptionallyRelativeOutputPath(const char* remote);
  88. // flag to determine if this project should be included in a parent project
  89. bool GetExcludeAll()
  90. {
  91. return m_ExcludeFromAll;
  92. }
  93. void SetExcludeAll(bool b)
  94. {
  95. m_ExcludeFromAll = b;
  96. }
  97. ///! set/get the parent generator
  98. cmLocalGenerator* GetParent(){return m_Parent;}
  99. void SetParent(cmLocalGenerator* g) { m_Parent = g; g->AddChild(this); }
  100. ///! set/get the children
  101. void AddChild(cmLocalGenerator* g) { this->Children.push_back(g); }
  102. std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; };
  103. void AddLanguageFlags(std::string& flags, const char* lang);
  104. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  105. void AddConfigVariableFlags(std::string& flags, const char* var);
  106. void AppendFlags(std::string& flags, const char* newFlags);
  107. ///! Get the include flags for the current makefile and language
  108. const char* GetIncludeFlags(const char* lang);
  109. ///! for existing files convert to output path and short path if spaces
  110. std::string ConvertToOutputForExisting(const char* p);
  111. /** Called from command-line hook to check dependencies. */
  112. virtual void CheckDependencies(cmMakefile* /* mf */,
  113. bool /* verbose */,
  114. bool /* clear */) {};
  115. /** Called from command-line hook to scan dependencies. */
  116. virtual bool ScanDependencies(std::vector<std::string> const& /* args */) {return true;};
  117. protected:
  118. /** Construct a script from the given list of command lines. */
  119. std::string ConstructScript(const cmCustomCommandLines& commandLines,
  120. const char* newline = "\n");
  121. ///! Fill out these strings for the given target. Libraries to link, flags, and linkflags.
  122. void GetTargetFlags(std::string& linkLibs,
  123. std::string& flags,
  124. std::string& linkFlags,
  125. cmTarget&target);
  126. ///! put all the libraries for a target on into the given stream
  127. virtual void OutputLinkLibraries(std::ostream&, const char* name,cmTarget &);
  128. /** Get the include flags for the current makefile and language. */
  129. void GetIncludeDirectories(std::vector<std::string>& dirs);
  130. // Expand rule variables in CMake of the type found in language rules
  131. void ExpandRuleVariables(std::string& string,
  132. const char* language,
  133. const char* objects=0,
  134. const char* target=0,
  135. const char* linkLibs=0,
  136. const char* source=0,
  137. const char* object =0,
  138. const char* flags = 0,
  139. const char* objectsquoted = 0,
  140. const char* targetBase = 0,
  141. const char* targetSOName = 0,
  142. const char* linkFlags = 0);
  143. // Expand rule variables in a single string
  144. std::string ExpandRuleVariable(std::string const& variable,
  145. const char* lang,
  146. const char* objects,
  147. const char* target,
  148. const char* linkLibs,
  149. const char* source,
  150. const char* object,
  151. const char* flags,
  152. const char* objectsquoted,
  153. const char* targetBase,
  154. const char* targetSOName,
  155. const char* linkFlags);
  156. ///! Convert a target to a utility target for unsupported languages of a generator
  157. void AddBuildTargetRule(const char* llang, cmTarget& target);
  158. ///! add a custom command to build a .o file that is part of a target
  159. void AddCustomCommandToCreateObject(const char* ofname,
  160. const char* lang,
  161. cmSourceFile& source,
  162. cmTarget& target);
  163. // Create Custom Targets and commands for unsupported languages
  164. // The set passed in should contain the languages supported by the
  165. // generator directly. Any targets containing files that are not
  166. // of the types listed will be compiled as custom commands and added
  167. // to a custom target.
  168. void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
  169. virtual void AddInstallRule(std::ostream& fout, const char* dest, int type,
  170. const char* files, bool optional = false, const char* properties = 0);
  171. cmMakefile *m_Makefile;
  172. cmGlobalGenerator *m_GlobalGenerator;
  173. // members used for relative path function ConvertToMakefilePath
  174. std::string m_RelativePathToSourceDir;
  175. std::string m_RelativePathToBinaryDir;
  176. std::vector<std::string> m_HomeDirectoryComponents;
  177. std::vector<std::string> m_StartDirectoryComponents;
  178. std::vector<std::string> m_HomeOutputDirectoryComponents;
  179. std::vector<std::string> m_StartOutputDirectoryComponents;
  180. bool m_ExcludeFromAll;
  181. cmLocalGenerator* m_Parent;
  182. std::vector<cmLocalGenerator*> Children;
  183. std::map<cmStdString, cmStdString> m_LanguageToIncludeFlags;
  184. bool m_WindowsShell;
  185. bool m_UseRelativePaths;
  186. bool m_IgnoreLibPrefix;
  187. bool Configured;
  188. };
  189. #endif