Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmDepends.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmDepends_h
13 #define cmDepends_h
14
15 #include "cmStandardIncludes.h"
16
17 class cmFileTimeComparison;
18 class cmLocalGenerator;
19
20 /** \class cmDepends
21  * \brief Dependency scanner superclass.
22  *
23  * This class is responsible for maintaining a .depends.make file in
24  * the build tree corresponding to an object file.  Subclasses help it
25  * maintain dependencies for particular languages.
26  */
27 class cmDepends
28 {
29 public:
30   /** Instances need to know the build directory name and the relative
31       path from the build directory to the target file.  */
32   cmDepends(cmLocalGenerator* lg=0, const char* targetDir="");
33   
34   /** at what level will the compile be done from */
35   void SetCompileDirectory(const char *dir) {this->CompileDirectory = dir;};
36
37   /** Set the local generator for the directory in which we are
38       scanning dependencies.  This is not a full local generator; it
39       has been setup to do relative path conversions for the current
40       directory.  */
41   void SetLocalGenerator(cmLocalGenerator* lg) { this->LocalGenerator = lg; }
42
43   /** Set the specific language to be scanned.  */
44   void SetLanguage(const char* lang) { this->Language = lang; }
45
46   /** Set the target build directory.  */
47   void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
48
49   /** should this be verbose in its output */
50   void SetVerbose(bool verb) { this->Verbose = verb; }
51     
52   /** Virtual destructor to cleanup subclasses properly.  */
53   virtual ~cmDepends();
54
55   /** Write dependencies for the target file.  */
56   bool Write(std::ostream &makeDepends, std::ostream &internalDepends);
57
58   class DependencyVector: public std::vector<std::string> {};
59
60   /** Check dependencies for the target file.  Returns true if
61       dependencies are okay and false if they must be generated.  If
62       they must be generated Clear has already been called to wipe out
63       the old dependencies.
64       Dependencies which are still valid will be stored in validDeps. */
65   bool Check(const char *makeFile, const char* internalFile,
66              std::map<std::string, DependencyVector>& validDeps);
67
68   /** Clear dependencies for the target file so they will be regenerated.  */
69   void Clear(const char *file);
70
71   /** Set the file comparison object */
72   void SetFileComparison(cmFileTimeComparison* fc) { 
73     this->FileComparison = fc; }
74
75 protected:
76
77   // Write dependencies for the target file to the given stream.
78   // Return true for success and false for failure.
79   virtual bool WriteDependencies(const char *src, const char* obj,
80     std::ostream& makeDepends, std::ostream& internalDepends);
81
82   // Check dependencies for the target file in the given stream.
83   // Return false if dependencies must be regenerated and true
84   // otherwise.
85   virtual bool CheckDependencies(std::istream& internalDepends,
86                            std::map<std::string, DependencyVector>& validDeps);
87
88   // Finalize the dependency information for the target.
89   virtual bool Finalize(std::ostream& makeDepends,
90                         std::ostream& internalDepends);
91
92   // The directory in which the build rule for the target file is executed.
93   std::string CompileDirectory;
94
95   // The local generator.
96   cmLocalGenerator* LocalGenerator;
97
98   // Flag for verbose output.
99   bool Verbose;
100   cmFileTimeComparison* FileComparison;
101
102   std::string Language;
103
104   // The full path to the target's build directory.
105   std::string TargetDirectory;
106
107   size_t MaxPath;
108   char* Dependee;
109   char* Depender;
110
111   // The include file search path.
112   std::vector<std::string> IncludePath;
113
114   void SetIncludePathFromLanguage(const char* lang);
115
116 private:
117   cmDepends(cmDepends const&); // Purposely not implemented.
118   void operator=(cmDepends const&); // Purposely not implemented.
119 };
120
121 #endif