Skip to content

Commit 80067ff

Browse files
committed
Default CMake Binary to VEnv
Set to None
1 parent e8d7326 commit 80067ff

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

cppython/plugins/conan/plugin.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import os
9+
import shutil
910
from logging import Logger, getLogger
1011
from pathlib import Path
1112
from typing import Any
@@ -45,8 +46,7 @@ def __init__(
4546

4647
self._ensure_default_profiles()
4748

48-
# Initialize cmake_binary with system default. It may be overridden during sync.
49-
self._cmake_binary = 'cmake'
49+
self._cmake_binary = None
5050

5151
@staticmethod
5252
def features(directory: Path) -> SupportedFeatures:
@@ -174,7 +174,7 @@ def _run_conan_install(self, conanfile_path: Path, update: bool, build_type: str
174174
command_args.extend(['-s', f'build_type={build_type}'])
175175

176176
# Add cmake binary configuration if specified
177-
if self._cmake_binary and self._cmake_binary != 'cmake':
177+
if self._cmake_binary:
178178
# Quote the path if it contains spaces
179179
cmake_path = f'"{self._cmake_binary}"' if ' ' in self._cmake_binary else self._cmake_binary
180180
command_args.extend(['-c', f'tools.cmake:cmake_program={cmake_path}'])
@@ -239,6 +239,23 @@ def sync_data(self, consumer: SyncConsumer) -> SyncData:
239239

240240
raise NotSupportedError(f'Unsupported sync types: {consumer.sync_types()}')
241241

242+
@staticmethod
243+
def _resolve_cmake_binary(cmake_path: Path | str | None) -> str | None:
244+
"""Resolve the cmake binary path.
245+
246+
If an explicit path is provided, use it. Otherwise, try to find cmake
247+
in the current Python environment (venv) to ensure we use the same
248+
cmake version for all operations including dependency builds.
249+
250+
Args:
251+
cmake_path: Explicit cmake path, or None to auto-detect
252+
253+
Returns:
254+
Resolved cmake path as string, or None if not found
255+
"""
256+
resolved = cmake_path or shutil.which('cmake')
257+
return str(Path(resolved).resolve()) if resolved else None
258+
242259
def _sync_with_cmake(self, consumer: SyncConsumer) -> CMakeSyncData:
243260
"""Synchronize with CMake generator and create sync data.
244261
@@ -251,9 +268,8 @@ def _sync_with_cmake(self, consumer: SyncConsumer) -> CMakeSyncData:
251268
# Extract cmake_binary from CMakeGenerator if available
252269
if isinstance(consumer, CMakeGenerator) and not os.environ.get('CMAKE_BINARY'):
253270
# Only override if not already set from environment variable
254-
# Convert Path to string, or use 'cmake' if None
255271
cmake_path = consumer.data.cmake_binary
256-
self._cmake_binary = str(cmake_path) if cmake_path else 'cmake'
272+
self._cmake_binary = self._resolve_cmake_binary(cmake_path)
257273

258274
return self._create_cmake_sync_data()
259275

@@ -301,7 +317,7 @@ def publish(self) -> None:
301317
command_args.extend(['-c', 'tools.build:skip_test=True'])
302318

303319
# Add cmake binary configuration if specified
304-
if self._cmake_binary and self._cmake_binary != 'cmake':
320+
if self._cmake_binary:
305321
# Quote the path if it contains spaces
306322
cmake_path = f'"{self._cmake_binary}"' if ' ' in self._cmake_binary else self._cmake_binary
307323
command_args.extend(['-c', f'tools.cmake:cmake_program={cmake_path}'])

0 commit comments

Comments
 (0)