From 58ab03c031e24127c9acfee92ab79f297cddf0f8 Mon Sep 17 00:00:00 2001 From: Tyler Yankee Date: Mon, 9 Mar 2026 12:24:33 -0400 Subject: [PATCH] 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 --- Source/cmLocalGenerator.cxx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 1a4bbecb22..2b044b5ede 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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)) {