cmGlobVerificationManager.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 cmGlobVerificationManager_h
  4. #define cmGlobVerificationManager_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmListFileCache.h"
  7. #include <iosfwd>
  8. #include <map>
  9. #include <string>
  10. #include <utility>
  11. #include <vector>
  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. public:
  21. cmGlobVerificationManager() {}
  22. protected:
  23. ///! Save verification script for given makefile.
  24. ///! Saves to output <path>/<CMakeFilesDirectory>/VerifyGlobs.cmake
  25. bool SaveVerificationScript(const std::string& path);
  26. ///! Add an entry into the glob cache
  27. void AddCacheEntry(bool recurse, bool listDirectories, bool followSymlinks,
  28. const std::string& relative,
  29. const std::string& expression,
  30. const std::vector<std::string>& files,
  31. const std::string& variable,
  32. const cmListFileBacktrace& bt);
  33. ///! Clear the glob cache for state reset.
  34. void Reset();
  35. ///! Check targets should be written in generated build system.
  36. bool DoWriteVerifyTarget() const;
  37. ///! Get the paths to the generated script and stamp files
  38. std::string const& GetVerifyScript() const { return this->VerifyScript; }
  39. std::string const& GetVerifyStamp() const { return this->VerifyStamp; }
  40. private:
  41. struct CacheEntryKey
  42. {
  43. const bool Recurse;
  44. const bool ListDirectories;
  45. const bool FollowSymlinks;
  46. const std::string Relative;
  47. const std::string Expression;
  48. CacheEntryKey(const bool rec, const bool l, const bool s,
  49. const std::string& rel, const std::string& e)
  50. : Recurse(rec)
  51. , ListDirectories(l)
  52. , FollowSymlinks(s)
  53. , Relative(rel)
  54. , Expression(e)
  55. {
  56. }
  57. bool operator<(const CacheEntryKey& r) const;
  58. void PrintGlobCommand(std::ostream& out, const std::string& cmdVar);
  59. };
  60. struct CacheEntryValue
  61. {
  62. bool Initialized = false;
  63. std::vector<std::string> Files;
  64. std::vector<std::pair<std::string, cmListFileBacktrace>> Backtraces;
  65. CacheEntryValue() {}
  66. };
  67. typedef std::map<CacheEntryKey, CacheEntryValue> CacheEntryMap;
  68. CacheEntryMap Cache;
  69. std::string VerifyScript;
  70. std::string VerifyStamp;
  71. // Only cmState should be able to add cache values.
  72. // cmGlobVerificationManager should never be used directly.
  73. friend class cmState; // allow access to add cache values
  74. };
  75. #endif