Skip to content

Commit 0e1719a

Browse files
committed
Custom Layout
1 parent aba296c commit 0e1719a

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

cppython/plugins/conan/builder.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,24 @@ def _create_base_conanfile(
4646
content = f'''"""CPPython managed base ConanFile.
4747
4848
This file is auto-generated by CPPython. Do not edit manually.
49-
Dependencies are managed through pyproject.toml.
49+
Dependencies and layout are managed through pyproject.toml.
5050
"""
5151
5252
from conan import ConanFile
5353
5454
5555
class CPPythonBase(ConanFile):
56-
"""Base ConanFile with CPPython managed dependencies."""
56+
"""Base ConanFile with CPPython managed dependencies and layout."""
57+
58+
def layout(self):
59+
"""CPPython managed layout for consistent paths across all platforms.
60+
61+
Uses explicit folder settings instead of cmake_layout() to avoid
62+
platform/generator-dependent behavior (e.g., build_type subfolders
63+
on single-config generators).
64+
"""
65+
self.folders.build = "."
66+
self.folders.generators = "generators"
5767
5868
def requirements(self):
5969
"""CPPython managed requirements."""
@@ -74,7 +84,7 @@ def _create_conanfile(
7484
"""Creates a conanfile.py file that inherits from CPPython base."""
7585
class_name = name.replace('-', '_').title().replace('_', '')
7686
content = f'''import os
77-
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
87+
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain
7888
from conan.tools.files import copy
7989
8090
from conanfile_base import CPPythonBase
@@ -107,7 +117,12 @@ def build_requirements(self):
107117
# Add your custom build requirements here
108118
109119
def layout(self):
110-
cmake_layout(self)
120+
"""Configure build folder layout.
121+
122+
CPPython managed layout is inherited from CPPythonBase.
123+
Override if you need custom folder settings.
124+
"""
125+
super().layout() # Get CPPython managed layout
111126
112127
def generate(self):
113128
deps = CMakeDeps(self)

cppython/plugins/conan/plugin.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,6 @@ def _run_conan_install(self, conanfile_path: Path, update: bool, build_type: str
165165
output_folder = self.core_data.cppython_data.build_path
166166
command_args.extend(['--output-folder', str(output_folder)])
167167

168-
# Normalize cmake_layout behavior across all platforms/generators:
169-
# - build_folder=. puts build output directly in output_folder (no 'build' subfolder)
170-
# - build_folder_vars=[] prevents build_type subfolders (Release/Debug)
171-
# This ensures generators always end up in output_folder/generators/ consistently
172-
command_args.extend(['-c', 'tools.cmake.cmake_layout:build_folder=.'])
173-
command_args.extend(['-c', 'tools.cmake.cmake_layout:build_folder_vars=[]'])
174-
175168
# Add build missing flag
176169
command_args.extend(['--build', 'missing'])
177170

@@ -287,8 +280,8 @@ def _create_cmake_sync_data(self) -> CMakeSyncData:
287280
Returns:
288281
CMakeSyncData configured for Conan integration
289282
"""
290-
# With cmake_layout config overrides (build_folder=. and build_folder_vars=[]),
291-
# generators are always placed in build_path/generators/ regardless of platform/generator
283+
# The generated conanfile uses explicit layout (self.folders.generators = "generators")
284+
# Combined with --output-folder=build_path, generators are always at build_path/generators/
292285
conan_toolchain_path = self.core_data.cppython_data.build_path / 'generators' / 'conan_toolchain.cmake'
293286

294287
return CMakeSyncData(

0 commit comments

Comments
 (0)