cmDependsC.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmDependsC_h
  4. #define cmDependsC_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmDepends.h"
  7. #include "cmsys/RegularExpression.hxx"
  8. #include <iosfwd>
  9. #include <map>
  10. #include <queue>
  11. #include <set>
  12. #include <string>
  13. #include <vector>
  14. class cmLocalGenerator;
  15. /** \class cmDependsC
  16. * \brief Dependency scanner for C and C++ object files.
  17. */
  18. class cmDependsC : public cmDepends
  19. {
  20. CM_DISABLE_COPY(cmDependsC)
  21. public:
  22. /** Checking instances need to know the build directory name and the
  23. relative path from the build directory to the target file. */
  24. cmDependsC();
  25. cmDependsC(cmLocalGenerator* lg, const char* targetDir,
  26. const std::string& lang,
  27. const std::map<std::string, DependencyVector>* validDeps);
  28. /** Virtual destructor to cleanup subclasses properly. */
  29. ~cmDependsC() override;
  30. protected:
  31. // Implement writing/checking methods required by superclass.
  32. bool WriteDependencies(const std::set<std::string>& sources,
  33. const std::string& obj, std::ostream& makeDepends,
  34. std::ostream& internalDepends) override;
  35. // Method to scan a single file.
  36. void Scan(std::istream& is, const char* directory,
  37. const std::string& 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<std::string, std::string> 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. std::string FileName;
  60. std::string QuotedLocation;
  61. };
  62. struct cmIncludeLines
  63. {
  64. cmIncludeLines()
  65. : Used(false)
  66. {
  67. }
  68. std::vector<UnscannedEntry> UnscannedEntries;
  69. bool Used;
  70. };
  71. protected:
  72. const std::map<std::string, DependencyVector>* ValidDeps;
  73. std::set<std::string> Encountered;
  74. std::queue<UnscannedEntry> Unscanned;
  75. std::map<std::string, cmIncludeLines*> FileCache;
  76. std::map<std::string, std::string> HeaderLocationCache;
  77. std::string CacheFileName;
  78. void WriteCacheFile() const;
  79. void ReadCacheFile();
  80. };
  81. #endif