Strange errors while build example with Import std on main branch

bash-5.2$ cd Tests/RunCMake/CXXModules/examples/import-std
bash-5.2$ !CXX
CXX=g++-15 cmake -S . -B build --fresh -D CMAKE_CXX_STANDARD_LIBRARY=libstdc++
-- The CXX compiler identification is GNU 15.1.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-15 - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /Users/clausklein/.local/share/cmake-4.0/Modules/Compiler/CMakeCommonCompilerMacros.cmake:248 (cmake_language):
  CMake's support for `import std;` in C++23 and newer is experimental.  It
  is meant only for experimentation and feedback to CMake developers.
Call Stack (most recent call first):
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /Users/clausklein/.local/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:4 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
-- Configuring done (1.6s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/clausklein/Downloads/cmake/Tests/RunCMake/CXXModules/examples/import-std/build
bash-5.2$ !ninja
ninja -C build/
ninja: Entering directory `build/'
ninja: error: 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXXDependInfo.json', needed by 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXX.dd', missing and no known rule to make it
bash-5.2$ ninja -C build/ -v
ninja: Entering directory `build/'
ninja: error: 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXXDependInfo.json', needed by 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXX.dd', missing and no known rule to make it
bash-5.2$ ninja -C build/ -nv
ninja: Entering directory `build/'
ninja: error: 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXXDependInfo.json', needed by 'CMakeFiles/__CMAKE__CXX23@synth_db5858ea839d.dir/CXX.dd', missing and no known rule to make it

it works better it the project is created like this:

  cd build
  CXX=g++-15 cmake -S .. -B . --fresh

@ben.boeckel Some project cmake file are create at SOURCE_DIR?

bash-5.2$ tree build CMakeFiles/
build
├── CMakeCache.txt
├── CMakeFiles
│   ├── 4.0.20250529-gdf894a1
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeSystem.cmake
│   │   └── CompilerIdCXX
│   │       ├── CMakeCXXCompilerId.cpp
│   │       ├── a.out
│   │       └── tmp
│   ├── CMakeConfigureLog.yaml
│   ├── CMakeScratch
│   ├── InstallScripts.json
│   ├── TargetDirectories.txt
│   ├── __CMAKE__CXX23@synth_db5858ea839d.dir
│   ├── cmake.check_cache
│   ├── main.dir
│   ├── pkgRedirects
│   └── rules.ninja
├── CTestTestfile.cmake
├── build.ninja
├── cmake_install.cmake
└── compile_commands.json
CMakeFiles/
├── __CMAKE__CXX23@synth_db5858ea839d.dir
│   └── CXXDependInfo.json
└── main.dir
    └── CXXDependInfo.json

12 directories, 17 files
bash-5.2$ 

I found the same problems with clang-20:

bash-5.2$ CXX=clang++ cmake -S . -B build --fresh -D CMAKE_CXX_STANDARD=26  -D CMAKE_CXX_MODULE_STD=OFF
-- The CXX compiler identification is Clang 20.1.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_CXX_SCAN_FOR_MODULES="1" ; CMAKE_CXX_MODULE_STD="OFF" ; CMAKE_CXX_COMPILER_IMPORT_STD=""
-- Compiler is: Clang version: 20.1.5
-- CMake is: 4.0.20250529-gdf894a1 modules scan: 1
Cloning into 'catch2-src'...
HEAD is now at 2b60af89 v3.8.1
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_clausklein_Workspace_cpp_cxx23_scope_build__deps_catch2_src__
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_clausklein_Workspace_cpp_cxx23_scope_build__deps_catch2_src__ - Success
Examples to be built: scope_example;unique_resource;unique_resource-file
-- Configuring done (12.5s)
-- Generating done (0.2s)
-- Build files have been written to: /Users/clausklein/Workspace/cpp/cxx23/scope/build
bash-5.2$ ninja -C build
ninja: Entering directory `build'
ninja: error: 'CMakeFiles/beman.scope.dir/CXXDependInfo.json', needed by 'CMakeFiles/beman.scope.dir/include/beman/scope/beman.scope.cppm.o.modmap', missing and no known rule to make it
bash-5.2$ tree CMakeFiles/
CMakeFiles/
├── __CMAKE__CXX26@synth_02d7bd95711d.dir
│   └── CXXDependInfo.json
└── beman.scope.dir
    └── CXXDependInfo.json

3 directories, 2 files
bash-5.2$ 

somethings goes wrong on master within Ninja Generator!

snipped of git diff v4.0.2 Source/cmNinjaTargetGenerator.cxx:

diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 8d936525b0..ac87c0d32b 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -490,38 +478,20 @@ std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
   std::string const ppName =
     cmStrCat(objName.substr(0, objName.size() - objExt.size()), "-pp.", ppExt);
 
-  std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
-  if (!path.empty()) {
-    path += '/';
-  }
-  path +=
-    cmStrCat(this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
-             this->GetGlobalGenerator()->ConfigDirectory(config), '/', ppName);
-  return path;
+  return cmStrCat(this->GetObjectFileDir(config), '/', ppName);
 }
 
 std::string cmNinjaTargetGenerator::GetDyndepFilePath(
   std::string const& lang, std::string const& config) const
 {
-  std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
-  if (!path.empty()) {
-    path += '/';
-  }
-  path += cmStrCat(
-    this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
-    this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang, ".dd");
-  return path;
+  return cmStrCat(this->GetObjectFileDir(config), '/', lang, ".dd");
 }
 
 std::string cmNinjaTargetGenerator::GetTargetDependInfoPath(
   std::string const& lang, std::string const& config) const
 {
-  std::string path =
-    cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/',
-             this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
-             this->GetGlobalGenerator()->ConfigDirectory(config), '/', lang,
-             "DependInfo.json");
-  return path;
+  return cmStrCat(this->GetObjectFileDir(config), '/', lang,
+                  "DependInfo.json");
 }
 
 std::string cmNinjaTargetGenerator::GetTargetOutputDir(
``