cmFindPackageStack.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <memory>
  6. #include <string>
  7. #include "cmStack.h"
  8. class cmMakefile;
  9. /**
  10. * Represents one call to find_package.
  11. */
  12. class cmFindPackageCall
  13. {
  14. public:
  15. std::string Name;
  16. unsigned int Index;
  17. };
  18. /**
  19. * RAII type to manage the find_package call stack.
  20. */
  21. // Note: implemented in cmMakefile.cxx
  22. class cmFindPackageStackRAII
  23. {
  24. cmMakefile* Makefile;
  25. cmFindPackageCall** Value = nullptr;
  26. public:
  27. cmFindPackageStackRAII(cmMakefile* mf, std::string const& pkg);
  28. ~cmFindPackageStackRAII();
  29. cmFindPackageStackRAII(cmFindPackageStackRAII const&) = delete;
  30. cmFindPackageStackRAII& operator=(cmFindPackageStackRAII const&) = delete;
  31. /** Get a mutable pointer to the top of the stack.
  32. The pointer is invalidated if BindTop is called again or when the
  33. cmFindPackageStackRAII goes out of scope. */
  34. void BindTop(cmFindPackageCall*& value);
  35. };
  36. /**
  37. * Represents a stack of find_package calls with efficient value semantics.
  38. */
  39. class cmFindPackageStack
  40. : protected cmStack<cmFindPackageCall, cmFindPackageStack>
  41. {
  42. using cmStack::cmStack;
  43. friend cmFindPackageStack::Base;
  44. friend class cmFindPackageStackRAII;
  45. public:
  46. using cmStack::Push;
  47. using cmStack::Pop;
  48. using cmStack::Empty;
  49. cmFindPackageCall const& Top() const;
  50. };
  51. #ifndef cmFindPackageStack_cxx
  52. extern template class cmStack<cmFindPackageCall, cmFindPackageStack>;
  53. extern template cmFindPackageCall&
  54. cmStack<cmFindPackageCall, cmFindPackageStack>::Top<true>();
  55. #endif