Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmDependsC.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 cmDependsC_h
13 #define cmDependsC_h
14
15 #include "cmDepends.h"
16 #include <cmsys/RegularExpression.hxx>
17 #include <queue>
18
19 /** \class cmDependsC
20  * \brief Dependency scanner for C and C++ object files.
21  */
22 class cmDependsC: public cmDepends
23 {
24 public:
25   /** Checking instances need to know the build directory name and the
26       relative path from the build directory to the target file.  */
27   cmDependsC();
28   cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang,
29              const std::map<std::string, DependencyVector>* validDeps);
30
31   /** Virtual destructor to cleanup subclasses properly.  */
32   virtual ~cmDependsC();
33
34 protected:
35   // Implement writing/checking methods required by superclass.
36   virtual bool WriteDependencies(const std::set<std::string>& sources,
37                                  const std::string&           obj,
38                                  std::ostream& makeDepends,
39                                  std::ostream& internalDepends);
40
41   // Method to scan a single file.
42   void Scan(std::istream& is, const char* directory,
43     const cmStdString& fullName);
44
45   // Regular expression to identify C preprocessor include directives.
46   cmsys::RegularExpression IncludeRegexLine;
47
48   // Regular expressions to choose which include files to scan
49   // recursively and which to complain about not finding.
50   cmsys::RegularExpression IncludeRegexScan;
51   cmsys::RegularExpression IncludeRegexComplain;
52   std::string IncludeRegexLineString;
53   std::string IncludeRegexScanString;
54   std::string IncludeRegexComplainString;
55
56   // Regex to transform #include lines.
57   std::string IncludeRegexTransformString;
58   cmsys::RegularExpression IncludeRegexTransform;
59   typedef std::map<cmStdString, cmStdString> TransformRulesType;
60   TransformRulesType TransformRules;
61   void SetupTransforms();
62   void ParseTransform(std::string const& xform);
63   void TransformLine(std::string& line);
64
65 public:
66   // Data structures for dependency graph walk.
67   struct UnscannedEntry
68   {
69     cmStdString FileName;
70     cmStdString QuotedLocation;
71   };
72
73   struct cmIncludeLines
74   {
75     cmIncludeLines(): Used(false) {}
76     std::vector<UnscannedEntry> UnscannedEntries;
77     bool Used;
78   };
79 protected:
80   const std::map<std::string, DependencyVector>* ValidDeps;
81   std::set<cmStdString> Encountered;
82   std::queue<UnscannedEntry> Unscanned;
83
84   std::map<cmStdString, cmIncludeLines *> FileCache;
85   std::map<cmStdString, cmStdString> HeaderLocationCache;
86
87   cmStdString CacheFileName;
88
89   void WriteCacheFile() const;
90   void ReadCacheFile();
91 private:
92   cmDependsC(cmDependsC const&); // Purposely not implemented.
93   void operator=(cmDependsC const&); // Purposely not implemented.
94 };
95
96 #endif