cmLinkItem.h 3.9 KB

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