Skip to content

Commit

Permalink
allow override external targets with other targets
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Apr 28, 2023
1 parent 33a0f91 commit e72eced
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
53 changes: 52 additions & 1 deletion src/tools/external.jam
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Allowed options:
* `<name>`: should be in the form `LIBRARY=NAME`; overrides the searched name
for library `LIBRARY` with the name `NAME`. Multiple instances (even for
the same library) are allowed.
* `<target>` should be in the form `LIBRARY=TARGET`, where `TARGET` should be a
target reference, or `LIBRARY`, in which case the current project should
contain a target called `LIBRARY`; target to use instead of creating a new
target for `LIBRARY`. This can be useful if the user wants a non-standard
method of locating the library (e.g. <<_pkg_config>>), or wants to build
the library manually. One instance per `LIBRARY` is allowed.

The rule supports keyword arguments.

Expand Down Expand Up @@ -200,6 +206,18 @@ rule init ( options * : condition * )
}
----

[[bbv2.tools.external.target_override]]
== Overriding with other targets

`configure` rule can be used to override the created target with another
target. One particular use case is overriding with a target created by
`pkg-config` module.

[source,jam]
----
pkg-config.import sqlite3 ;
external.configure sqlite3 : <target>sqlite3 ;
----
|# # end::doc[]

local rule declare-target ( tgt-id : sources * : options * : header-only ? )
Expand Down Expand Up @@ -271,7 +289,16 @@ local rule declare-target ( tgt-id : sources * : options * : header-only ? )
: $(user-options) ] ;
}

local target-ref = [ get-target $(tgt-name) : $(user-options) ] ;
if $(target-ref)
{
$(lib-tgt).set-target $(target-ref) ;
$(lib-tgt).set-caller [ $(configs).get $(config) : caller ] ;
}

targets.main-target-alternative $(lib-tgt) ;

$(configs).set $(config) : $(registered-targets) $(tgt-name) ;
}
}

Expand All @@ -291,6 +318,23 @@ local rule lib-name ( lib-name : options * : user-options * )
return $(result) ;
}

local rule get-target ( lib-name : user-options * )
{
local result ;
for local opt in $(user-options)
{
if $(opt:G) != <target> { continue ; }
if $(opt:G=) = $(lib-name)
{
result += $(lib-name) ;
}

result += [ MATCH ^$(lib-name)=(.*) : $(opt:G=) ]
[ MATCH ^$(lib-name)$ : $(opt:G=) ] ;
}
return $(result) ;
}

local rule get-configs ( proj-name )
{
local configs = .configs-$(proj-name) ;
Expand All @@ -316,6 +360,7 @@ local rule register-config ( proj-name : configs : options * : condition )
$(configs).register $(condition) ;
$(configs).set $(condition) : options : $(options) ;
$(configs).set $(condition) : condition : $(condition) ;
$(configs).set $(condition) : caller : [ project.current ] ;
$(configs).set $(condition) : targets ;

$(configs).use $(condition) ;
Expand Down Expand Up @@ -388,6 +433,11 @@ class external-library : ac-library
self.sources = $(sources) ;
}

rule set-caller ( caller )
{
self.caller = $(caller) ;
}

rule compute-usage-requirements ( subvariant )
{
local base = [ basic-target.compute-usage-requirements $(subvariant) ] ;
Expand All @@ -398,7 +448,8 @@ class external-library : ac-library
{
if $(self.target)
{
return [ $(self.target).generate $(property-set) ] $(sources) ;
return [ targets.generate-from-reference $(self.target)
: $(self.caller) : $(property-set) ] ;
}

local proj = [ project ] ;
Expand Down
2 changes: 0 additions & 2 deletions src/tools/pkg-config.jam
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ using pkg-config : [config] : [command] ... : [ options ] ... : [condition] ...

rule init ( config ? : command * : options * : condition * )
{
echo using pkg-config $(config) ":" $(command) ":" $(options) ;

if ! $(.initialized)
{
.initialized = true ;
Expand Down

0 comments on commit e72eced

Please sign in to comment.