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