cmTarget.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. #include "cmSourceFile.h"
  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. void SetType(TargetType f) { m_TargetType = f; }
  38. /**
  39. * Indicate whether the target is part of the all target
  40. */
  41. bool IsInAll() const { return m_InAll; }
  42. bool GetInAll() const { return m_InAll; }
  43. void SetInAll(bool f) { m_InAll = f; }
  44. /**
  45. * Get the list of the custom commands for this target
  46. */
  47. const std::vector<cmCustomCommand> &GetCustomCommands() const {return m_CustomCommands;}
  48. std::vector<cmCustomCommand> &GetCustomCommands() {return m_CustomCommands;}
  49. /**
  50. * Get the list of the source lists used by this target
  51. */
  52. const std::vector<std::string> &GetSourceLists() const
  53. {return m_SourceLists;}
  54. std::vector<std::string> &GetSourceLists() {return m_SourceLists;}
  55. /**
  56. * Get the list of the source files used by this target
  57. */
  58. const std::vector<cmSourceFile*> &GetSourceFiles() const
  59. {return m_SourceFiles;}
  60. std::vector<cmSourceFile*> &GetSourceFiles() {return m_SourceFiles;}
  61. ///! does this target have a cxx file in it
  62. bool HasCxx() const;
  63. /**
  64. * Get the list of the source files used by this target
  65. */
  66. enum LinkLibraryType {GENERAL, DEBUG, OPTIMIZED};
  67. typedef std::vector<std::pair<std::string,LinkLibraryType> > LinkLibraries;
  68. const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
  69. void AddLinkLibrary(cmMakefile& mf,
  70. const char *target, const char* lib,
  71. LinkLibraryType llt);
  72. void AddLinkLibrary(const std::string& lib,
  73. LinkLibraryType llt);
  74. void MergeLinkLibraries( cmMakefile& mf, const char* selfname, const LinkLibraries& libs );
  75. const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
  76. void AddLinkDirectory(const char* d);
  77. /**
  78. * Set the path where this target should be installed. This is relative to
  79. * INSTALL_PREFIX
  80. */
  81. std::string GetInstallPath() const {return m_InstallPath;}
  82. void SetInstallPath(const char *name) {m_InstallPath = name;}
  83. /**
  84. * Generate the SourceFilesList from the SourceLists. This should only be
  85. * done once to be safe.
  86. */
  87. void GenerateSourceFilesFromSourceLists(cmMakefile &mf);
  88. /** Add a utility on which this project depends. A utility is an executable
  89. * name as would be specified to the ADD_EXECUTABLE or UTILITY_SOURCE
  90. * commands. It is not a full path nor does it have an extension.
  91. */
  92. void AddUtility(const char* u) { m_Utilities.insert(u);}
  93. ///! Get the utilities used by this target
  94. std::set<cmStdString>const& GetUtilities() const { return m_Utilities; }
  95. void AnalyzeLibDependencies( const cmMakefile& mf );
  96. private:
  97. /**
  98. * This map holds the dependency graph. map[x] returns a set of
  99. * direct dependencies of x.
  100. */
  101. typedef std::map< cmStdString, std::set< cmStdString > > DependencyMap;
  102. /**
  103. * Maps a library name to its internal structure
  104. */
  105. typedef std::map< cmStdString, std::pair<cmStdString,LinkLibraryType> > LibTypeMap;
  106. /**
  107. * Emits the library \param lib and all its dependencies into
  108. * link_line. \param emitted keeps track of the libraries that have
  109. * been emitted to avoid duplicates--it is more efficient than
  110. * searching link_line. \param visited is used detect cycles. Note
  111. * that \param link_line is in reverse order, in that the
  112. * dependencies of a library are listed before the library itself.
  113. */
  114. void Emit( const std::string& lib,
  115. const DependencyMap& dep_map,
  116. std::set<cmStdString>& emitted,
  117. std::set<cmStdString>& visited,
  118. std::vector<std::string>& link_line ) const;
  119. /**
  120. * Finds the explicit dependencies for \param lib, if they have been
  121. * specified, and inserts them into \param dep_map. It also adds the
  122. * maps from the library names to internal structures for any
  123. * libraries introduced by the analysis. \param addLibDirs is true
  124. * if paths to newly found libraries should be added to the search
  125. * path.
  126. */
  127. void GatherDependencies( const cmMakefile& mf, const std::string& lib,
  128. DependencyMap& dep_map );
  129. /**
  130. * Returns true if lib1 depends on lib2 according to \param
  131. * dep_map. \param visited is used to prevent infinite loops when
  132. * cycles are present.
  133. */
  134. bool DependsOn( const std::string& lib1, const std::string& lib2,
  135. const DependencyMap& dep_map,
  136. std::set<cmStdString>& visited ) const;
  137. private:
  138. std::vector<cmCustomCommand> m_CustomCommands;
  139. std::vector<std::string> m_SourceLists;
  140. TargetType m_TargetType;
  141. std::vector<cmSourceFile*> m_SourceFiles;
  142. LinkLibraries m_LinkLibraries;
  143. LinkLibraries m_PrevLinkedLibraries;
  144. std::vector<std::string> m_LinkDirectories;
  145. bool m_InAll;
  146. std::string m_InstallPath;
  147. std::set<cmStdString> m_Utilities;
  148. };
  149. typedef std::map<cmStdString,cmTarget> cmTargets;
  150. #endif