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