cmLinkItem.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <map>
  6. #include <ostream>
  7. #include <string>
  8. #include <unordered_map>
  9. #include <vector>
  10. #include <cmext/algorithm>
  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 s, bool c, cmListFileBacktrace bt);
  22. cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt);
  23. std::string const& AsStr() const;
  24. cmGeneratorTarget const* Target = nullptr;
  25. bool Cross = false;
  26. cmListFileBacktrace Backtrace;
  27. friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);
  28. friend bool operator==(cmLinkItem const& l, cmLinkItem const& r);
  29. friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item);
  30. };
  31. class cmLinkImplItem : public cmLinkItem
  32. {
  33. public:
  34. cmLinkImplItem();
  35. cmLinkImplItem(cmLinkItem item, bool checkCMP0027);
  36. bool CheckCMP0027 = false;
  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. // Object files linked directly in this configuration.
  45. std::vector<cmLinkItem> Objects;
  46. // Libraries linked directly in other configurations.
  47. // Needed only for OLD behavior of CMP0003.
  48. std::vector<cmLinkItem> WrongConfigLibraries;
  49. // Whether the list depends on a genex referencing the configuration.
  50. bool HadContextSensitiveCondition = false;
  51. };
  52. struct cmLinkInterfaceLibraries
  53. {
  54. // Libraries listed in the interface.
  55. std::vector<cmLinkItem> Libraries;
  56. // Object files listed in the interface.
  57. std::vector<cmLinkItem> Objects;
  58. // Whether the list depends on a genex referencing the head target.
  59. bool HadHeadSensitiveCondition = false;
  60. // Whether the list depends on a genex referencing the configuration.
  61. bool HadContextSensitiveCondition = false;
  62. };
  63. struct cmLinkInterface : public cmLinkInterfaceLibraries
  64. {
  65. // Languages whose runtime libraries must be linked.
  66. std::vector<std::string> Languages;
  67. std::unordered_map<std::string, std::vector<cmLinkItem>>
  68. LanguageRuntimeLibraries;
  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 = 0;
  74. // Libraries listed for other configurations.
  75. // Needed only for OLD behavior of CMP0003.
  76. std::vector<cmLinkItem> WrongConfigLibraries;
  77. bool ImplementationIsInterface = false;
  78. // Whether the list depends on a link language genex.
  79. bool HadLinkLanguageSensitiveCondition = false;
  80. };
  81. struct cmOptionalLinkInterface : public cmLinkInterface
  82. {
  83. bool LibrariesDone = false;
  84. bool AllDone = false;
  85. bool Exists = false;
  86. bool Explicit = false;
  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. std::unordered_map<std::string, std::vector<cmLinkImplItem>>
  97. LanguageRuntimeLibraries;
  98. // Whether the list depends on a link language genex.
  99. bool HadLinkLanguageSensitiveCondition = false;
  100. };
  101. // Cache link implementation computation from each configuration.
  102. struct cmOptionalLinkImplementation : public cmLinkImplementation
  103. {
  104. bool LibrariesDone = false;
  105. bool LanguagesDone = false;
  106. bool HadHeadSensitiveCondition = false;
  107. };
  108. /** Compute the link type to use for the given configuration. */
  109. inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  110. const std::string& config, std::vector<std::string> const& debugConfigs)
  111. {
  112. // No configuration is always optimized.
  113. if (config.empty()) {
  114. return OPTIMIZED_LibraryType;
  115. }
  116. // Check if any entry in the list matches this configuration.
  117. std::string configUpper = cmSystemTools::UpperCase(config);
  118. if (cm::contains(debugConfigs, configUpper)) {
  119. return DEBUG_LibraryType;
  120. }
  121. // The current configuration is not a debug configuration.
  122. return OPTIMIZED_LibraryType;
  123. }