resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmDepends.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 <set>
10 #include <string>
11 #include <vector>
12
13 class cmFileTimeCache;
14 class cmLocalUnixMakefileGenerator3;
15
16 /** \class cmDepends
17  * \brief Dependency scanner superclass.
18  *
19  * This class is responsible for maintaining a .depends.make file in
20  * the build tree corresponding to an object file.  Subclasses help it
21  * maintain dependencies for particular languages.
22  */
23 class cmDepends
24 {
25 public:
26   using DependencyMap = std::map<std::string, std::vector<std::string>>;
27
28   /** Instances need to know the build directory name and the relative
29       path from the build directory to the target file.  */
30   cmDepends(cmLocalUnixMakefileGenerator3* lg = nullptr,
31             std::string targetDir = "");
32
33   cmDepends(cmDepends const&) = delete;
34   cmDepends& operator=(cmDepends const&) = delete;
35
36   /** Set the local generator for the directory in which we are
37       scanning dependencies.  This is not a full local generator; it
38       has been setup to do relative path conversions for the current
39       directory.  */
40   void SetLocalGenerator(cmLocalUnixMakefileGenerator3* lg)
41   {
42     this->LocalGenerator = lg;
43   }
44
45   /** Set the specific language to be scanned.  */
46   void SetLanguage(const std::string& lang) { this->Language = lang; }
47
48   /** Set the target build directory.  */
49   void SetTargetDirectory(const std::string& dir)
50   {
51     this->TargetDirectory = dir;
52   }
53
54   /** should this be verbose in its output */
55   void SetVerbose(bool verb) { this->Verbose = verb; }
56
57   /** Virtual destructor to cleanup subclasses properly.  */
58   virtual ~cmDepends();
59
60   /** Write dependencies for the target file.  */
61   bool Write(std::ostream& makeDepends, std::ostream& internalDepends);
62
63   /** Check dependencies for the target file.  Returns true if
64       dependencies are okay and false if they must be generated.  If
65       they must be generated Clear has already been called to wipe out
66       the old dependencies.
67       Dependencies which are still valid will be stored in validDeps. */
68   bool Check(const std::string& makeFile, const std::string& internalFile,
69              DependencyMap& validDeps);
70
71   /** Clear dependencies for the target file so they will be regenerated.  */
72   void Clear(const std::string& file) const;
73
74   /** Set the file comparison object */
75   void SetFileTimeCache(cmFileTimeCache* fc) { this->FileTimeCache = fc; }
76
77 protected:
78   // Write dependencies for the target file to the given stream.
79   // Return true for success and false for failure.
80   virtual bool WriteDependencies(const std::set<std::string>& sources,
81                                  const std::string& obj,
82                                  std::ostream& makeDepends,
83                                  std::ostream& internalDepends);
84
85   // Check dependencies for the target file in the given stream.
86   // Return false if dependencies must be regenerated and true
87   // otherwise.
88   virtual bool CheckDependencies(std::istream& internalDepends,
89                                  const std::string& internalDependsFileName,
90                                  DependencyMap& validDeps);
91
92   // Finalize the dependency information for the target.
93   virtual bool Finalize(std::ostream& makeDepends,
94                         std::ostream& internalDepends);
95
96   // The local generator.
97   cmLocalUnixMakefileGenerator3* LocalGenerator;
98
99   // Flag for verbose output.
100   bool Verbose = false;
101   cmFileTimeCache* FileTimeCache = nullptr;
102
103   std::string Language;
104
105   // The full path to the target's build directory.
106   std::string TargetDirectory;
107
108   // The include file search path.
109   std::vector<std::string> IncludePath;
110
111   void SetIncludePathFromLanguage(const std::string& lang);
112 };