cmSourceFileLocation.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmSourceFileLocation_h
  14. #define cmSourceFileLocation_h
  15. #include "cmStandardIncludes.h"
  16. class cmMakefile;
  17. /** \class cmSourceFileLocation
  18. * \brief cmSourceFileLocation tracks knowledge about a source file location
  19. *
  20. * Source files can be referenced by a variety of names. The
  21. * directory and/or extension may be omitted leading to a certain
  22. * level of ambiguity about the source file location. This class is
  23. * used by cmSourceFile to keep track of what is known about the
  24. * source file location. Each reference may add some information
  25. * about the directory or extension of the file.
  26. */
  27. class cmSourceFileLocation
  28. {
  29. public:
  30. /**
  31. * Construct for a source file created in a given cmMakefile
  32. * instance with an initial name.
  33. */
  34. cmSourceFileLocation(cmMakefile* mf, const char* name);
  35. /**
  36. * Return whether the givne 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 char* GetDirectory() const { return this->Directory.c_str(); }
  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 char* GetName() const { return this->Name.c_str(); }
  71. /**
  72. * Get the cmMakefile instance for which the source file was created.
  73. */
  74. cmMakefile* GetMakefile() const { return this->Makefile; }
  75. private:
  76. cmMakefile* 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 Update(const char* name);
  85. void UpdateExtension(const char* name);
  86. void UpdateDirectory(const char* name);
  87. };
  88. #endif