add_custom_command: Update dependency search heuristics

Search for a target with the `.exe` suffix stripped from its name only
if a target by the original name doesn't exist.

Fixes: #27612
This commit is contained in:
Tyler Yankee
2026-03-09 12:24:33 -04:00
parent 3b7ab808a2
commit 58ab03c031

View File

@@ -2331,12 +2331,21 @@ bool cmLocalGenerator::GetRealDependency(std::string const& inName,
if (name.empty()) {
return false;
}
if (cmHasSuffix(name, ".exe"_s)) {
name = cmSystemTools::GetFilenameWithoutLastExtension(name);
}
// Look for a CMake target with the given name.
if (cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name)) {
cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name);
if (!target && cmHasSuffix(name, ".exe"_s)) {
// If it doesn't exist, try to strip the `.exe` suffix.
std::string strippedName =
cmSystemTools::GetFilenameWithoutLastExtension(name);
if (cmGeneratorTarget* strippedTarget =
this->FindGeneratorTargetToUse(strippedName)) {
name = strippedName;
target = strippedTarget;
}
}
if (target) {
// make sure it is not just a coincidence that the target name
// found is part of the inName
if (cmSystemTools::FileIsFullPath(inName)) {