cmLinkItem.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <map>
  7. #include <ostream>
  8. #include <string>
  9. #include <vector>
  10. #include "cmAlgorithms.h"
  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 fromGenex);
  36. bool FromGenex = 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. // 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. // Whether the list depends on a genex referencing the head target.
  53. bool HadHeadSensitiveCondition = false;
  54. };
  55. struct cmLinkInterface : public cmLinkInterfaceLibraries
  56. {
  57. // Languages whose runtime libraries must be linked.
  58. std::vector<std::string> Languages;
  59. // Shared library dependencies needed for linking on some platforms.
  60. std::vector<cmLinkItem> SharedDeps;
  61. // Number of repetitions of a strongly connected component of two
  62. // or more static libraries.
  63. unsigned int Multiplicity = 0;
  64. // Libraries listed for other configurations.
  65. // Needed only for OLD behavior of CMP0003.
  66. std::vector<cmLinkItem> WrongConfigLibraries;
  67. bool ImplementationIsInterface = false;
  68. // Whether the list depends on a link language genex.
  69. bool HadLinkLanguageSensitiveCondition = false;
  70. };
  71. struct cmOptionalLinkInterface : public cmLinkInterface
  72. {
  73. bool LibrariesDone = false;
  74. bool AllDone = false;
  75. bool Exists = false;
  76. bool Explicit = false;
  77. };
  78. struct cmHeadToLinkInterfaceMap
  79. : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
  80. {
  81. };
  82. struct cmLinkImplementation : public cmLinkImplementationLibraries
  83. {
  84. // Languages whose runtime libraries must be linked.
  85. std::vector<std::string> Languages;
  86. // Whether the list depends on a link language genex.
  87. bool HadLinkLanguageSensitiveCondition = false;
  88. };
  89. // Cache link implementation computation from each configuration.
  90. struct cmOptionalLinkImplementation : public cmLinkImplementation
  91. {
  92. bool LibrariesDone = false;
  93. bool LanguagesDone = false;
  94. bool HadHeadSensitiveCondition = false;
  95. };
  96. /** Compute the link type to use for the given configuration. */
  97. inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  98. const std::string& config, std::vector<std::string> const& debugConfigs)
  99. {
  100. // No configuration is always optimized.
  101. if (config.empty()) {
  102. return OPTIMIZED_LibraryType;
  103. }
  104. // Check if any entry in the list matches this configuration.
  105. std::string configUpper = cmSystemTools::UpperCase(config);
  106. if (cmContains(debugConfigs, configUpper)) {
  107. return DEBUG_LibraryType;
  108. }
  109. // The current configuration is not a debug configuration.
  110. return OPTIMIZED_LibraryType;
  111. }
  112. #endif