xcodebuild clean fails with CMake and custom build directories on new build system

CMake calls through to xcodebuild clean, but this fails since custom build directories are set. The current workaround is to have to trash the entire CMake build folder. With many subprojects this then takes a long time to rebuild. Can Apple please fix this?

Here I have a project with multiple targets (a fake workspace). CMake can only generate xcprojects and not xcworkspace files. Visual Studio and Android Studio both integrate CMake into the IDE. But building iOS and macOS universal apps is still not simple with CMake. Can Xcode team support CMake better in general?

Code Block
cmake --build . --target clean 
xcodebuild -project foo.xcodeproj clean -target ALL_BUILD -parallelizeTargets -configuration Debug -hideShellScriptEnvironment
Command line invocation:
  xcodebuild -project foo.xcodeproj clean -target ALL_BUILD -parallelizeTargets -configuration Debug -hideShellScriptEnvironment
User defaults from command line:
  HideShellScriptEnvironment = YES
note: Using new build system
note: Building targets in parallel
error: Could not delete `build/lib` because it was not created by the build system.
error: Could not delete `build/app1` because it was not created by the build system.
error: Could not delete `build/app2` because it was not created by the build system.
warning: Refusing to delete `build` because it contains one of the projects in this workspace: `build/foo.xcodeproj`.
CLEAN FAILED

We are affected by this too. We have to use the legacy build system before. But now Xcode 13 removed the legacy build system. Also, "dry run" is not supported in the new build system too. I hope Apple can keep the legacy build system before these problems are solved.

xcodebuild clean fails with CMake and custom build directories on new build system
 
 
Q