cmGlobVerificationManager.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <iosfwd>
  6. #include <map>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "cmListFileCache.h"
  11. class cmMessenger;
  12. /** \class cmGlobVerificationManager
  13. * \brief Class for expressing build-time dependencies on glob expressions.
  14. *
  15. * Generates a CMake script which verifies glob outputs during prebuild.
  16. *
  17. */
  18. class cmGlobVerificationManager
  19. {
  20. protected:
  21. //! Save verification script for given makefile.
  22. //! Saves to output <path>/<CMakeFilesDirectory>/VerifyGlobs.cmake
  23. bool SaveVerificationScript(const std::string& path, cmMessenger* messenger);
  24. //! Add an entry into the glob cache
  25. void AddCacheEntry(bool recurse, bool listDirectories, bool followSymlinks,
  26. const std::string& relative,
  27. const std::string& expression,
  28. const std::vector<std::string>& files,
  29. const std::string& variable,
  30. const cmListFileBacktrace& bt, cmMessenger* messenger);
  31. //! Clear the glob cache for state reset.
  32. void Reset();
  33. //! Check targets should be written in generated build system.
  34. bool DoWriteVerifyTarget() const;
  35. //! Get the paths to the generated script and stamp files
  36. std::string const& GetVerifyScript() const { return this->VerifyScript; }
  37. std::string const& GetVerifyStamp() const { return this->VerifyStamp; }
  38. private:
  39. struct CacheEntryKey
  40. {
  41. const bool Recurse;
  42. const bool ListDirectories;
  43. const bool FollowSymlinks;
  44. const std::string Relative;
  45. const std::string Expression;
  46. CacheEntryKey(const bool rec, const bool l, const bool s, std::string rel,
  47. std::string e)
  48. : Recurse(rec)
  49. , ListDirectories(l)
  50. , FollowSymlinks(s)
  51. , Relative(std::move(rel))
  52. , Expression(std::move(e))
  53. {
  54. }
  55. bool operator<(const CacheEntryKey& r) const;
  56. void PrintGlobCommand(std::ostream& out, const std::string& cmdVar);
  57. };
  58. struct CacheEntryValue
  59. {
  60. bool Initialized = false;
  61. std::vector<std::string> Files;
  62. std::vector<std::pair<std::string, cmListFileBacktrace>> Backtraces;
  63. };
  64. using CacheEntryMap = std::map<CacheEntryKey, CacheEntryValue>;
  65. CacheEntryMap Cache;
  66. std::string VerifyScript;
  67. std::string VerifyStamp;
  68. // Only cmState should be able to add cache values.
  69. // cmGlobVerificationManager should never be used directly.
  70. friend class cmState; // allow access to add cache values
  71. };