@@ -168,7 +168,22 @@ def ask(*args, **kwargs):
168
168
"include_source" : False ,
169
169
"has_source" : True ,
170
170
"cpus" : os .cpu_count (),
171
+ "pm_name" : "" ,
171
172
}
173
+ package_manager = ask (
174
+ "Package manager to use ([N]one/[c]onan/[v]cpkg)" ,
175
+ cli_args .package_manager or "n" ,
176
+ mapper = lambda v : v [0 :1 ].lower (),
177
+ predicate = lambda v : v in ["n" , "c" , "v" ],
178
+ header = """\
179
+ Choosing Conan requires it to be installed. Choosing vcpkg requires the
180
+ VCPKG_ROOT environment variable to be setup to vcpkg's root directory.""" ,
181
+ )
182
+ d ["vcpkg" ] = package_manager == "v"
183
+ d ["conan" ] = package_manager == "c"
184
+ d ["pm" ] = package_manager != "n"
185
+ if d ["pm" ]:
186
+ d ["pm_name" ] = "conan" if d ["conan" ] else "vcpkg"
172
187
d ["uc_name" ] = d ["name" ].upper ().replace ("-" , "_" )
173
188
if d ["type_id" ] != "e" :
174
189
key = "c_examples" if cli_args .c else "cpp_examples"
@@ -216,20 +231,38 @@ def should_write_examples(d, at):
216
231
217
232
218
233
def should_install_file (name , d ):
219
- if name == "install-config.cmake" and d ["type_id" ] == "e" :
234
+ if name == "vcpkg.json" and not d ["vcpkg" ]:
235
+ return False
236
+ if name == "conanfile.txt" and not d ["conan" ]:
237
+ return False
238
+ if name == "install-config.cmake" and d ["exe" ]:
239
+ return False
240
+ if name == "windows-set-path.cmake" and d ["pm" ]:
241
+ return False
242
+ if name == "install-script.cmake" and not d ["exe" ]:
243
+ return False
244
+ if name == "header_impl.c" and (not d ["c_header" ] or not d ["pm" ]):
220
245
return False
221
- if name == "install-script.cmake " and d ["type_id" ] != "e" :
246
+ if name == "clang-11.profile " and not d ["conan" ] :
222
247
return False
223
248
return True
224
249
225
250
251
+ def transform_path (path , d ):
252
+ if not d ["exe" ] and d ["pm" ] and path .endswith ("install-config.cmake" ):
253
+ return f"{ path } .in"
254
+ if d ["c" ] and d ["pm" ] and path .endswith ("_test.c" ):
255
+ return f"{ path } pp"
256
+ return path
257
+
258
+
226
259
def write_dir (path , d , overwrite , zip_path ):
227
260
for entry in zip_path .iterdir ():
228
261
name = entry .name .replace ("__name__" , d ["name" ])
229
262
next_path = os .path .join (path , name )
230
263
if entry .is_file ():
231
264
if should_install_file (name , d ):
232
- write_file (next_path , d , overwrite , entry )
265
+ write_file (transform_path ( next_path , d ) , d , overwrite , entry )
233
266
elif name != "example" or should_write_examples (d , entry .at ):
234
267
mkdir (next_path )
235
268
write_dir (next_path , d , overwrite , entry )
@@ -273,11 +306,15 @@ def git_init(cwd):
273
306
274
307
def print_tips (d ):
275
308
config = " --config Debug" if is_windows else ""
309
+ conan = ""
310
+ if d ["conan" ]:
311
+ conan = """
312
+ conan install . -if conan -s build_type=Debug -b missing"""
276
313
print (f"""\
277
314
To get you started with the project in developer mode, you may configure,
278
315
build, install and test with the following commands from the project directory,
279
316
in that order:
280
-
317
+ { conan }
281
318
cmake --preset=dev
282
319
cmake --build --preset=dev
283
320
cmake --install build/dev{ config } --prefix prefix
@@ -509,6 +546,12 @@ def main(zip):
509
546
const = "n" ,
510
547
help = "generate examples for a library" ,
511
548
)
549
+ p .add_argument (
550
+ "-p" ,
551
+ metavar = "pm" ,
552
+ dest = "package_manager" ,
553
+ help = "package manager to use (Options are: conan, vcpkg)" ,
554
+ )
512
555
args = p .parse_args ()
513
556
if args .dummy :
514
557
p .print_help ()
0 commit comments