Support specifying custom location of thirdparty packages on makepanda command-line

This commit is contained in:
rdb 2015-03-29 18:16:29 +02:00
parent 0f8f4d63b0
commit 982ece639d
2 changed files with 74 additions and 35 deletions

View File

@ -150,6 +150,9 @@ def usage(problem):
for pkg in PkgListGet():
p = pkg.lower()
print(" --use-%-9s --no-%-9s (enable/disable use of %s)"%(p, p, pkg))
if sys.platform != 'win32':
print(" --<PKG>-incdir (custom location for header files of thirdparty package)")
print(" --<PKG>-libdir (custom location for library files of thirdparty package)")
print("")
print(" --nothing (disable every third-party lib)")
print(" --everything (enable every third-party lib)")
@ -180,11 +183,13 @@ def parseopts(args):
target = None
target_arch = None
universal = False
for pkg in PkgListGet(): longopts.append("no-"+pkg.lower())
for pkg in PkgListGet(): longopts.append("use-"+pkg.lower())
for pkg in PkgListGet():
longopts.append("no-" + pkg.lower())
longopts.append(pkg.lower() + "-incdir=")
longopts.append(pkg.lower() + "-libdir=")
try:
opts, extras = getopt.getopt(args, "", longopts)
for option,value in opts:
for option, value in opts:
if (option=="--help"): raise Exception
elif (option=="--optimize"): optimize=value
elif (option=="--installer"): INSTALLER=1
@ -229,19 +234,25 @@ def parseopts(args):
elif (option=="--use-icl"): BOOUSEINTELCOMPILER = True
else:
for pkg in PkgListGet():
if (option=="--use-"+pkg.lower()):
if option == "--use-" + pkg.lower():
PkgEnable(pkg)
break
for pkg in PkgListGet():
if (option=="--no-"+pkg.lower()):
elif option == "--use-" + pkg.lower():
PkgDisable(pkg)
break
if (option=="--everything" or option.startswith("--use-")
or option=="--nothing" or option.startswith("--no-")):
elif option == "--" + pkg.lower() + "-incdir":
PkgSetCustomLocation(pkg)
IncDirectory(pkg, value)
break
elif option == "--" + pkg.lower() + "-libdir":
PkgSetCustomLocation(pkg)
LibDirectory(pkg, value)
break
if (option == "--everything" or option.startswith("--use-")
or option == "--nothing" or option.startswith("--no-")):
anything = 1
except:
usage(0)
print("Exception while parsing commandline:", sys.exc_info()[0])
usage(sys.exc_info()[1])
if not anything:
if RUNTIME:
@ -4179,7 +4190,7 @@ if (not RUNTIME):
#
if (not RUNTIME and PkgSkip("GL")==0):
OPTS=['DIR:panda/src/glgsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGL', 'NVIDIACG']
OPTS=['DIR:panda/src/glgsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGL', 'GL', 'NVIDIACG']
TargetAdd('p3glgsg_config_glgsg.obj', opts=OPTS, input='config_glgsg.cxx')
TargetAdd('p3glgsg_glgsg.obj', opts=OPTS, input='glgsg.cxx')
@ -4188,7 +4199,7 @@ if (not RUNTIME and PkgSkip("GL")==0):
#
if (not RUNTIME and PkgSkip("GLES")==0):
OPTS=['DIR:panda/src/glesgsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES']
OPTS=['DIR:panda/src/glesgsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES', 'GLES']
TargetAdd('p3glesgsg_config_glesgsg.obj', opts=OPTS, input='config_glesgsg.cxx')
TargetAdd('p3glesgsg_glesgsg.obj', opts=OPTS, input='glesgsg.cxx')
@ -4197,7 +4208,7 @@ if (not RUNTIME and PkgSkip("GLES")==0):
#
if (not RUNTIME and PkgSkip("GLES2")==0):
OPTS=['DIR:panda/src/gles2gsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES2']
OPTS=['DIR:panda/src/gles2gsg', 'DIR:panda/src/glstuff', 'BUILDING:PANDAGLES2', 'GLES2']
TargetAdd('p3gles2gsg_config_gles2gsg.obj', opts=OPTS, input='config_gles2gsg.cxx')
TargetAdd('p3gles2gsg_gles2gsg.obj', opts=OPTS, input='gles2gsg.cxx')

View File

@ -1217,8 +1217,9 @@ def UnsetLinkAllStatic():
##
########################################################################
PKG_LIST_ALL=[]
PKG_LIST_OMIT={}
PKG_LIST_ALL = []
PKG_LIST_OMIT = {}
PKG_LIST_CUSTOM = set()
def PkgListSet(pkgs):
global PKG_LIST_ALL
@ -1244,6 +1245,12 @@ def PkgEnable(pkg):
def PkgDisable(pkg):
PKG_LIST_OMIT[pkg] = 1
def PkgSetCustomLocation(pkg):
PKG_LIST_CUSTOM.add(pkg)
def PkgHasCustomLocation(pkg):
return pkg in PKG_LIST_CUSTOM
def PkgSkip(pkg):
return PKG_LIST_OMIT[pkg]
@ -1401,22 +1408,22 @@ def PkgConfigEnable(opt, pkgname, tool = "pkg-config"):
for i, j in PkgConfigGetDefSymbols(pkgname, tool).items():
DefSymbol(opt, i, j)
def LibraryExists(lib, lpath=[]):
def LocateLibrary(lib, lpath=[]):
""" Returns True if this library was found in the given search path, False otherwise. """
target = GetTarget()
for dir in lpath:
if target == 'darwin' and os.path.isfile(os.path.join(dir, 'lib%s.dylib' % lib)):
return True
return os.path.join(dir, 'lib%s.dylib' % lib)
elif target != 'darwin' and os.path.isfile(os.path.join(dir, 'lib%s.so' % lib)):
return True
return os.path.join(dir, 'lib%s.so' % lib)
elif os.path.isfile(os.path.join(dir, 'lib%s.a' % lib)):
return True
return os.path.join(dir, 'lib%s.a' % lib)
return False
return None
def SystemLibraryExists(lib):
return LibraryExists(lib, SYS_LIB_DIRS)
return LocateLibrary(lib, SYS_LIB_DIRS) is not None
def ChooseLib(libs, thirdparty=None):
""" Chooses a library from the parameters, in order of preference. Returns the first if none of them were found. """
@ -1430,7 +1437,7 @@ def ChooseLib(libs, thirdparty=None):
libname = l
if l.startswith("lib"):
libname = l[3:]
if LibraryExists(libname, lpath):
if LocateLibrary(libname, lpath):
return libname
if len(libs) > 0:
@ -1466,16 +1473,18 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
for d in olddefs:
defs[d] = ""
if (pkg.lower() == "swscale" and os.path.isfile(GetThirdpartyDir() + "ffmpeg/include/libswscale/swscale.h")):
custom_loc = PkgHasCustomLocation(pkg)
if pkg.lower() == "swscale" and os.path.isfile(GetThirdpartyDir() + "ffmpeg/include/libswscale/swscale.h"):
# Let it be handled by the ffmpeg package
LibName(target_pkg, "-lswscale")
return
if (pkg.lower() == "swresample" and os.path.isfile(GetThirdpartyDir() + "ffmpeg/include/libswresample/swresample.h")):
if pkg.lower() == "swresample" and os.path.isfile(GetThirdpartyDir() + "ffmpeg/include/libswresample/swresample.h"):
LibName(target_pkg, "-lswresample")
return
pkg_dir = os.path.join(GetThirdpartyDir(), pkg.lower())
if (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")):
FrameworkDirectory(target_pkg, pkg_dir)
LibName(target_pkg, "-framework " + framework)
@ -1515,7 +1524,7 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
DefSymbol(target_pkg, d, v)
return
elif (GetHost() == "darwin" and framework != None):
elif not custom_loc and GetHost() == "darwin" and framework != None:
prefix = SDK["MACOSX"]
if (os.path.isdir(prefix + "/Library/Frameworks/%s.framework" % framework) or
os.path.isdir(prefix + "/System/Library/Frameworks/%s.framework" % framework) or
@ -1529,7 +1538,7 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
elif VERBOSE:
print(ColorText("cyan", "Couldn't find the framework %s" % (framework)))
elif (LocateBinary(tool) != None and (tool != "pkg-config" or pkgconfig != None)):
elif not custom_loc and LocateBinary(tool) != None and (tool != "pkg-config" or pkgconfig != None):
if (isinstance(pkgconfig, str) or tool != "pkg-config"):
if (PkgConfigHavePkg(pkgconfig, tool)):
return PkgConfigEnable(target_pkg, pkgconfig, tool)
@ -1559,22 +1568,38 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
libname = l
if l.startswith("lib"):
libname = l[3:]
if SystemLibraryExists(libname):
if custom_loc:
# Try searching in the package's LibDirectories.
lpath = [dir for ppkg, dir in LIBDIRECTORIES if pkg == ppkg]
location = LocateLibrary(libname, lpath)
if location is not None:
LibName(target_pkg, location)
else:
have_pkg = False
print(GetColor("cyan") + "Couldn't find library lib" + libname + GetColor())
elif SystemLibraryExists(libname):
# It exists in a system library directory.
LibName(target_pkg, "-l" + libname)
else:
# Try searching in the package's LibDirectories.
lpath = [dir for ppkg, dir in LIBDIRECTORIES if pkg == ppkg or ppkg == "ALWAYS"]
if LibraryExists(libname, lpath):
location = LocateLibrary(libname, lpath)
if location is not None:
LibName(target_pkg, "-l" + libname)
else:
have_pkg = False
if VERBOSE:
if VERBOSE or custom_loc:
print(GetColor("cyan") + "Couldn't find library lib" + libname + GetColor())
# Determine which include directories to look in.
incdirs = list(SYS_INC_DIRS)
incdirs = []
if not custom_loc:
incdirs += list(SYS_INC_DIRS)
for ppkg, pdir in INCDIRECTORIES:
if pkg == ppkg or ppkg == "ALWAYS":
if pkg == ppkg or (ppkg == "ALWAYS" and not custom_loc):
incdirs.append(pdir)
# The incs list contains both subdirectories to explicitly add to
@ -1588,14 +1613,17 @@ def SmartPkgEnable(pkg, pkgconfig = None, libs = None, incs = None, defs = None,
# Note: It's possible to specify a file instead of a dir, for the sake of checking if it exists.
if incdir is None and i.endswith(".h"):
have_pkg = False
if VERBOSE:
if VERBOSE or custom_loc:
print(GetColor("cyan") + "Couldn't find header file " + i + GetColor())
if incdir is not None and os.path.isdir(incdir):
IncDirectory(target_pkg, incdir)
if (not have_pkg):
if (pkg in PkgListGet()):
if not have_pkg:
if custom_loc:
print("%sERROR:%s Could not locate thirdparty package %s in specified directory, aborting build" % (GetColor("red"), GetColor(), pkg.lower()))
exit()
elif pkg in PkgListGet():
print("%sWARNING:%s Could not locate thirdparty package %s, excluding from build" % (GetColor("red"), GetColor(), pkg.lower()))
PkgDisable(pkg)
else: