More robust location of libraries in thirdparty packages on Linux

This commit is contained in:
rdb 2016-04-24 01:45:24 +02:00
parent 2c6a6c9f06
commit c8f59367d1

View File

@ -1409,10 +1409,16 @@ def PkgConfigEnable(opt, pkgname, tool = "pkg-config"):
for i, j in PkgConfigGetDefSymbols(pkgname, tool).items(): for i, j in PkgConfigGetDefSymbols(pkgname, tool).items():
DefSymbol(opt, i, j) DefSymbol(opt, i, j)
def LocateLibrary(lib, lpath=[]): def LocateLibrary(lib, lpath=[], prefer_static=False):
""" Returns True if this library was found in the given search path, False otherwise. """ """Searches for the library in the search path, returning its path if found,
or None if it was not found."""
target = GetTarget() target = GetTarget()
if prefer_static and target != 'windows':
for dir in lpath:
if os.path.isfile(os.path.join(dir, 'lib%s.a' % lib)):
return os.path.join(dir, 'lib%s.a' % lib)
for dir in lpath: for dir in lpath:
if target == 'darwin' and os.path.isfile(os.path.join(dir, 'lib%s.dylib' % lib)): if target == 'darwin' and os.path.isfile(os.path.join(dir, 'lib%s.dylib' % lib)):
return os.path.join(dir, 'lib%s.dylib' % lib) return os.path.join(dir, 'lib%s.dylib' % lib)
@ -1484,6 +1490,7 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
LibName(target_pkg, "-lswresample") LibName(target_pkg, "-lswresample")
return return
# First check if the package is in the thirdparty directory.
pkg_dir = os.path.join(GetThirdpartyDir(), pkg.lower()) pkg_dir = os.path.join(GetThirdpartyDir(), pkg.lower())
if not custom_loc and os.path.isdir(pkg_dir): if not custom_loc and os.path.isdir(pkg_dir):
if framework and os.path.isdir(os.path.join(pkg_dir, framework + ".framework")): if framework and os.path.isdir(os.path.join(pkg_dir, framework + ".framework")):
@ -1494,32 +1501,55 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
if os.path.isdir(os.path.join(pkg_dir, "include")): if os.path.isdir(os.path.join(pkg_dir, "include")):
IncDirectory(target_pkg, os.path.join(pkg_dir, "include")) IncDirectory(target_pkg, os.path.join(pkg_dir, "include"))
if os.path.isdir(os.path.join(pkg_dir, "lib")): # Handle cases like freetype2 where the include dir is a subdir under "include"
LibDirectory(target_pkg, os.path.join(pkg_dir, "lib")) for i in incs:
if os.path.isdir(os.path.join(pkg_dir, "include", i)):
IncDirectory(target_pkg, os.path.join(pkg_dir, "include", i))
if (PkgSkip("PYTHON") == 0): lpath = [os.path.join(pkg_dir, "lib")]
if not PkgSkip("PYTHON"):
py_lib_dir = os.path.join(pkg_dir, "lib", SDK["PYTHONVERSION"]) py_lib_dir = os.path.join(pkg_dir, "lib", SDK["PYTHONVERSION"])
if os.path.isdir(py_lib_dir): if os.path.isdir(py_lib_dir):
LibDirectory(target_pkg, py_lib_dir) lpath.append(py_lib_dir)
# TODO: check for a .pc file in the lib/pkg-config/ dir # TODO: check for a .pc file in the lib/pkgconfig/ dir
if (tool != None and os.path.isfile(os.path.join(pkg_dir, "bin", tool))): if (tool != None and os.path.isfile(os.path.join(pkg_dir, "bin", tool))):
tool = os.path.join(pkg_dir, "bin", tool) tool = os.path.join(pkg_dir, "bin", tool)
for i in PkgConfigGetLibs(None, tool): for i in PkgConfigGetLibs(None, tool):
LibName(target_pkg, i) if i.startswith('-l'):
# To make sure we don't pick up the system copy, write out
# the full path instead.
libname = i[2:]
location = LocateLibrary(libname, lpath, prefer_static=True)
if location is not None:
LibName(target_pkg, location)
else:
print(GetColor("cyan") + "Couldn't find library lib" + libname + " in thirdparty directory " + pkg.lower() + GetColor())
LibName(target_pkg, i)
else:
LibName(target_pkg, i)
for i, j in PkgConfigGetDefSymbols(None, tool).items(): for i, j in PkgConfigGetDefSymbols(None, tool).items():
DefSymbol(target_pkg, i, j) DefSymbol(target_pkg, i, j)
return return
# Now search for the libraries in the package's lib directories.
for l in libs: for l in libs:
libname = l libname = l
if l.startswith("lib"): if l.startswith("lib"):
libname = l[3:] libname = l[3:]
# This is for backward compatibility - in the thirdparty dir, we kept some libs with "panda" prefix, like libpandatiff.
if len(glob.glob(os.path.join(pkg_dir, "lib", "libpanda%s.*" % (libname)))) > 0 \ location = LocateLibrary(libname, lpath, prefer_static=True)
and len(glob.glob(os.path.join(pkg_dir, "lib", "lib%s.*" % (libname)))) == 0: if location is not None:
libname = "panda" + libname LibName(target_pkg, location)
LibName(target_pkg, "-l" + libname) else:
# This is for backward compatibility - in the thirdparty dir,
# we kept some libs with "panda" prefix, like libpandatiff.
location = LocateLibrary("panda" + libname, lpath, prefer_static=True)
if location is not None:
LibName(target_pkg, location)
else:
print(GetColor("cyan") + "Couldn't find library lib" + libname + " in thirdparty directory " + pkg.lower() + GetColor())
for d, v in defs.values(): for d, v in defs.values():
DefSymbol(target_pkg, d, v) DefSymbol(target_pkg, d, v)