MCPcopy Create free account
hub / github.com/Kitware/CMake / UpdateExtension

Method UpdateExtension

Source/cmSourceFileLocation.cxx:102–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void cmSourceFileLocation::UpdateExtension(std::string const& name)
103{
104 assert(this->Makefile);
105 // Check the extension.
106 cm::string_view ext = cmSystemTools::GetFilenameLastExtensionView(name);
107 if (!ext.empty()) {
108 ext = ext.substr(1);
109 }
110
111 // The global generator checks extensions of enabled languages.
112 cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
113 cmMakefile const* mf = this->Makefile;
114 auto* cm = mf->GetCMakeInstance();
115 if (!gg->GetLanguageFromExtension(ext).empty() ||
116 cm->IsAKnownExtension(ext)) {
117 // This is a known extension. Use the given filename with extension.
118 this->Name = cmSystemTools::GetFilenameName(name);
119 this->AmbiguousExtension = false;
120 } else {
121 // This is not a known extension. See if the file exists on disk as
122 // named.
123 std::string tryPath;
124 if (this->AmbiguousDirectory) {
125 // Check the source tree only because a file in the build tree should
126 // be specified by full path at least once. We do not want this
127 // detection to depend on whether the project has already been built.
128 tryPath = cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/');
129 }
130 if (!this->Directory.empty()) {
131 tryPath += this->Directory;
132 tryPath += "/";
133 }
134 tryPath += this->Name;
135 if (cmSystemTools::FileExists(tryPath, true)) {
136 // We found a source file named by the user on disk. Trust it's
137 // extension.
138 this->Name = cmSystemTools::GetFilenameName(name);
139 this->AmbiguousExtension = false;
140
141 // If the directory was ambiguous, it isn't anymore.
142 if (this->AmbiguousDirectory) {
143 this->DirectoryUseSource();
144 }
145 }
146 }
147}
148
149bool cmSourceFileLocation::MatchesAmbiguousExtension(
150 cmSourceFileLocation const& loc) const

Callers 1

cmSourceFileLocationMethod · 0.95

Calls 9

DirectoryUseSourceMethod · 0.95
IsAKnownExtensionMethod · 0.80
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
emptyMethod · 0.45
substrMethod · 0.45
GetGlobalGeneratorMethod · 0.45
GetCMakeInstanceMethod · 0.45

Tested by

no test coverage detected