cmSourceFileLocation.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. cmSourceFileLocation& operator=(const cmSourceFileLocation& loc);
  29. /**
  30. * Return whether the given source file location could refers to the
  31. * same source file as this location given the level of ambiguity in
  32. * each location.
  33. */
  34. bool Matches(cmSourceFileLocation const& loc);
  35. /**
  36. * Explicity state that the source file is located in the source tree.
  37. */
  38. void DirectoryUseSource();
  39. /**
  40. * Explicity state that the source file is located in the build tree.
  41. */
  42. void DirectoryUseBinary();
  43. /**
  44. * Return whether the directory containing the source is ambiguous.
  45. */
  46. bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
  47. /**
  48. * Return whether the extension of the source name is ambiguous.
  49. */
  50. bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
  51. /**
  52. * Get the directory containing the file as best is currently known.
  53. * If DirectoryIsAmbiguous() returns false this will be a full path.
  54. * Otherwise it will be a relative path (possibly empty) that is
  55. * either with respect to the source or build tree.
  56. */
  57. const std::string& GetDirectory() const { return this->Directory; }
  58. /**
  59. * Get the file name as best is currently known. If
  60. * ExtensionIsAmbiguous() returns true this name may not be the
  61. * final name (but could be). Otherwise the returned name is the
  62. * final name.
  63. */
  64. const std::string& GetName() const { return this->Name; }
  65. /**
  66. * Get the cmMakefile instance for which the source file was created.
  67. */
  68. cmMakefile const* GetMakefile() const { return this->Makefile; }
  69. private:
  70. cmMakefile const* Makefile;
  71. bool AmbiguousDirectory;
  72. bool AmbiguousExtension;
  73. std::string Directory;
  74. std::string Name;
  75. bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
  76. // Update the location with additional knowledge.
  77. void Update(cmSourceFileLocation const& loc);
  78. void UpdateExtension(const std::string& name);
  79. };
  80. #endif