cmLinkItem.cxx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmLinkItem.h"
  4. #include "cmGeneratorTarget.h"
  5. #include <utility> // IWYU pragma: keep
  6. cmLinkItem::cmLinkItem()
  7. : Target(nullptr)
  8. {
  9. }
  10. cmLinkItem::cmLinkItem(std::string const& n, cmListFileBacktrace const& bt)
  11. : String(n)
  12. , Target(nullptr)
  13. , Backtrace(bt)
  14. {
  15. }
  16. cmLinkItem::cmLinkItem(cmGeneratorTarget const* t,
  17. cmListFileBacktrace const& bt)
  18. : Target(t)
  19. , Backtrace(bt)
  20. {
  21. }
  22. std::string const& cmLinkItem::AsStr() const
  23. {
  24. return this->Target ? this->Target->GetName() : this->String;
  25. }
  26. bool operator<(cmLinkItem const& l, cmLinkItem const& r)
  27. {
  28. // Order among targets.
  29. if (l.Target && r.Target) {
  30. return l.Target < r.Target;
  31. }
  32. // Order targets before strings.
  33. if (l.Target) {
  34. return true;
  35. }
  36. if (r.Target) {
  37. return false;
  38. }
  39. // Order among strings.
  40. return l.String < r.String;
  41. }
  42. bool operator==(cmLinkItem const& l, cmLinkItem const& r)
  43. {
  44. return l.Target == r.Target && l.String == r.String;
  45. }
  46. std::ostream& operator<<(std::ostream& os, cmLinkItem const& item)
  47. {
  48. return os << item.AsStr();
  49. }
  50. cmLinkImplItem::cmLinkImplItem()
  51. : cmLinkItem()
  52. , FromGenex(false)
  53. {
  54. }
  55. cmLinkImplItem::cmLinkImplItem(cmLinkItem item, bool fromGenex)
  56. : cmLinkItem(std::move(item))
  57. , FromGenex(fromGenex)
  58. {
  59. }