cmLinkItem.h 3.9 KB

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