cmDependsC.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmDependsC_h
  11. #define cmDependsC_h
  12. #include "cmDepends.h"
  13. #include <cmsys/RegularExpression.hxx>
  14. #include <queue>
  15. /** \class cmDependsC
  16. * \brief Dependency scanner for C and C++ object files.
  17. */
  18. class cmDependsC: public cmDepends
  19. {
  20. public:
  21. /** Checking instances need to know the build directory name and the
  22. relative path from the build directory to the target file. */
  23. cmDependsC();
  24. cmDependsC(cmLocalGenerator* lg, const char* targetDir, const char* lang,
  25. const std::map<std::string, DependencyVector>* validDeps);
  26. /** Virtual destructor to cleanup subclasses properly. */
  27. virtual ~cmDependsC();
  28. protected:
  29. typedef std::vector<char> t_CharBuffer;
  30. // Implement writing/checking methods required by superclass.
  31. virtual bool WriteDependencies(const char *src,
  32. const char *file,
  33. std::ostream& makeDepends,
  34. std::ostream& internalDepends);
  35. // Method to scan a single file.
  36. void Scan(std::istream& is, const char* directory,
  37. const cmStdString& fullName);
  38. // Regular expression to identify C preprocessor include directives.
  39. cmsys::RegularExpression IncludeRegexLine;
  40. // Regular expressions to choose which include files to scan
  41. // recursively and which to complain about not finding.
  42. cmsys::RegularExpression IncludeRegexScan;
  43. cmsys::RegularExpression IncludeRegexComplain;
  44. std::string IncludeRegexLineString;
  45. std::string IncludeRegexScanString;
  46. std::string IncludeRegexComplainString;
  47. // Regex to transform #include lines.
  48. std::string IncludeRegexTransformString;
  49. cmsys::RegularExpression IncludeRegexTransform;
  50. typedef std::map<cmStdString, cmStdString> TransformRulesType;
  51. TransformRulesType TransformRules;
  52. void SetupTransforms();
  53. void ParseTransform(std::string const& xform);
  54. void TransformLine(std::string& line);
  55. public:
  56. // Data structures for dependency graph walk.
  57. struct UnscannedEntry
  58. {
  59. cmStdString FileName;
  60. cmStdString QuotedLocation;
  61. };
  62. struct cmIncludeLines
  63. {
  64. cmIncludeLines(): Used(false) {}
  65. std::vector<UnscannedEntry> UnscannedEntries;
  66. bool Used;
  67. };
  68. protected:
  69. const std::map<std::string, DependencyVector>* ValidDeps;
  70. std::set<cmStdString> Encountered;
  71. std::queue<UnscannedEntry> Unscanned;
  72. t_CharBuffer Buffer;
  73. std::map<cmStdString, cmIncludeLines *> FileCache;
  74. std::map<cmStdString, cmStdString> HeaderLocationCache;
  75. cmStdString CacheFileName;
  76. void WriteCacheFile() const;
  77. void ReadCacheFile();
  78. private:
  79. cmDependsC(cmDependsC const&); // Purposely not implemented.
  80. void operator=(cmDependsC const&); // Purposely not implemented.
  81. };
  82. #endif