cmTarget.h 7.3 KB

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