Repository: scikit-build/scikit-build-core
Pull request #272 (2023-04-12 22:06:48)

fix: unused prefix warning
This warning is showing up, fix by moving the setting into -C.



Patch:
diff --git a/src/scikit_build_core/cmake.py b/src/scikit_build_core/cmake.py
index 4896e69..5d20067 100644
--- a/src/scikit_build_core/cmake.py
+++ b/src/scikit_build_core/cmake.py
@@ -131,6 +131,24 @@ class CMaker:
                     f.write(f'set({key} [===[{str_value}]===] CACHE PATH "" FORCE)\n')
                 else:
                     f.write(f'set({key} [===[{value}]===] CACHE STRING "" FORCE)\n')
+
+            if self.module_dirs:
+                # Convert to CMake's internal path format, otherwise this breaks try_compile on Windows
+                module_dirs_str = ";".join(map(str, self.module_dirs)).replace(
+                    "\\", "/"
+                )
+                f.write(
+                    f'set(CMAKE_MODULE_PATH [===[{module_dirs_str}]===] CACHE PATH "" FORCE)\n'
+                )
+
+            if self.prefix_dirs:
+                prefix_dirs_str = ";".join(map(str, self.prefix_dirs)).replace(
+                    "\\", "/"
+                )
+                f.write(
+                    f'set(CMAKE_PREFIX_PATH [===[{prefix_dirs_str}]===] CACHE PATH "" FORCE)\n'
+                )
+
         contents = self.init_cache_file.read_text(encoding="utf-8").strip()
         logger.debug(
             "{}:\n{}",
@@ -148,7 +166,7 @@ class CMaker:
             yield f"-C{self.init_cache_file}"
 
         if self.single_config and self.build_type:
-            yield f"-DCMAKE_BUILD_TYPE={self.build_type}"
+            yield f"-DCMAKE_BUILD_TYPE:STRING={self.build_type}"
 
         for key, value in defines.items():
             if isinstance(value, bool):
@@ -160,15 +178,6 @@ class CMaker:
             else:
                 yield f"-D{key}={value}"
 
-        if self.module_dirs:
-            # Convert to CMake's internal path format, otherwise this breaks try_compile on Windows
-            module_dirs_str = ";".join(map(str, self.module_dirs)).replace("\\", "/")
-            yield f"-DCMAKE_MODULE_PATH:PATH={module_dirs_str}"
-
-        if self.prefix_dirs:
-            prefix_dirs_str = ";".join(map(str, self.prefix_dirs)).replace("\\", "/")
-            yield f"-DCMAKE_PREFIX_PATH:PATH={prefix_dirs_str}"
-
     def configure(
         self,
         *,


Test patch:
diff --git a/tests/test_cmake_config.py b/tests/test_cmake_config.py
index bcc2a95..660410e 100644
--- a/tests/test_cmake_config.py
+++ b/tests/test_cmake_config.py
@@ -22,17 +22,7 @@ def configure_args(config: CMaker, *, init: bool = False) -> Generator[str, None
         yield f"-C{cmake_init}"
 
     if config.single_config:
-        yield f"-DCMAKE_BUILD_TYPE={config.build_type}"
-
-    if config.module_dirs:
-        yield "-DCMAKE_MODULE_PATH:PATH={}".format(
-            ";".join(str(p).replace("\\", "/") for p in config.module_dirs)
-        )
-
-    if config.prefix_dirs:
-        yield "-DCMAKE_PREFIX_PATH:PATH={}".format(
-            ";".join(str(p).replace("\\", "/") for p in config.prefix_dirs)
-        )
+        yield f"-DCMAKE_BUILD_TYPE:STRING={config.build_type}"
 
 
 @pytest.mark.configure()
diff --git a/tests/test_custom_modules.py b/tests/test_custom_modules.py
index 3d9267b..d263577 100644
--- a/tests/test_custom_modules.py
+++ b/tests/test_custom_modules.py
@@ -9,5 +9,5 @@ PROJECT_DIR = DIR / "packages" / "custom_cmake"
 def test_ep(isolated):
     isolated.install("hatchling", "scikit-build-core[pyproject]")
     isolated.install(PROJECT_DIR / "extern", isolated=False)
-    isolated.install(PROJECT_DIR, isolated=False)
+    isolated.install(PROJECT_DIR, "-v", isolated=False)
     # Needs script fix: assert isolated.run("script1") == ""