mirror of
https://github.com/boostorg/build.git
synced 2026-02-13 00:12:11 +00:00
Improve "linking" of libraries into static libraries.
When a library is present in sources of a static library, return it to dependents via usage requirements, not by adding it to the list of created targets. [SVN r29362]
This commit is contained in:
@@ -695,21 +695,38 @@ class archive-generator : generator
|
||||
local result = [ generator.run $(project) $(name) : $(property-set)
|
||||
: $(sources) ] ;
|
||||
|
||||
# For static linking, we can't directly link to libraries.
|
||||
# For static linking, if we get a library in source, we can't
|
||||
# directly link to it. So, we need to cause our dependencies
|
||||
# to link to that library. There are two approaches:
|
||||
# - adding the library to the list of returned targets.
|
||||
# - using the <library> usage requirements.
|
||||
# The problem with the first is:
|
||||
#
|
||||
# lib a1 : : <file>liba1.a ;
|
||||
# lib a2 : a2.cpp a1 : <link>static ;
|
||||
# install dist : a2 ;
|
||||
#
|
||||
# here we'll try to install 'a1', even though it's not necessary in
|
||||
# the general case.
|
||||
# With the second approaches, even indirect dependents will link to
|
||||
# the library, but it should not cause any harm.
|
||||
# So, return all LIB sources together with created targets,
|
||||
# so that dependents link to them.
|
||||
local usage-requirements ;
|
||||
if [ $(property-set).get <link> ] = static
|
||||
{
|
||||
for local t in $(sources)
|
||||
{
|
||||
if [ type.is-derived [ $(t).type ] LIB ]
|
||||
{
|
||||
result += $(t) ;
|
||||
usage-requirements += <library>$(t) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $(result) ;
|
||||
|
||||
usage-requirements = [ property-set.create $(usage-requirements) ] ;
|
||||
|
||||
return $(usage-requirements) $(result) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ class unix-archive-generator : archive-generator
|
||||
local result = [ archive-generator.run $(project) $(name) : $(property-set)
|
||||
: $(sources) ] ;
|
||||
|
||||
unix.set-library-order $(sources) : $(property-set) : $(result) ;
|
||||
unix.set-library-order $(sources) : $(property-set) : $(result[2-]) ;
|
||||
|
||||
return $(result) ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user