cmDependsC.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmDependsC_h
  14. #define cmDependsC_h
  15. #include "cmDepends.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. #include <queue>
  18. /** \class cmDependsC
  19. * \brief Dependency scanner for C and C++ object files.
  20. */
  21. class cmDependsC: public cmDepends
  22. {
  23. public:
  24. /** Checking instances need to know the build directory name and the
  25. relative path from the build directory to the target file. */
  26. cmDependsC();
  27. cmDependsC(std::vector<std::string> const& includes,
  28. const char* scanRegex, const char* complainRegex,
  29. std::set<cmStdString> const& generatedFiles,
  30. const cmStdString& cachFileName);
  31. /** Virtual destructor to cleanup subclasses properly. */
  32. virtual ~cmDependsC();
  33. protected:
  34. typedef std::vector<char> t_CharBuffer;
  35. // Implement writing/checking methods required by superclass.
  36. virtual bool WriteDependencies(const char *src,
  37. const char *file,
  38. std::ostream& makeDepends,
  39. std::ostream& internalDepends);
  40. // Method to scan a single file.
  41. void Scan(std::istream& is, const char* directory,
  42. const cmStdString& fullName);
  43. // Method to test for the existence of a file.
  44. bool FileExistsOrIsGenerated(const std::string& fname,
  45. std::set<cmStdString>& scanned,
  46. std::set<cmStdString>& dependencies);
  47. bool FileIsGenerated(const std::string& fname,
  48. std::set<cmStdString>& scanned,
  49. std::set<cmStdString>& dependencies);
  50. // The include file search path.
  51. std::vector<std::string> const* IncludePath;
  52. // Regular expression to identify C preprocessor include directives.
  53. cmsys::RegularExpression IncludeRegexLine;
  54. // Regular expressions to choose which include files to scan
  55. // recursively and which to complain about not finding.
  56. cmsys::RegularExpression IncludeRegexScan;
  57. cmsys::RegularExpression IncludeRegexComplain;
  58. // Set of generated files available.
  59. std::set<cmStdString> const* GeneratedFiles;
  60. public:
  61. // Data structures for dependency graph walk.
  62. struct UnscannedEntry
  63. {
  64. cmStdString FileName;
  65. cmStdString QuotedLocation;
  66. };
  67. struct cmIncludeLines
  68. {
  69. cmIncludeLines(): Used(false) {}
  70. std::vector<UnscannedEntry> UnscannedEntries;
  71. bool Used;
  72. };
  73. protected:
  74. std::set<cmStdString> Encountered;
  75. std::queue<UnscannedEntry> Unscanned;
  76. t_CharBuffer Buffer;
  77. std::map<cmStdString, cmIncludeLines *> fileCache;
  78. cmStdString CacheFileName;
  79. void WriteCacheFile() const;
  80. void ReadCacheFile();
  81. private:
  82. cmDependsC(cmDependsC const&); // Purposely not implemented.
  83. void operator=(cmDependsC const&); // Purposely not implemented.
  84. };
  85. #endif