cmLinkItem.h 3.9 KB

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