cmSourceFileLocation.h 3.3 KB

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