cmDependsC.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // Implement writing/checking methods required by superclass.
  30. virtual bool WriteDependencies(const std::set<std::string>& sources,
  31. const std::string& obj,
  32. std::ostream& makeDepends,
  33. std::ostream& internalDepends);
  34. // Method to scan a single file.
  35. void Scan(std::istream& is, const char* directory,
  36. const cmStdString& fullName);
  37. // Regular expression to identify C preprocessor include directives.
  38. cmsys::RegularExpression IncludeRegexLine;
  39. // Regular expressions to choose which include files to scan
  40. // recursively and which to complain about not finding.
  41. cmsys::RegularExpression IncludeRegexScan;
  42. cmsys::RegularExpression IncludeRegexComplain;
  43. std::string IncludeRegexLineString;
  44. std::string IncludeRegexScanString;
  45. std::string IncludeRegexComplainString;
  46. // Regex to transform #include lines.
  47. std::string IncludeRegexTransformString;
  48. cmsys::RegularExpression IncludeRegexTransform;
  49. typedef std::map<cmStdString, cmStdString> TransformRulesType;
  50. TransformRulesType TransformRules;
  51. void SetupTransforms();
  52. void ParseTransform(std::string const& xform);
  53. void TransformLine(std::string& line);
  54. public:
  55. // Data structures for dependency graph walk.
  56. struct UnscannedEntry
  57. {
  58. cmStdString FileName;
  59. cmStdString QuotedLocation;
  60. };
  61. struct cmIncludeLines
  62. {
  63. cmIncludeLines(): Used(false) {}
  64. std::vector<UnscannedEntry> UnscannedEntries;
  65. bool Used;
  66. };
  67. protected:
  68. const std::map<std::string, DependencyVector>* ValidDeps;
  69. std::set<cmStdString> Encountered;
  70. std::queue<UnscannedEntry> Unscanned;
  71. std::map<cmStdString, cmIncludeLines *> FileCache;
  72. std::map<cmStdString, cmStdString> HeaderLocationCache;
  73. cmStdString CacheFileName;
  74. void WriteCacheFile() const;
  75. void ReadCacheFile();
  76. private:
  77. cmDependsC(cmDependsC const&); // Purposely not implemented.
  78. void operator=(cmDependsC const&); // Purposely not implemented.
  79. };
  80. #endif