cmLinkItem.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmLinkItem_h
  4. #define cmLinkItem_h
  5. #include "cmListFileCache.h"
  6. #include "cmSystemTools.h"
  7. class cmGeneratorTarget;
  8. // Basic information about each link item.
  9. class cmLinkItem : public std::string
  10. {
  11. typedef std::string std_string;
  12. public:
  13. cmLinkItem()
  14. : std_string()
  15. , Target(CM_NULLPTR)
  16. {
  17. }
  18. cmLinkItem(const std_string& n, cmGeneratorTarget const* t)
  19. : std_string(n)
  20. , Target(t)
  21. {
  22. }
  23. cmLinkItem(cmLinkItem const& r)
  24. : std_string(r)
  25. , Target(r.Target)
  26. {
  27. }
  28. cmGeneratorTarget const* Target;
  29. };
  30. class cmLinkImplItem : public cmLinkItem
  31. {
  32. public:
  33. cmLinkImplItem()
  34. : cmLinkItem()
  35. , Backtrace()
  36. , FromGenex(false)
  37. {
  38. }
  39. cmLinkImplItem(std::string const& n, cmGeneratorTarget const* t,
  40. cmListFileBacktrace const& bt, bool fromGenex)
  41. : cmLinkItem(n, t)
  42. , Backtrace(bt)
  43. , FromGenex(fromGenex)
  44. {
  45. }
  46. cmLinkImplItem(cmLinkImplItem const& r)
  47. : cmLinkItem(r)
  48. , Backtrace(r.Backtrace)
  49. , FromGenex(r.FromGenex)
  50. {
  51. }
  52. cmListFileBacktrace Backtrace;
  53. bool FromGenex;
  54. };
  55. /** The link implementation specifies the direct library
  56. dependencies needed by the object files of the target. */
  57. struct cmLinkImplementationLibraries
  58. {
  59. // Libraries linked directly in this configuration.
  60. std::vector<cmLinkImplItem> Libraries;
  61. // Libraries linked directly in other configurations.
  62. // Needed only for OLD behavior of CMP0003.
  63. std::vector<cmLinkItem> WrongConfigLibraries;
  64. };
  65. struct cmLinkInterfaceLibraries
  66. {
  67. // Libraries listed in the interface.
  68. std::vector<cmLinkItem> Libraries;
  69. };
  70. struct cmLinkInterface : public cmLinkInterfaceLibraries
  71. {
  72. // Languages whose runtime libraries must be linked.
  73. std::vector<std::string> Languages;
  74. // Shared library dependencies needed for linking on some platforms.
  75. std::vector<cmLinkItem> SharedDeps;
  76. // Number of repetitions of a strongly connected component of two
  77. // or more static libraries.
  78. unsigned int Multiplicity;
  79. // Libraries listed for other configurations.
  80. // Needed only for OLD behavior of CMP0003.
  81. std::vector<cmLinkItem> WrongConfigLibraries;
  82. bool ImplementationIsInterface;
  83. cmLinkInterface()
  84. : Multiplicity(0)
  85. , ImplementationIsInterface(false)
  86. {
  87. }
  88. };
  89. struct cmOptionalLinkInterface : public cmLinkInterface
  90. {
  91. cmOptionalLinkInterface()
  92. : LibrariesDone(false)
  93. , AllDone(false)
  94. , Exists(false)
  95. , HadHeadSensitiveCondition(false)
  96. , ExplicitLibraries(CM_NULLPTR)
  97. {
  98. }
  99. bool LibrariesDone;
  100. bool AllDone;
  101. bool Exists;
  102. bool HadHeadSensitiveCondition;
  103. const char* ExplicitLibraries;
  104. };
  105. struct cmHeadToLinkInterfaceMap
  106. : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
  107. {
  108. };
  109. struct cmLinkImplementation : public cmLinkImplementationLibraries
  110. {
  111. // Languages whose runtime libraries must be linked.
  112. std::vector<std::string> Languages;
  113. };
  114. // Cache link implementation computation from each configuration.
  115. struct cmOptionalLinkImplementation : public cmLinkImplementation
  116. {
  117. cmOptionalLinkImplementation()
  118. : LibrariesDone(false)
  119. , LanguagesDone(false)
  120. , HadHeadSensitiveCondition(false)
  121. {
  122. }
  123. bool LibrariesDone;
  124. bool LanguagesDone;
  125. bool HadHeadSensitiveCondition;
  126. };
  127. /** Compute the link type to use for the given configuration. */
  128. inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  129. const std::string& config, std::vector<std::string> const& debugConfigs)
  130. {
  131. // No configuration is always optimized.
  132. if (config.empty()) {
  133. return OPTIMIZED_LibraryType;
  134. }
  135. // Check if any entry in the list matches this configuration.
  136. std::string configUpper = cmSystemTools::UpperCase(config);
  137. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  138. debugConfigs.end()) {
  139. return DEBUG_LibraryType;
  140. }
  141. // The current configuration is not a debug configuration.
  142. return OPTIMIZED_LibraryType;
  143. }
  144. #endif