cmTarget.h 7.7 KB

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