@@ -61,6 +61,12 @@ Allowed options:
6161* `<name>`: should be in the form `LIBRARY=NAME`; overrides the searched name
6262 for library `LIBRARY` with the name `NAME`. Multiple instances (even for
6363 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.
6470
6571The rule supports keyword arguments.
6672
@@ -200,6 +206,18 @@ rule init ( options * : condition * )
200206}
201207----
202208
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+ ----
203221|# # end::doc[]
204222
205223local rule declare-target ( tgt-id : sources * : options * : header-only ? )
@@ -271,7 +289,16 @@ local rule declare-target ( tgt-id : sources * : options * : header-only ? )
271289 : $(user-options) ] ;
272290 }
273291
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+
274299 targets.main-target-alternative $(lib-tgt) ;
300+
301+ $(configs).set $(config) : $(registered-targets) $(tgt-name) ;
275302 }
276303}
277304
@@ -291,6 +318,23 @@ local rule lib-name ( lib-name : options * : user-options * )
291318 return $(result) ;
292319}
293320
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+
294338local rule get-configs ( proj-name )
295339{
296340 local configs = .configs-$(proj-name) ;
@@ -316,6 +360,7 @@ local rule register-config ( proj-name : configs : options * : condition )
316360 $(configs).register $(condition) ;
317361 $(configs).set $(condition) : options : $(options) ;
318362 $(configs).set $(condition) : condition : $(condition) ;
363+ $(configs).set $(condition) : caller : [ project.current ] ;
319364 $(configs).set $(condition) : targets ;
320365
321366 $(configs).use $(condition) ;
@@ -388,6 +433,11 @@ class external-library : ac-library
388433 self.sources = $(sources) ;
389434 }
390435
436+ rule set-caller ( caller )
437+ {
438+ self.caller = $(caller) ;
439+ }
440+
391441 rule compute-usage-requirements ( subvariant )
392442 {
393443 local base = [ basic-target.compute-usage-requirements $(subvariant) ] ;
@@ -398,7 +448,8 @@ class external-library : ac-library
398448 {
399449 if $(self.target)
400450 {
401- return [ $(self.target).generate $(property-set) ] $(sources) ;
451+ return [ targets.generate-from-reference $(self.target)
452+ : $(self.caller) : $(property-set) ] ;
402453 }
403454
404455 local proj = [ project ] ;
0 commit comments