cmLinkItem.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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"
  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(CM_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. cmLinkImplItem(cmLinkImplItem const& r)
  48. : cmLinkItem(r)
  49. , Backtrace(r.Backtrace)
  50. , FromGenex(r.FromGenex)
  51. {
  52. }
  53. cmListFileBacktrace Backtrace;
  54. bool FromGenex;
  55. };
  56. /** The link implementation specifies the direct library
  57. dependencies needed by the object files of the target. */
  58. struct cmLinkImplementationLibraries
  59. {
  60. // Libraries linked directly in this configuration.
  61. std::vector<cmLinkImplItem> Libraries;
  62. // Libraries linked directly in other configurations.
  63. // Needed only for OLD behavior of CMP0003.
  64. std::vector<cmLinkItem> WrongConfigLibraries;
  65. };
  66. struct cmLinkInterfaceLibraries
  67. {
  68. // Libraries listed in the interface.
  69. std::vector<cmLinkItem> Libraries;
  70. };
  71. struct cmLinkInterface : public cmLinkInterfaceLibraries
  72. {
  73. // Languages whose runtime libraries must be linked.
  74. std::vector<std::string> Languages;
  75. // Shared library dependencies needed for linking on some platforms.
  76. std::vector<cmLinkItem> SharedDeps;
  77. // Number of repetitions of a strongly connected component of two
  78. // or more static libraries.
  79. unsigned int Multiplicity;
  80. // Libraries listed for other configurations.
  81. // Needed only for OLD behavior of CMP0003.
  82. std::vector<cmLinkItem> WrongConfigLibraries;
  83. bool ImplementationIsInterface;
  84. cmLinkInterface()
  85. : Multiplicity(0)
  86. , ImplementationIsInterface(false)
  87. {
  88. }
  89. };
  90. struct cmOptionalLinkInterface : public cmLinkInterface
  91. {
  92. cmOptionalLinkInterface()
  93. : LibrariesDone(false)
  94. , AllDone(false)
  95. , Exists(false)
  96. , HadHeadSensitiveCondition(false)
  97. , ExplicitLibraries(CM_NULLPTR)
  98. {
  99. }
  100. bool LibrariesDone;
  101. bool AllDone;
  102. bool Exists;
  103. bool HadHeadSensitiveCondition;
  104. const char* ExplicitLibraries;
  105. };
  106. struct cmHeadToLinkInterfaceMap
  107. : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
  108. {
  109. };
  110. struct cmLinkImplementation : public cmLinkImplementationLibraries
  111. {
  112. // Languages whose runtime libraries must be linked.
  113. std::vector<std::string> Languages;
  114. };
  115. // Cache link implementation computation from each configuration.
  116. struct cmOptionalLinkImplementation : public cmLinkImplementation
  117. {
  118. cmOptionalLinkImplementation()
  119. : LibrariesDone(false)
  120. , LanguagesDone(false)
  121. , HadHeadSensitiveCondition(false)
  122. {
  123. }
  124. bool LibrariesDone;
  125. bool LanguagesDone;
  126. bool HadHeadSensitiveCondition;
  127. };
  128. /** Compute the link type to use for the given configuration. */
  129. inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  130. const std::string& config, std::vector<std::string> const& debugConfigs)
  131. {
  132. // No configuration is always optimized.
  133. if (config.empty()) {
  134. return OPTIMIZED_LibraryType;
  135. }
  136. // Check if any entry in the list matches this configuration.
  137. std::string configUpper = cmSystemTools::UpperCase(config);
  138. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  139. debugConfigs.end()) {
  140. return DEBUG_LibraryType;
  141. }
  142. // The current configuration is not a debug configuration.
  143. return OPTIMIZED_LibraryType;
  144. }
  145. #endif