1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
9 #include "cmSourceFileLocationKind.h"
13 /** \class cmSourceFileLocation
14 * \brief cmSourceFileLocation tracks knowledge about a source file location
16 * Source files can be referenced by a variety of names. The
17 * directory and/or extension may be omitted leading to a certain
18 * level of ambiguity about the source file location. This class is
19 * used by cmSourceFile to keep track of what is known about the
20 * source file location. Each reference may add some information
21 * about the directory or extension of the file.
23 class cmSourceFileLocation
27 * Construct for a source file created in a given cmMakefile
28 * instance with an initial name.
31 cmMakefile const* mf, const std::string& name,
32 cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
33 cmSourceFileLocation();
34 cmSourceFileLocation(const cmSourceFileLocation& loc);
36 cmSourceFileLocation& operator=(cmSourceFileLocation const&) = delete;
39 * Return whether the given source file location could refers to the
40 * same source file as this location given the level of ambiguity in
43 bool Matches(cmSourceFileLocation const& loc);
46 * Explicitly state that the source file is located in the source tree.
48 void DirectoryUseSource();
51 * Explicitly state that the source file is located in the build tree.
53 void DirectoryUseBinary();
56 * Return whether the directory containing the source is ambiguous.
58 bool DirectoryIsAmbiguous() const { return this->AmbiguousDirectory; }
61 * Return whether the extension of the source name is ambiguous.
63 bool ExtensionIsAmbiguous() const { return this->AmbiguousExtension; }
66 * Get the directory containing the file as best is currently known.
67 * If DirectoryIsAmbiguous() returns false this will be a full path.
68 * Otherwise it will be a relative path (possibly empty) that is
69 * either with respect to the source or build tree.
71 const std::string& GetDirectory() const { return this->Directory; }
74 * Get the file name as best is currently known. If
75 * ExtensionIsAmbiguous() returns true this name may not be the
76 * final name (but could be). Otherwise the returned name is the
79 const std::string& GetName() const { return this->Name; }
82 * Get the full file path composed of GetDirectory() and GetName().
84 std::string GetFullPath() const;
87 * Get the cmMakefile instance for which the source file was created.
89 cmMakefile const* GetMakefile() const { return this->Makefile; }
92 cmMakefile const* const Makefile = nullptr;
93 bool AmbiguousDirectory = true;
94 bool AmbiguousExtension = true;
95 std::string Directory;
98 bool MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const;
100 // Update the location with additional knowledge.
101 void Update(cmSourceFileLocation const& loc);
102 void UpdateExtension(const std::string& name);