cmSourceFileLocation.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmSourceFileLocation_h
  11. #define cmSourceFileLocation_h
  12. #include "cmStandardIncludes.h"
  13. class cmMakefile;
  14. /** \class cmSourceFileLocation
  15. * \brief cmSourceFileLocation tracks knowledge about a source file location
  16. *
  17. * Source files can be referenced by a variety of names. The
  18. * directory and/or extension may be omitted leading to a certain
  19. * level of ambiguity about the source file location. This class is
  20. * used by cmSourceFile to keep track of what is known about the
  21. * source file location. Each reference may add some information
  22. * about the directory or extension of the file.
  23. */
  24. class cmSourceFileLocation
  25. {
  26. public:
  27. /**
  28. * Construct for a source file created in a given cmMakefile
  29. * instance with an initial name.
  30. */
  31. cmSourceFileLocation(cmMakefile const* mf, const std::string& name);
  32. cmSourceFileLocation();
  33. cmSourceFileLocation(const cmSourceFileLocation& loc);
  34. cmSourceFileLocation& operator=(const cmSourceFileLocation& loc);
  35. /**
  36. * Return whether the given source file location could refers to the
  37. * same source file as this location given the level of ambiguity in
  38. * each location.
  39. */
  40. bool Matches(cmSourceFileLocation const& loc);
  41. /**
  42. * Explicity state that the source file is located in the source tree.
  43. */
  44. void DirectoryUseSource();
  45. /**
  46. * Explicity state that the source file is located in the build tree.
  47. */
  48. void DirectoryUseBinary();
  49. /**
  50. * Return whether the directory containing the source is ambiguous.
  51. */
  52. bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
  53. /**
  54. * Return whether the extension of the source name is ambiguous.
  55. */
  56. bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
  57. /**
  58. * Get the directory containing the file as best is currently known.
  59. * If DirectoryIsAmbiguous() returns false this will be a full path.
  60. * Otherwise it will be a relative path (possibly empty) that is
  61. * either with respect to the source or build tree.
  62. */
  63. const std::string& GetDirectory() const { return this->Directory; }
  64. /**
  65. * Get the file name as best is currently known. If
  66. * ExtensionIsAmbiguous() returns true this name may not be the
  67. * final name (but could be). Otherwise the returned name is the
  68. * final name.
  69. */
  70. const std::string& GetName() const { return this->Name; }
  71. /**
  72. * Get the cmMakefile instance for which the source file was created.
  73. */
  74. cmMakefile const* GetMakefile() const { return this->Makefile; }
  75. private:
  76. cmMakefile const* Makefile;
  77. bool AmbiguousDirectory;
  78. bool AmbiguousExtension;
  79. std::string Directory;
  80. std::string Name;
  81. bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
  82. // Update the location with additional knowledge.
  83. void Update(cmSourceFileLocation const& loc);
  84. void UpdateExtension(const std::string& name);
  85. };
  86. #endif