cmLocalGenerator.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. ///! Get the makefile for this generator
  50. cmMakefile *GetMakefile() {
  51. return this->m_Makefile; };
  52. ///! Get the GlobalGenerator this is associated with
  53. cmGlobalGenerator *GetGlobalGenerator() {
  54. return m_GlobalGenerator; };
  55. ///! Set the Global Generator, done on creation by the GlobalGenerator
  56. void SetGlobalGenerator(cmGlobalGenerator *gg);
  57. /** Get the full name of the target's file, without path. */
  58. std::string GetFullTargetName(const char* n, const cmTarget& t);
  59. /**
  60. * Convert the given remote path to a relative path with respect to
  61. * this generator's output directory. The remote path must use
  62. * forward slashes and not already be escaped or quoted.
  63. */
  64. std::string ConvertToRelativePath(const char* remote);
  65. /**
  66. * Convert to an output path that is relative to the current output
  67. * directory. The remote path must use forward slashes and not
  68. * already be escaped or quoted.
  69. */
  70. std::string ConvertToRelativeOutputPath(const char* remote);
  71. /**
  72. * Calls ConvertToRelativePath conditionally on the cache option
  73. * CMAKE_USE_RELATIVE_PATHS. The remote path must use forward
  74. * slashes and not already be escaped or quoted.
  75. */
  76. std::string ConvertToOptionallyRelativePath(const char* remote);
  77. /**
  78. * Convert the given path to an output path that is optionally
  79. * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
  80. * remote path must use forward slashes and not already be escaped
  81. * or quoted.
  82. */
  83. std::string ConvertToOptionallyRelativeOutputPath(const char* remote);
  84. // flag to determine if this project should be included in a parent project
  85. bool GetExcludeAll()
  86. {
  87. return m_ExcludeFromAll;
  88. }
  89. void SetExcludeAll(bool b)
  90. {
  91. m_ExcludeFromAll = b;
  92. }
  93. ///! set/get the parent generator
  94. cmLocalGenerator* GetParent(){return m_Parent;}
  95. void SetParent(cmLocalGenerator* g) { m_Parent = g; g->AddChild(this); }
  96. ///! set/get the children
  97. void AddChild(cmLocalGenerator* g) { this->Children.push_back(g); }
  98. std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; };
  99. void AddLanguageFlags(std::string& flags, const char* lang);
  100. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  101. void AddConfigVariableFlags(std::string& flags, const char* var);
  102. void AppendFlags(std::string& flags, const char* newFlags);
  103. ///! Get the include flags for the current makefile and language
  104. const char* GetIncludeFlags(const char* lang);
  105. ///! for existing files convert to output path and short path if spaces
  106. std::string ConvertToOutputForExisting(const char* p);
  107. protected:
  108. /** Construct a script from the given list of command lines. */
  109. std::string ConstructScript(const cmCustomCommandLines& commandLines,
  110. const char* newline = "\n");
  111. ///! Fill out these strings for the given target. Libraries to link, flags, and linkflags.
  112. void GetTargetFlags(std::string& linkLibs,
  113. std::string& flags,
  114. std::string& linkFlags,
  115. cmTarget&target);
  116. ///! put all the libraries for a target on into the given stream
  117. virtual void OutputLinkLibraries(std::ostream&, const char* name, const cmTarget &);
  118. /** Get the include flags for the current makefile and language. */
  119. void GetIncludeDirectories(std::vector<std::string>& dirs);
  120. // Expand rule variables in CMake of the type found in language rules
  121. void ExpandRuleVariables(std::string& string,
  122. const char* language,
  123. const char* objects=0,
  124. const char* target=0,
  125. const char* linkLibs=0,
  126. const char* source=0,
  127. const char* object =0,
  128. const char* flags = 0,
  129. const char* objectsquoted = 0,
  130. const char* targetBase = 0,
  131. const char* targetSOName = 0,
  132. const char* linkFlags = 0);
  133. ///! Convert a target to a utility target for unsupported languages of a generator
  134. void AddBuildTargetRule(const char* llang, cmTarget& target);
  135. ///! add a custom command to build a .o file that is part of a target
  136. void AddCustomCommandToCreateObject(const char* ofname,
  137. const char* lang,
  138. cmSourceFile& source,
  139. cmTarget& target);
  140. // Create Custom Targets and commands for unsupported languages
  141. // The set passed in should contain the languages supported by the
  142. // generator directly. Any targets containing files that are not
  143. // of the types listed will be compiled as custom commands and added
  144. // to a custom target.
  145. void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
  146. virtual void AddInstallRule(std::ostream& fout, const char* dest, int type,
  147. const char* files, bool optional = false, const char* properties = 0);
  148. cmMakefile *m_Makefile;
  149. cmGlobalGenerator *m_GlobalGenerator;
  150. // members used for relative path function ConvertToMakefilePath
  151. std::string m_RelativePathToSourceDir;
  152. std::string m_RelativePathToBinaryDir;
  153. std::vector<std::string> m_CurrentOutputDirectoryComponents;
  154. bool m_ExcludeFromAll;
  155. cmLocalGenerator* m_Parent;
  156. std::vector<cmLocalGenerator*> Children;
  157. std::map<cmStdString, cmStdString> m_LanguageToIncludeFlags;
  158. bool m_WindowsShell;
  159. bool m_UseRelativePaths;
  160. bool m_IgnoreLibPrefix;
  161. bool Configured;
  162. };
  163. #endif