cmDependsC.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <iosfwd>
  7. #include <map>
  8. #include <queue>
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. #include "cmsys/RegularExpression.hxx"
  13. #include "cmDepends.h"
  14. class cmLocalUnixMakefileGenerator3;
  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(cmLocalUnixMakefileGenerator3* lg, const std::string& targetDir,
  25. const std::string& lang, const DependencyMap* validDeps);
  26. /** Virtual destructor to cleanup subclasses properly. */
  27. ~cmDependsC() override;
  28. cmDependsC(cmDependsC const&) = delete;
  29. cmDependsC& operator=(cmDependsC const&) = delete;
  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 std::string& 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. using TransformRulesType = std::map<std::string, std::string>;
  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. std::vector<UnscannedEntry> UnscannedEntries;
  65. bool Used = false;
  66. };
  67. protected:
  68. const DependencyMap* ValidDeps = nullptr;
  69. std::set<std::string> Encountered;
  70. std::queue<UnscannedEntry> Unscanned;
  71. std::map<std::string, cmIncludeLines> FileCache;
  72. std::map<std::string, std::string> HeaderLocationCache;
  73. std::string CacheFileName;
  74. void WriteCacheFile() const;
  75. void ReadCacheFile();
  76. };
  77. #endif