@@ -61,6 +61,12 @@ Allowed options:
61
61
* `<name>`: should be in the form `LIBRARY=NAME`; overrides the searched name
62
62
for library `LIBRARY` with the name `NAME`. Multiple instances (even for
63
63
the same library) are allowed.
64
+ * `<target>` should be in the form `LIBRARY=TARGET`, where `TARGET` should be a
65
+ target reference, or `LIBRARY`, in which case the current project should
66
+ contain a target called `LIBRARY`; target to use instead of creating a new
67
+ target for `LIBRARY`. This can be useful if the user wants a non-standard
68
+ method of locating the library (e.g. <<_pkg_config>>), or wants to build
69
+ the library manually. One instance per `LIBRARY` is allowed.
64
70
65
71
The rule supports keyword arguments.
66
72
@@ -200,6 +206,18 @@ rule init ( options * : condition * )
200
206
}
201
207
----
202
208
209
+ [[bbv2.tools.external.target_override]]
210
+ == Overriding with other targets
211
+
212
+ `configure` rule can be used to override the created target with another
213
+ target. One particular use case is overriding with a target created by
214
+ `pkg-config` module.
215
+
216
+ [source,jam]
217
+ ----
218
+ pkg-config.import sqlite3 ;
219
+ external.configure sqlite3 : <target>sqlite3 ;
220
+ ----
203
221
|# # end::doc[]
204
222
205
223
local rule declare-target ( tgt-id : sources * : options * : header-only ? )
@@ -271,7 +289,16 @@ local rule declare-target ( tgt-id : sources * : options * : header-only ? )
271
289
: $(user-options) ] ;
272
290
}
273
291
292
+ local target-ref = [ get-target $(tgt-name) : $(user-options) ] ;
293
+ if $(target-ref)
294
+ {
295
+ $(lib-tgt).set-target $(target-ref) ;
296
+ $(lib-tgt).set-caller [ $(configs).get $(config) : caller ] ;
297
+ }
298
+
274
299
targets.main-target-alternative $(lib-tgt) ;
300
+
301
+ $(configs).set $(config) : $(registered-targets) $(tgt-name) ;
275
302
}
276
303
}
277
304
@@ -291,6 +318,23 @@ local rule lib-name ( lib-name : options * : user-options * )
291
318
return $(result) ;
292
319
}
293
320
321
+ local rule get-target ( lib-name : user-options * )
322
+ {
323
+ local result ;
324
+ for local opt in $(user-options)
325
+ {
326
+ if $(opt:G) != <target> { continue ; }
327
+ if $(opt:G=) = $(lib-name)
328
+ {
329
+ result += $(lib-name) ;
330
+ }
331
+
332
+ result += [ MATCH ^$(lib-name)=(.*) : $(opt:G=) ]
333
+ [ MATCH ^$(lib-name)$ : $(opt:G=) ] ;
334
+ }
335
+ return $(result) ;
336
+ }
337
+
294
338
local rule get-configs ( proj-name )
295
339
{
296
340
local configs = .configs-$(proj-name) ;
@@ -316,6 +360,7 @@ local rule register-config ( proj-name : configs : options * : condition )
316
360
$(configs).register $(condition) ;
317
361
$(configs).set $(condition) : options : $(options) ;
318
362
$(configs).set $(condition) : condition : $(condition) ;
363
+ $(configs).set $(condition) : caller : [ project.current ] ;
319
364
$(configs).set $(condition) : targets ;
320
365
321
366
$(configs).use $(condition) ;
@@ -388,6 +433,11 @@ class external-library : ac-library
388
433
self.sources = $(sources) ;
389
434
}
390
435
436
+ rule set-caller ( caller )
437
+ {
438
+ self.caller = $(caller) ;
439
+ }
440
+
391
441
rule compute-usage-requirements ( subvariant )
392
442
{
393
443
local base = [ basic-target.compute-usage-requirements $(subvariant) ] ;
@@ -398,7 +448,8 @@ class external-library : ac-library
398
448
{
399
449
if $(self.target)
400
450
{
401
- return [ $(self.target).generate $(property-set) ] $(sources) ;
451
+ return [ targets.generate-from-reference $(self.target)
452
+ : $(self.caller) : $(property-set) ] ;
402
453
}
403
454
404
455
local proj = [ project ] ;
0 commit comments