cmLinkItem.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 s, cmListFileBacktrace bt);
  22. cmLinkItem(cmGeneratorTarget const* t, cmListFileBacktrace bt);
  23. std::string const& AsStr() const;
  24. cmGeneratorTarget const* Target = nullptr;
  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 = false;
  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 = 0;
  61. // Libraries listed for other configurations.
  62. // Needed only for OLD behavior of CMP0003.
  63. std::vector<cmLinkItem> WrongConfigLibraries;
  64. bool ImplementationIsInterface = false;
  65. cmLinkInterface() {}
  66. };
  67. struct cmOptionalLinkInterface : public cmLinkInterface
  68. {
  69. cmOptionalLinkInterface() {}
  70. bool LibrariesDone = false;
  71. bool AllDone = false;
  72. bool Exists = false;
  73. bool HadHeadSensitiveCondition = false;
  74. const char* ExplicitLibraries = nullptr;
  75. };
  76. struct cmHeadToLinkInterfaceMap
  77. : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
  78. {
  79. };
  80. struct cmLinkImplementation : public cmLinkImplementationLibraries
  81. {
  82. // Languages whose runtime libraries must be linked.
  83. std::vector<std::string> Languages;
  84. };
  85. // Cache link implementation computation from each configuration.
  86. struct cmOptionalLinkImplementation : public cmLinkImplementation
  87. {
  88. cmOptionalLinkImplementation() {}
  89. bool LibrariesDone = false;
  90. bool LanguagesDone = false;
  91. bool HadHeadSensitiveCondition = false;
  92. };
  93. /** Compute the link type to use for the given configuration. */
  94. inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
  95. const std::string& config, std::vector<std::string> const& debugConfigs)
  96. {
  97. // No configuration is always optimized.
  98. if (config.empty()) {
  99. return OPTIMIZED_LibraryType;
  100. }
  101. // Check if any entry in the list matches this configuration.
  102. std::string configUpper = cmSystemTools::UpperCase(config);
  103. if (std::find(debugConfigs.begin(), debugConfigs.end(), configUpper) !=
  104. debugConfigs.end()) {
  105. return DEBUG_LibraryType;
  106. }
  107. // The current configuration is not a debug configuration.
  108. return OPTIMIZED_LibraryType;
  109. }
  110. #endif