cmTarget.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 cmTarget_h
  14. #define cmTarget_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmCustomCommand.h"
  17. class cmSourceFile;
  18. /** \class cmTarget
  19. * \brief Represent a library or executable target loaded from a makefile.
  20. *
  21. * cmTarget represents a target loaded from
  22. * a makefile.
  23. */
  24. class cmTarget
  25. {
  26. public:
  27. enum TargetType { EXECUTABLE, WIN32_EXECUTABLE, STATIC_LIBRARY,
  28. SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, INSTALL_FILES,
  29. INSTALL_PROGRAMS };
  30. /**
  31. * Return the type of target.
  32. */
  33. TargetType GetType() const
  34. {
  35. return m_TargetType;
  36. }
  37. /**
  38. * Set the target type
  39. */
  40. void SetType(TargetType f);
  41. /**
  42. * Indicate whether the target is part of the all target
  43. */
  44. bool IsInAll() const { return m_InAll; }
  45. bool GetInAll() const { return m_InAll; }
  46. void SetInAll(bool f) { m_InAll = f; }
  47. /**
  48. * Get the list of the custom commands for this target
  49. */
  50. const std::vector<cmCustomCommand> &GetCustomCommands() const {return m_CustomCommands;}
  51. std::vector<cmCustomCommand> &GetCustomCommands() {return m_CustomCommands;}
  52. /**
  53. * Get the list of the source lists used by this target
  54. */
  55. const std::vector<std::string> &GetSourceLists() const
  56. {return m_SourceLists;}
  57. std::vector<std::string> &GetSourceLists() {return m_SourceLists;}
  58. /**
  59. * Get the list of the source files used by this target
  60. */
  61. const std::vector<cmSourceFile*> &GetSourceFiles() const
  62. {return m_SourceFiles;}
  63. std::vector<cmSourceFile*> &GetSourceFiles() {return m_SourceFiles;}
  64. ///! does this target have a cxx file in it
  65. bool HasCxx() const;
  66. /**
  67. * Get the list of the source files used by this target
  68. */
  69. enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
  70. typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
  71. const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
  72. /**
  73. * Clear the dependency information recorded for this target, if any.
  74. */
  75. void ClearDependencyInformation(cmMakefile& mf, const char* target);
  76. void AddLinkLibrary(cmMakefile& mf,
  77. const char *target, const char* lib,
  78. LinkLibraryType llt);
  79. void AddLinkLibrary(const std::string& lib,
  80. LinkLibraryType llt);
  81. void MergeLinkLibraries( cmMakefile& mf, const char* selfname, const LinkLibraries& libs );
  82. const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
  83. void AddLinkDirectory(const char* d);
  84. /**
  85. * Set the path where this target should be installed. This is relative to
  86. * INSTALL_PREFIX
  87. */
  88. std::string GetInstallPath() const {return m_InstallPath;}
  89. void SetInstallPath(const char *name) {m_InstallPath = name;}
  90. /**
  91. * Generate the SourceFilesList from the SourceLists. This should only be
  92. * done once to be safe.
  93. */
  94. void GenerateSourceFilesFromSourceLists(cmMakefile &mf);
  95. /** Add a utility on which this project depends. A utility is an executable
  96. * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
  97. * commands. It is not a full path nor does it have an extension.
  98. */
  99. void AddUtility(const char* u) { m_Utilities.insert(u);}
  100. ///! Get the utilities used by this target
  101. std::set<cmStdString>const& GetUtilities() const { return m_Utilities; }
  102. void AnalyzeLibDependencies( const cmMakefile& mf );
  103. private:
  104. /**
  105. * A list of direct dependencies. Use in conjunction with DependencyMap.
  106. */
  107. typedef std::vector<cmStdString> DependencyList;
  108. /**
  109. * This map holds the dependency graph. map[x] returns a set of
  110. * direct dependencies of x. Note that the direct depenencies are
  111. * ordered. This is necessary to handle direct dependencies that
  112. * themselves have no dependency information.
  113. */
  114. typedef std::map< cmStdString, std::vector< cmStdString > > DependencyMap;
  115. /**
  116. * Maps a library name to its internal structure
  117. */
  118. typedef std::map< cmStdString, std::pair<cmStdString,LinkLibraryType> > LibTypeMap;
  119. /**
  120. * Inserts \a dep at the end of the dependency list of \a lib.
  121. */
  122. void InsertDependency( DependencyMap& depMap,
  123. const cmStdString& lib,
  124. const cmStdString& dep ) const;
  125. /*
  126. * Deletes \a dep from the dependency list of \a lib.
  127. */
  128. void DeleteDependency( DependencyMap& depMap,
  129. const cmStdString& lib,
  130. const cmStdString& dep ) const;
  131. /**
  132. * Emits the library \a lib and all its dependencies into link_line.
  133. * \a emitted keeps track of the libraries that have been emitted to
  134. * avoid duplicates--it is more efficient than searching
  135. * link_line. \a visited is used detect cycles. Note that \a
  136. * link_line is in reverse order, in that the dependencies of a
  137. * library are listed before the library itself.
  138. */
  139. void Emit( const std::string& lib,
  140. const DependencyMap& dep_map,
  141. std::set<cmStdString>& emitted,
  142. std::set<cmStdString>& visited,
  143. std::vector<std::string>& link_line ) const;
  144. /**
  145. * Finds the dependencies for \a lib and inserts them into \a
  146. * dep_map.
  147. */
  148. void GatherDependencies( const cmMakefile& mf, const std::string& lib,
  149. DependencyMap& dep_map );
  150. private:
  151. std::vector<cmCustomCommand> m_CustomCommands;
  152. std::vector<std::string> m_SourceLists;
  153. TargetType m_TargetType;
  154. std::vector<cmSourceFile*> m_SourceFiles;
  155. LinkLibraries m_LinkLibraries;
  156. LinkLibraries m_PrevLinkedLibraries;
  157. std::vector<std::string> m_LinkDirectories;
  158. bool m_InAll;
  159. std::string m_InstallPath;
  160. std::set<cmStdString> m_Utilities;
  161. bool m_RecordDependencies;
  162. };
  163. typedef std::map<cmStdString,cmTarget> cmTargets;
  164. #endif