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