| 100 | } |
| 101 | |
| 102 | void 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 | |
| 149 | bool cmSourceFileLocation::MatchesAmbiguousExtension( |
| 150 | cmSourceFileLocation const& loc) const |
no test coverage detected