cmTarget.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 "cmCustomCommand.h"
  16. class cmSourceFile;
  17. /** \class cmTarget
  18. * \brief Represent a library or executable target loaded from a makefile.
  19. *
  20. * cmTarget represents a target loaded from
  21. * a makefile.
  22. */
  23. class cmTarget
  24. {
  25. public:
  26. enum TargetType { EXECUTABLE, WIN32_EXECUTABLE, STATIC_LIBRARY,
  27. SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, INSTALL_FILES,
  28. INSTALL_PROGRAMS };
  29. enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
  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> &GetPreBuildCommands() const
  51. {return m_PreBuildCommands;}
  52. std::vector<cmCustomCommand> &GetPreBuildCommands()
  53. {return m_PreBuildCommands;}
  54. const std::vector<cmCustomCommand> &GetPreLinkCommands() const
  55. {return m_PreLinkCommands;}
  56. std::vector<cmCustomCommand> &GetPreLinkCommands()
  57. {return m_PreLinkCommands;}
  58. const std::vector<cmCustomCommand> &GetPostBuildCommands() const
  59. {return m_PostBuildCommands;}
  60. std::vector<cmCustomCommand> &GetPostBuildCommands()
  61. {return m_PostBuildCommands;}
  62. /**
  63. * Get the list of the source lists used by this target
  64. */
  65. const std::vector<std::string> &GetSourceLists() const
  66. {return m_SourceLists;}
  67. std::vector<std::string> &GetSourceLists() {return m_SourceLists;}
  68. /**
  69. * Get the list of the source files used by this target
  70. */
  71. const std::vector<cmSourceFile*> &GetSourceFiles() const
  72. {return m_SourceFiles;}
  73. std::vector<cmSourceFile*> &GetSourceFiles() {return m_SourceFiles;}
  74. ///! does this target have a cxx file in it
  75. bool HasCxx() const;
  76. /**
  77. * Get the list of the source files used by this target
  78. */
  79. enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
  80. typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
  81. const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
  82. /**
  83. * Clear the dependency information recorded for this target, if any.
  84. */
  85. void ClearDependencyInformation(cmMakefile& mf, const char* target);
  86. void AddLinkLibrary(cmMakefile& mf,
  87. const char *target, const char* lib,
  88. LinkLibraryType llt);
  89. void AddLinkLibrary(const std::string& lib,
  90. LinkLibraryType llt);
  91. void MergeLinkLibraries( cmMakefile& mf, const char* selfname, const LinkLibraries& libs );
  92. const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
  93. void AddLinkDirectory(const char* d);
  94. /**
  95. * Set the path where this target should be installed. This is relative to
  96. * INSTALL_PREFIX
  97. */
  98. std::string GetInstallPath() const {return m_InstallPath;}
  99. void SetInstallPath(const char *name) {m_InstallPath = name;}
  100. /**
  101. * Generate the SourceFilesList from the SourceLists. This should only be
  102. * done once to be safe.
  103. */
  104. void GenerateSourceFilesFromSourceLists(cmMakefile &mf);
  105. /** Add a utility on which this project depends. A utility is an executable
  106. * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
  107. * commands. It is not a full path nor does it have an extension.
  108. */
  109. void AddUtility(const char* u) { m_Utilities.insert(u);}
  110. ///! Get the utilities used by this target
  111. std::set<cmStdString>const& GetUtilities() const { return m_Utilities; }
  112. void AnalyzeLibDependencies( const cmMakefile& mf );
  113. ///! Set/Get a property of this target file
  114. void SetProperty(const char *prop, const char *value);
  115. const char *GetProperty(const char *prop) const;
  116. bool GetPropertyAsBool(const char *prop) const;
  117. /**
  118. * Trace through the source files in this target and add al source files
  119. * that they depend on, used by the visual studio generators
  120. */
  121. void TraceVSDependencies(std::string projName, cmMakefile *mf);
  122. private:
  123. /**
  124. * A list of direct dependencies. Use in conjunction with DependencyMap.
  125. */
  126. typedef std::vector<cmStdString> DependencyList;
  127. /**
  128. * This map holds the dependency graph. map[x] returns a set of
  129. * direct dependencies of x. Note that the direct depenencies are
  130. * ordered. This is necessary to handle direct dependencies that
  131. * themselves have no dependency information.
  132. */
  133. typedef std::map< cmStdString, std::vector< cmStdString > > DependencyMap;
  134. /**
  135. * Maps a library name to its internal structure
  136. */
  137. typedef std::map< cmStdString, std::pair<cmStdString,LinkLibraryType> > LibTypeMap;
  138. /**
  139. * Inserts \a dep at the end of the dependency list of \a lib.
  140. */
  141. void InsertDependency( DependencyMap& depMap,
  142. const cmStdString& lib,
  143. const cmStdString& dep ) const;
  144. /*
  145. * Deletes \a dep from the dependency list of \a lib.
  146. */
  147. void DeleteDependency( DependencyMap& depMap,
  148. const cmStdString& lib,
  149. const cmStdString& dep ) const;
  150. /**
  151. * Emits the library \a lib and all its dependencies into link_line.
  152. * \a emitted keeps track of the libraries that have been emitted to
  153. * avoid duplicates--it is more efficient than searching
  154. * link_line. \a visited is used detect cycles. Note that \a
  155. * link_line is in reverse order, in that the dependencies of a
  156. * library are listed before the library itself.
  157. */
  158. void Emit( const std::string& lib,
  159. const DependencyMap& dep_map,
  160. std::set<cmStdString>& emitted,
  161. std::set<cmStdString>& visited,
  162. std::vector<std::string>& link_line ) const;
  163. /**
  164. * Finds the dependencies for \a lib and inserts them into \a
  165. * dep_map.
  166. */
  167. void GatherDependencies( const cmMakefile& mf, const std::string& lib,
  168. DependencyMap& dep_map );
  169. private:
  170. std::vector<cmCustomCommand> m_PreBuildCommands;
  171. std::vector<cmCustomCommand> m_PreLinkCommands;
  172. std::vector<cmCustomCommand> m_PostBuildCommands;
  173. std::vector<std::string> m_SourceLists;
  174. TargetType m_TargetType;
  175. std::vector<cmSourceFile*> m_SourceFiles;
  176. LinkLibraries m_LinkLibraries;
  177. LinkLibraries m_PrevLinkedLibraries;
  178. std::vector<std::string> m_LinkDirectories;
  179. bool m_InAll;
  180. std::string m_InstallPath;
  181. std::set<cmStdString> m_Utilities;
  182. bool m_RecordDependencies;
  183. std::map<cmStdString,cmStdString> m_Properties;
  184. };
  185. typedef std::map<cmStdString,cmTarget> cmTargets;
  186. #endif