@ -589,9 +589,12 @@ class PkgConfigDependency(ExternalDependency):
if ret != 0 :
if ret != 0 :
raise DependencyException ( ' Could not generate libs for %s : \n \n %s ' %
raise DependencyException ( ' Could not generate libs for %s : \n \n %s ' %
( self . name , out ) )
( self . name , out ) )
# These libraries should be safe to de-dup
link_args = [ ]
link_args = OrderedSet ( )
# Library paths should be safe to de-dup
libpaths = OrderedSet ( )
libpaths = OrderedSet ( )
# Track -lfoo libraries to avoid duplicate work
libs_found = OrderedSet ( )
# Track not-found libraries to know whether to add library paths
libs_notfound = [ ]
libs_notfound = [ ]
libtype = ' static ' if self . static else ' default '
libtype = ' static ' if self . static else ' default '
# We always look for the file ourselves instead of depending on the
# We always look for the file ourselves instead of depending on the
@ -609,6 +612,9 @@ class PkgConfigDependency(ExternalDependency):
libpaths . add ( lib [ 2 : ] )
libpaths . add ( lib [ 2 : ] )
continue
continue
elif lib . startswith ( ' -l ' ) :
elif lib . startswith ( ' -l ' ) :
# Don't resolve the same -lfoo argument again
if lib in libs_found :
continue
if self . clib_compiler :
if self . clib_compiler :
args = self . clib_compiler . find_library ( lib [ 2 : ] , self . env ,
args = self . clib_compiler . find_library ( lib [ 2 : ] , self . env ,
list ( libpaths ) , libtype )
list ( libpaths ) , libtype )
@ -618,10 +624,11 @@ class PkgConfigDependency(ExternalDependency):
else :
else :
args = None
args = None
if args :
if args :
libs_found . add ( lib )
# Replace -l arg with full path to library if available
# Replace -l arg with full path to library if available
# else, library is provided by the compiler and can't be resolved
if not args [ 0 ] . startswith ( ' -l ' ) :
if not args [ 0 ] . startswith ( ' -l ' ) :
lib = args [ 0 ]
lib = args [ 0 ]
# else, library is provided by the compiler and can't be resolved
else :
else :
# Library wasn't found, maybe we're looking in the wrong
# Library wasn't found, maybe we're looking in the wrong
# places or the library will be provided with LDFLAGS or
# places or the library will be provided with LDFLAGS or
@ -645,10 +652,12 @@ class PkgConfigDependency(ExternalDependency):
raise DependencyException ( ' Got a libtools specific " %s " dependencies '
raise DependencyException ( ' Got a libtools specific " %s " dependencies '
' but we could not compute the actual shared '
' but we could not compute the actual shared '
' library path ' % lib )
' library path ' % lib )
lib = shared_lib
self . is_libtool = True
self . is_libtool = True
link_args . add ( lib )
lib = shared_lib
self . link_args = list ( link_args )
if lib in link_args :
continue
link_args . append ( lib )
self . link_args = link_args
# Add all -Lbar args if we have -lfoo args in link_args
# Add all -Lbar args if we have -lfoo args in link_args
if libs_notfound :
if libs_notfound :
# Order of -L flags doesn't matter with ld, but it might with other
# Order of -L flags doesn't matter with ld, but it might with other