From 0b7d8e4ad61e32ad1d71aacdd2f12e0cfc596524 Mon Sep 17 00:00:00 2001 From: Stepanov Igor Date: Fri, 25 Jul 2025 09:39:56 +0300 Subject: [PATCH] xcode: Restore ctest --build-and-test without --build-project Previously, it used to be possible to execute ctest --build-and-test without specifying --build-project. When used with the Xcode generator, this would work as long as there was only one .xcodeproj file in the directory, where xcodebuild would then default to using that project. The recent changes to support .xcworkspace files broke that logic, placing a malformed pair of options "-project .xcodeproj" on the command line instead of omitting the "-project" option altogether. Fixes: #27090 --- Source/cmGlobalXCodeGenerator.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 27fdfaccf5..314349a28b 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -551,6 +551,15 @@ cmGlobalXCodeGenerator::GenerateBuildCommand( std::string const xcodebuild = this->SelectMakeProgram(makeProgram, this->GetXcodeBuildCommand()); + // Note that projectName can be empty, such as from a command like this one: + // ctest --build-and-test . build --build-generator Xcode + // If projectName is empty, then isWorkspace set further below will always + // be false because workspacePath will never point to a valid workspace file. + // And if projectName is empty, we don't add any -workspace or -project + // option to the xcodebuild command line because we don't know what to put + // after either option. For that scenario, we rely on xcodebuild finding + // exactly one .xcodeproj file in the working directory. + std::string const workspacePath = cmStrCat(projectName, ".xcworkspace"); std::string const projectPath = cmStrCat(projectName, ".xcodeproj"); @@ -563,7 +572,7 @@ cmGlobalXCodeGenerator::GenerateBuildCommand( if (isWorkspace) { requiredArgs.insert(requiredArgs.end(), { "-workspace", workspacePath }); - } else { + } else if (!projectName.empty()) { requiredArgs.insert(requiredArgs.end(), { "-project", projectPath }); }