cmLocalGenerator.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. fromTheTop indicates if this
  34. * is being invoked as part of a global Generate or specific to this
  35. * directory. The difference is that when done from the Top we might skip
  36. * some steps to save time, such as dependency generation for the
  37. * makefiles. This is done by a direct invocation from make.
  38. */
  39. virtual void Generate(bool /* fromTheTop */) {};
  40. /**
  41. * Process the CMakeLists files for this directory to fill in the
  42. * m_Makefile ivar
  43. */
  44. virtual void Configure();
  45. /**
  46. * Perform any final calculations prior to generation
  47. */
  48. virtual void ConfigureFinalPass();
  49. /**
  50. * Generate the install rules files in this directory.
  51. */
  52. virtual void GenerateInstallRules();
  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. /** Get the full name of the target's file, without path. */
  62. std::string GetFullTargetName(const char* n, const cmTarget& t);
  63. std::string ConvertToRelativeOutputPath(const char* p);
  64. // flag to determine if this project should be included in a parent project
  65. bool GetExcludeAll()
  66. {
  67. return m_ExcludeFromAll;
  68. }
  69. void SetExcludeAll(bool b)
  70. {
  71. m_ExcludeFromAll = b;
  72. }
  73. ///! set/get the parent generator
  74. cmLocalGenerator* GetParent(){return m_Parent;}
  75. void SetParent(cmLocalGenerator* g) { m_Parent = g;}
  76. void AddLanguageFlags(std::string& flags, const char* lang);
  77. void AddSharedFlags(std::string& flags, const char* lang, bool shared);
  78. void AddConfigVariableFlags(std::string& flags, const char* var);
  79. void AppendFlags(std::string& flags, const char* newFlags);
  80. ///! Get the include flags for the current makefile and language
  81. const char* GetIncludeFlags(const char* lang);
  82. ///! for existing files convert to output path and short path if spaces
  83. std::string ConvertToOutputForExisting(const char* p);
  84. void DetermineLibraryPathOrder(const cmTarget& target,
  85. std::vector<std::string>& linkPaths,
  86. std::vector<std::string>& linkLibs);
  87. protected:
  88. /** Construct a script from the given list of command lines. */
  89. std::string ConstructScript(const cmCustomCommandLines& commandLines,
  90. const char* newline = "\n");
  91. ///! Fill out these strings for the given target. Libraries to link, flags, and linkflags.
  92. void GetTargetFlags(std::string& linkLibs,
  93. std::string& flags,
  94. std::string& linkFlags,
  95. cmTarget&target);
  96. ///! put all the libraries for a target on into the given stream
  97. virtual void OutputLinkLibraries(std::ostream&, const char* name, const cmTarget &);
  98. /** Get the include flags for the current makefile and language. */
  99. void GetIncludeDirectories(std::vector<std::string>& dirs);
  100. // Expand rule variables in CMake of the type found in language rules
  101. void ExpandRuleVariables(std::string& string,
  102. const char* language,
  103. const char* objects=0,
  104. const char* target=0,
  105. const char* linkLibs=0,
  106. const char* source=0,
  107. const char* object =0,
  108. const char* flags = 0,
  109. const char* objectsquoted = 0,
  110. const char* targetBase = 0,
  111. const char* targetSOName = 0,
  112. const char* linkFlags = 0);
  113. ///! Convert a target to a utility target for unsupported languages of a generator
  114. void AddBuildTargetRule(const char* llang, cmTarget& target);
  115. ///! add a custom command to build a .o file that is part of a target
  116. void AddCustomCommandToCreateObject(const char* ofname,
  117. const char* lang,
  118. cmSourceFile& source,
  119. cmTarget& target);
  120. // Create Custom Targets and commands for unsupported languages
  121. // The set passed in should contain the languages supported by the
  122. // generator directly. Any targets containing files that are not
  123. // of the types listed will be compiled as custom commands and added
  124. // to a custom target.
  125. void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
  126. virtual void AddInstallRule(std::ostream& fout, const char* dest, int type,
  127. const char* files, bool optional = false, const char* properties = 0);
  128. bool m_FromTheTop;
  129. cmMakefile *m_Makefile;
  130. cmGlobalGenerator *m_GlobalGenerator;
  131. // members used for relative path function ConvertToMakefilePath
  132. std::string m_RelativePathToSourceDir;
  133. std::string m_RelativePathToBinaryDir;
  134. std::string m_CurrentOutputDirectory;
  135. std::string m_HomeOutputDirectory;
  136. std::string m_HomeDirectory;
  137. std::string m_HomeOutputDirectoryNoSlash;
  138. bool m_ExcludeFromAll;
  139. cmLocalGenerator* m_Parent;
  140. std::map<cmStdString, cmStdString> m_LanguageToIncludeFlags;
  141. bool m_WindowsShell;
  142. bool m_UseRelativePaths;
  143. bool m_IgnoreLibPrefix;
  144. };
  145. #endif