cmSourceFileLocation.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 cmSourceFileLocation_h
  4. #define cmSourceFileLocation_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. class cmMakefile;
  8. /** \class cmSourceFileLocation
  9. * \brief cmSourceFileLocation tracks knowledge about a source file location
  10. *
  11. * Source files can be referenced by a variety of names. The
  12. * directory and/or extension may be omitted leading to a certain
  13. * level of ambiguity about the source file location. This class is
  14. * used by cmSourceFile to keep track of what is known about the
  15. * source file location. Each reference may add some information
  16. * about the directory or extension of the file.
  17. */
  18. class cmSourceFileLocation
  19. {
  20. public:
  21. /**
  22. * Construct for a source file created in a given cmMakefile
  23. * instance with an initial name.
  24. */
  25. cmSourceFileLocation(cmMakefile const* mf, const std::string& name);
  26. cmSourceFileLocation();
  27. cmSourceFileLocation(const cmSourceFileLocation& loc);
  28. /**
  29. * Return whether the given source file location could refers to the
  30. * same source file as this location given the level of ambiguity in
  31. * each location.
  32. */
  33. bool Matches(cmSourceFileLocation const& loc);
  34. /**
  35. * Explicity state that the source file is located in the source tree.
  36. */
  37. void DirectoryUseSource();
  38. /**
  39. * Explicity state that the source file is located in the build tree.
  40. */
  41. void DirectoryUseBinary();
  42. /**
  43. * Return whether the directory containing the source is ambiguous.
  44. */
  45. bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
  46. /**
  47. * Return whether the extension of the source name is ambiguous.
  48. */
  49. bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
  50. /**
  51. * Get the directory containing the file as best is currently known.
  52. * If DirectoryIsAmbiguous() returns false this will be a full path.
  53. * Otherwise it will be a relative path (possibly empty) that is
  54. * either with respect to the source or build tree.
  55. */
  56. const std::string& GetDirectory() const { return this->Directory; }
  57. /**
  58. * Get the file name as best is currently known. If
  59. * ExtensionIsAmbiguous() returns true this name may not be the
  60. * final name (but could be). Otherwise the returned name is the
  61. * final name.
  62. */
  63. const std::string& GetName() const { return this->Name; }
  64. /**
  65. * Get the cmMakefile instance for which the source file was created.
  66. */
  67. cmMakefile const* GetMakefile() const { return this->Makefile; }
  68. private:
  69. cmMakefile const* const Makefile;
  70. bool AmbiguousDirectory;
  71. bool AmbiguousExtension;
  72. std::string Directory;
  73. std::string Name;
  74. bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
  75. // Update the location with additional knowledge.
  76. void Update(cmSourceFileLocation const& loc);
  77. void UpdateExtension(const std::string& name);
  78. cmSourceFileLocation& operator=(const cmSourceFileLocation& loc) = delete;
  79. };
  80. #endif