@@ -36,7 +36,12 @@ def generate_cppython_preset(
3636 preset_name = 'cppython'
3737
3838 # Create a default preset that inherits from provider's default preset
39- default_configure = ConfigurePreset (name = preset_name , hidden = True , toolchainFile = provider_data .toolchain_file )
39+ default_configure = ConfigurePreset (
40+ name = preset_name ,
41+ hidden = True ,
42+ description = 'Injected configuration preset for CPPython' ,
43+ toolchainFile = provider_data .toolchain_file ,
44+ )
4045 configure_presets .append (default_configure )
4146
4247 generated_preset = CMakePresets (
@@ -86,8 +91,10 @@ def write_cppython_preset(
8691 return cppython_preset_file
8792
8893 @staticmethod
89- def _create_user_presets (cmake_data : CMakeData , build_directory : Path ) -> tuple [ConfigurePreset , list [BuildPreset ]]:
90- """Create user configure and build presets.
94+ def _create_presets (
95+ cmake_data : CMakeData , build_directory : Path
96+ ) -> tuple [list [ConfigurePreset ], list [BuildPreset ]]:
97+ """Create the default configure and build presets for the user.
9198
9299 Args:
93100 cmake_data: The CMake data to use
@@ -96,26 +103,63 @@ def _create_user_presets(cmake_data: CMakeData, build_directory: Path) -> tuple[
96103 Returns:
97104 A tuple containing the configure preset and list of build presets
98105 """
99- user_configure_preset = ConfigurePreset (
100- name = cmake_data .configuration_name ,
101- inherits = 'cppython' ,
102- binaryDir = build_directory .as_posix (),
106+ user_configure_presets : list [ConfigurePreset ] = []
107+ user_build_presets : list [BuildPreset ] = []
108+
109+ name = cmake_data .configuration_name
110+ release_name = name + '-release'
111+ debug_name = name + '-debug'
112+
113+ user_configure_presets .append (
114+ ConfigurePreset (
115+ name = name ,
116+ description = 'All multi-configuration generators should inherit from this preset' ,
117+ hidden = True ,
118+ inherits = 'cppython' ,
119+ binaryDir = '${sourceDir}/' + build_directory .as_posix (),
120+ cacheVariables = {'CMAKE_CONFIGURATION_TYPES' : 'Debug;Release' },
121+ )
122+ )
123+
124+ user_configure_presets .append (
125+ ConfigurePreset (
126+ name = release_name ,
127+ description = 'All single-configuration generators should inherit from this preset' ,
128+ hidden = True ,
129+ inherits = name ,
130+ cacheVariables = {'CMAKE_BUILD_TYPE' : 'Release' },
131+ )
103132 )
104133
105- user_build_presets = [
134+ user_configure_presets .append (
135+ ConfigurePreset (
136+ name = debug_name ,
137+ description = 'All single-configuration generators should inherit from this preset' ,
138+ hidden = True ,
139+ inherits = name ,
140+ cacheVariables = {'CMAKE_BUILD_TYPE' : 'Debug' },
141+ )
142+ )
143+
144+ user_build_presets .append (
106145 BuildPreset (
107- name = f'{ cmake_data .configuration_name } -multi-release' ,
108- configurePreset = cmake_data .configuration_name ,
109- configuration = 'Release' ,
110- ),
146+ name = release_name ,
147+ description = 'An example build preset for release' ,
148+ hidden = True ,
149+ configurePreset = release_name ,
150+ )
151+ )
152+
153+ user_build_presets .append (
111154 BuildPreset (
112- name = f'{ cmake_data .configuration_name } -multi-debug' ,
113- configurePreset = cmake_data .configuration_name ,
114- configuration = 'Debug' ,
115- ),
116- ]
155+ name = debug_name ,
156+ description = 'An example build preset for debug' ,
157+ hidden = True ,
158+ configurePreset = debug_name ,
159+ )
160+ )
117161
118- return user_configure_preset , user_build_presets
162+ return user_configure_presets , user_build_presets
119163
120164 @staticmethod
121165 def _load_existing_preset (preset_file : Path ) -> CMakePresets | None :
@@ -152,39 +196,36 @@ def _update_configure_preset(existing_preset: ConfigurePreset, build_directory:
152196
153197 # Update binary directory if not set
154198 if not existing_preset .binaryDir :
155- existing_preset .binaryDir = build_directory .as_posix () # type: ignore[misc]
199+ existing_preset .binaryDir = '${sourceDir}/' + build_directory .as_posix () # type: ignore[misc]
156200
157201 @staticmethod
158- def _handle_configure_presets (
159- root_preset : CMakePresets , user_configure_preset : ConfigurePreset , build_directory : Path
202+ def _modify_presets (
203+ root_preset : CMakePresets ,
204+ user_configure_presets : list [ConfigurePreset ],
205+ user_build_presets : list [BuildPreset ],
206+ build_directory : Path ,
160207 ) -> None :
161- """Handle configure presets in the root preset.
208+ """Handle presets in the root preset.
162209
163210 Args:
164211 root_preset: The root preset to modify
165- user_configure_preset: The user's configure preset
212+ user_configure_presets: The user's configure presets
213+ user_build_presets: The user's build presets
166214 build_directory: The build directory to use
167215 """
168216 if root_preset .configurePresets is None :
169- root_preset .configurePresets = [ user_configure_preset ] # type: ignore[misc]
217+ root_preset .configurePresets = user_configure_presets . copy () # type: ignore[misc]
170218 else :
171219 # Update or add the user's configure preset
172- existing_preset = next (
173- (p for p in root_preset .configurePresets if p .name == user_configure_preset .name ), None
174- )
220+ for user_configure_preset in user_configure_presets :
221+ existing_preset = next (
222+ (p for p in root_preset .configurePresets if p .name == user_configure_preset .name ), None
223+ )
175224 if existing_preset :
176225 Builder ._update_configure_preset (existing_preset , build_directory )
177226 else :
178227 root_preset .configurePresets .append (user_configure_preset )
179228
180- @staticmethod
181- def _handle_build_presets (root_preset : CMakePresets , user_build_presets : list [BuildPreset ]) -> None :
182- """Handle build presets in the root preset.
183-
184- Args:
185- root_preset: The root preset to modify
186- user_build_presets: The user's build presets to add
187- """
188229 if root_preset .buildPresets is None :
189230 root_preset .buildPresets = user_build_presets .copy () # type: ignore[misc]
190231 else :
@@ -195,7 +236,7 @@ def _handle_build_presets(root_preset: CMakePresets, user_build_presets: list[Bu
195236 root_preset .buildPresets .append (build_preset )
196237
197238 @staticmethod
198- def _handle_includes (root_preset : CMakePresets , preset_file : Path , cppython_preset_file : Path ) -> None :
239+ def _modify_includes (root_preset : CMakePresets , preset_file : Path , cppython_preset_file : Path ) -> None :
199240 """Handle include paths in the root preset.
200241
201242 Args:
@@ -230,22 +271,19 @@ def generate_root_preset(
230271 A CMakePresets object
231272 """
232273 # Create user presets
233- user_configure_preset , user_build_presets = Builder ._create_user_presets (cmake_data , build_directory )
274+ user_configure_presets , user_build_presets = Builder ._create_presets (cmake_data , build_directory )
234275
235276 # Load existing preset or create new one
236277 root_preset = Builder ._load_existing_preset (preset_file )
237278 if root_preset is None :
238279 root_preset = CMakePresets (
239- configurePresets = [ user_configure_preset ] ,
280+ configurePresets = user_configure_presets ,
240281 buildPresets = user_build_presets ,
241282 )
242283 else :
243- # Handle existing preset
244- Builder ._handle_configure_presets (root_preset , user_configure_preset , build_directory )
245- Builder ._handle_build_presets (root_preset , user_build_presets )
284+ Builder ._modify_presets (root_preset , user_configure_presets , user_build_presets , build_directory )
246285
247- # Handle includes
248- Builder ._handle_includes (root_preset , preset_file , cppython_preset_file )
286+ Builder ._modify_includes (root_preset , preset_file , cppython_preset_file )
249287
250288 return root_preset
251289
0 commit comments