Repository: scikit-build/scikit-build-core (python)

Issue:
Windows install configuration defaults to debug
Hey 👋🏼 

I noticed some unexpected behavior while working on adding proper installation instructions for one of our C++-based projects (https://github.com/cda-tum/mqt-core) that uses scikit-build-core and pybind11 to expose the project to Python.
We use cibuildwheel to build binary wheels for all possible platforms, including Windows.
Due to better support for caching (via ccache) we want to use Ninja for the build also on Windows (which would normally default to using the MSVC generator). Thus, we explicitly set the `CMAKE_GENERATOR` in the pyproject.toml configuration of cibuildwheel (see https://github.com/cda-tum/mqt-core/blob/3ee8bea3ef9ff22b849cb11d811e4641692459ef/pyproject.toml#L278-L281).
This is working fine in principle. See https://github.com/cda-tum/mqt-core/actions/runs/7678858842/job/20929146794 for a successful example run.
- ✅ It uses Ninja: https://github.com/cda-tum/mqt-core/actions/runs/7678858842/job/20929146794#step:7:333
  ```
  -- Building for: Ninja
  ```
- ✅ It uses MSVC as a compiler: https://github.com/cda-tum/mqt-core/actions/runs/7678858842/job/20929146794#step:7:334
  ```
  The CXX compiler identification is MSVC 19.37.32826.1
  ```
- ❌ It uses "Debug" for the install configuration: https://github.com/cda-tum/mqt-core/actions/runs/7678858842/job/20929146794#step:7:486
  ```
  *** Installing project into wheel...
  -- Install configuration: "Debug"
  ```

Although the default `cmake.build-type = "Release"` and I would have assumed the install type to be the same.
Maybe this is just a faulty assumption. If so, is there any way that I could properly set the install configuration?
If not, could this point to a potential bug within scikit-build-core? Maybe a missing `--config cmake.build_type` somewhere?

The above scenario is running under `scikit-build-core 0.8.0 using CMake 3.27.9 (wheel)`.

Pull request:
fix: include CMAKE_BUILD_TYPE on Windows Ninja
Fix #629.


Patch:
diff --git a/src/scikit_build_core/cmake.py b/src/scikit_build_core/cmake.py
index 1f73a8d..762b5ae 100644
--- a/src/scikit_build_core/cmake.py
+++ b/src/scikit_build_core/cmake.py
@@ -178,9 +178,6 @@ class CMaker:
         if self.init_cache_file.is_file():
             yield f"-C{self.init_cache_file}"
 
-        if self.single_config and self.build_type:
-            yield f"-DCMAKE_BUILD_TYPE:STRING={self.build_type}"
-
         for key, value in defines.items():
             if isinstance(value, bool):
                 str_value = "ON" if value else "OFF"
@@ -214,6 +211,9 @@ class CMaker:
         if gen:
             self.single_config = gen == "Ninja" or "Makefiles" in gen
 
+        if self.single_config and self.build_type:
+            all_args.insert(2, f"-DCMAKE_BUILD_TYPE:STRING={self.build_type}")
+
         try:
             Run(env=self.env).live(self.cmake, *all_args)
         except subprocess.CalledProcessError:


Test patch:
diff --git a/tests/test_cmake_config.py b/tests/test_cmake_config.py
index d08f45e..3f8e25f 100644
--- a/tests/test_cmake_config.py
+++ b/tests/test_cmake_config.py
@@ -22,13 +22,13 @@ def configure_args(config: CMaker, *, init: bool = False) -> Generator[str, None
     yield f"-S{config.source_dir}"
     yield f"-B{config.build_dir}"
 
+    if config.single_config:
+        yield f"-DCMAKE_BUILD_TYPE:STRING={config.build_type}"
+
     if init:
         cmake_init = config.build_dir / "CMakeInit.txt"
         yield f"-C{cmake_init}"
 
-    if config.single_config:
-        yield f"-DCMAKE_BUILD_TYPE:STRING={config.build_type}"
-
 
 @pytest.mark.configure()
 def test_init_cache(fp, tmp_path):