def GetMayaRoot(noWarn=False): mayaspec = excons.GetArgument("with-maya") if "MAYA_LOCATION" in os.environ: if not "with-maya" in ARGUMENTS: # MAYA_LOCATION environment is set and with-maya is either undefined or read from cache excons.PrintOnce("Using MAYA_LOCATION environment.", tool="maya") mayadir = os.environ["MAYA_LOCATION"] return mayadir else: excons.PrintOnce("Ignoring MAYA_LOCATION environment.", tool="maya") if not mayaspec: if not noWarn: #excons.WarnOnce("Please set Maya version or directory using with-maya=", tool="maya") excons.WarnConfig() return None if not os.path.isdir(mayaspec): if not re.match(r"\d+(\.\d+)?", mayaspec): if not noWarn: excons.WarnOnce( "Invalid Maya specification \"%s\": Must be a directory or a version number" % mayaspec, tool="maya") return None ver = mayaspec if sys.platform == "win32": if excons.arch_dir == "x64": mayadir = "C:/Program Files/Autodesk/Maya%s" % ver else: mayadir = "C:/Program Files (x86)/Autodesk/Maya%s" % ver elif sys.platform == "darwin": mayadir = "/Applications/Autodesk/maya%s" % ver else: mayadir = "/usr/autodesk/maya%s" % ver if excons.arch_dir == "x64" and os.path.isdir(mayadir + "-x64"): mayadir += "-x64" else: mayadir = mayaspec.replace("\\", "/") if len(mayadir) > 0 and mayadir[-1] == "/": mayadir = mayadir[:-1] return mayadir
def CleanOne(name): if not SCons.Script.GetOption("clean"): return # Remove output files for path in Outputs(name): path = excons.out_dir + "/" + path if os.path.isfile(path): os.remove(path) excons.Print("Removed: '%s'" % excons.NormalizedRelativePath(path, excons.out_dir), tool="automake") # Remove build temporary files buildDir = BuildDir(name) if os.path.isdir(buildDir): env = None if sys.platform != "win32": _env = excons.devtoolset.GetDevtoolsetEnv(excons.GetArgument( "devtoolset", ""), merge=True) if _env: env = os.environ.copy() env.update(_env) subprocess.Popen("cd \"%s\"; make distclean" % buildDir, shell=True, env=env).communicate() shutil.rmtree(buildDir) excons.Print("Removed: '%s'" % excons.NormalizedRelativePath(buildDir, excons.out_dir), tool="automake") path = ConfigCachePath(name) if os.path.isfile(path): os.remove(path) excons.Print("Removed: '%s'" % excons.NormalizedRelativePath(path, excons.out_dir), tool="automake") path = OutputsCachePath(name) if os.path.isfile(path): os.remove(path) excons.Print("Removed: '%s'" % excons.NormalizedRelativePath(path, excons.out_dir), tool="automake")
def Version(asString=True, nice=False): mayadir = GetMayaRoot(noWarn=True) if not mayadir: return (None if not asString else "") mayainc = GetMayaInc(mayadir) mayaspec = excons.GetArgument("with-maya") if mayaspec is not None and not os.path.isdir(mayaspec): wantedver = mayaspec else: wantedver = None mtypes = excons.joinpath(mayainc, "maya", "MTypes.h") if os.path.isfile(mtypes): defexp = re.compile(r"^\s*#define\s+MAYA_API_VERSION\s+([0-9]+)") f = open(mtypes, "r") for line in f.readlines(): m = defexp.match(line) if m: year = int(m.group(1)[:4]) sub = int(m.group(1)[4]) if wantedver is not None: usever = "%d%s" % (year, ".5" if sub >= 5 else "") if usever != wantedver: excons.WarnOnce( "Maya headers version (%s) doesn't seem to match requested one (%s).\nMake sure to set or reset devkit path using 'with-mayadevkit=' flag." % (usever, wantedver)) if nice: # Maya 2013 and 2016 have a binary incompatible .5 version if sub >= 5 and year in (2013, 2016): return (year + 0.5 if not asString else "%d.5" % year) else: return (year if not asString else str(year)) else: return (int(m.group(1)) if not asString else m.group(1)) f.close() excons.WarnOnce("Cannot find maya headers (missing with-mayadevkit= ?).") return (None if not asString else "")
def Configure(name, topdir=None, opts=None): if SCons.Script.GetOption("clean"): return True if opts is None: opts = {} if topdir is None: topdir = os.path.abspath(".") bld = BuildDir(name) relpath = os.path.relpath(topdir, bld) cmd = "cd \"%s\"; %s/configure " % (bld, relpath) for k, v in opts.iteritems(): if type(v) == bool: if v: cmd += "%s " % k else: cmd += "%s=%s " % (k, ("\"%s\"" % v if type(v) in (str, unicode) else v)) cmd += "--prefix=\"%s\"" % excons.OutputBaseDirectory() env = None if sys.platform != "win32": _env = excons.devtoolset.GetDevtoolsetEnv(excons.GetArgument( "devtoolset", ""), merge=True) if _env: env = os.environ.copy() env.update(_env) excons.Print("Run Command: %s" % cmd, tool="automake") p = subprocess.Popen(cmd, env=env, shell=True) p.communicate() return (p.returncode == 0)
def Require(env): glutinc, glutlib = excons.GetDirs("glut") glutlibsuffix = excons.GetArgument("glut-libsuffix", "") if glutinc: env.Append(CPPPATH=[glutinc]) if glutlib: env.Append(LIBPATH=[glutlib]) if sys.platform == "win32": env.Append(CPPDEFINES=["GLUT_NO_LIB_PRAGMA"]) if excons.Build64(): env.Append(LIBS=["glut64%s" % glutlibsuffix]) else: env.Append(LIBS=["glut32"]) elif sys.platform == "darwin": env.Append(LINKFLAGS=" -framework GLUT") else: env.Append(LIBS=["glut%s" % glutlibsuffix])
def GetMayaInc(mayadir): # Starting maya 2016, the base install doesn't come with include files require_mdk = False if sys.platform == "darwin": require_mdk = not os.path.isdir(mayadir + "/devkit/include/maya") else: require_mdk = not os.path.isdir(mayadir + "/include/maya") mdk = (None if not require_mdk else excons.GetArgument("with-mayadevkit")) if "MAYA_INCLUDE" in os.environ: if not require_mdk or "with-mayadevkit" not in SCons.Script.ARGUMENTS: # MAYA_INCLUDE environment is set and maya is older than 2016 or with-mayadevkit is either undefined or read from cache excons.PrintOnce("Using MAYA_INCLUDE environment.", tool="maya") mayainc = os.environ["MAYA_INCLUDE"] return mayainc else: excons.PrintOnce("Ignoring MAYA_INCLUDE environment.", tool="maya") if mdk is None: if sys.platform == "darwin": mayainc = mayadir + "/devkit/include" else: mayainc = mayadir + "/include" else: mdk = mdk.replace("\\", "/") if len(mdk) > 0 and mdk[-1] == "/": mdk = mdk[:-1] if os.path.isabs(mdk): mayainc = mdk + "/include" else: mayainc = mayadir + "/" + mdk + "/include" return mayainc
def Require(env): glew_inc, glew_lib = excons.GetDirs("glew") glew_static = (excons.GetArgument("glew-static", 1, int) != 0) glew_no_glu = (excons.GetArgument("glew-noglu", 1, int) != 0) glew_mx = (excons.GetArgument("glew-mx", 0, int) != 0) if glew_inc: env.Append(CPPPATH=[glew_inc]) if glew_lib: env.Append(LIBPATH=[glew_lib]) defs = [] if glew_no_glu: defs.append("GLEW_NO_GLU") if glew_static: defs.append("GLEW_STATIC") if glew_mx: defs.append("GLEW_MX") env.Append(CPPDEFINES=defs) glew_libname = excons.GetArgument("glew-name", None) if not glew_libname: glew_libprefix = excons.GetArgument("glew-prefix", "") glew_libsuffix = excons.GetArgument("glew-suffix", "") glew_libname = glew_libprefix + ("glew32" if sys.platform == "win32" else "GLEW") + glew_libsuffix if glew_mx: glew_libname += "mx" if sys.platform == "win32" and glew_static: glew_libname += "s" excons.Link(env, glew_libname, static=glew_static, force=True, silent=True) excons.AddHelpOptions(glew=GetOptionsString())
def BuildDir(name): buildDir = excons.BuildBaseDirectory() + "/" + name if sys.platform == "win32": buildDir += "/msvc-%s" % excons.GetArgument("mscver", "10.0") return buildDir
def Require(env): excons.AddHelpOptions(nuke=GetOptionsString()) nukespec = excons.GetArgument("with-nuke") if nukespec is None: excons.WarnOnce( "Please set Nuke version or directory using with-nuke=", tool="nuke") return idn = ("Contents/MacOS/include" if sys.platform == "darwin" else "include") ldn = ("Contents/MacOS" if sys.platform == "darwin" else "") if os.path.isdir(nukespec): if sys.platform == "darwin": bn = os.path.basename(nukespec) _, ext = os.path.splitext(bn) if ext != ".app": nukespec += "/%s.app" % bn excons.SetArgument("with-nuke", nukespec) ndkinc, ndklib = excons.GetDirs("nuke", incdirname=idn, libdirname=ldn, libdirarch="none") else: if not re.match(r"\d+\.\d+v\d+", nukespec): excons.WarnOnce("Invalid Nuke version format: \"%s\"" % nukespec, tool="nuke") return if sys.platform == "win32": ndkbase = "C:/Program Files/Nuke%s" % nukespec elif sys.platform == "darwin": ndkbase = "/Applications/Nuke%s/Nuke%s.app" % (nukespec, nukespec) else: ndkbase = "/usr/local/Nuke%s" % nukespec ndkinc = "%s/%s" % (ndkbase, idn) ndklib = "%s/%s" % (ndkbase, ldn) if ldn else ndkbase if ndkinc: env.Append(CPPPATH=[ndkinc]) if ndklib: env.Append(LIBPATH=[ndklib]) if sys.platform == "darwin": #env.Append(CCFLAGS=" -isysroot /Developer/SDKs/MacOSX10.4u.sdk") #env.Append(LINKFLAGS=" -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk") #env.Append(LINKFLAGS=" -framework QuartzCore -framework IOKit -framework CoreFoundation -framework Carbon -framework ApplicationServices -framework OpenGL -framework AGL -framework Quicktime") pass env.Append(DEFINES=["USE_GLEW"]) if sys.platform != "win32": env.Append(CCFLAGS=" -Wno-unused-variable -Wno-unused-parameter") env.Append(LIBS=["DDImage", "GLEW"]) else: env.Append(LIBS=["DDImage", "glew32"])
def Require(libs=None): if libs is None: libs = [] boost_inc_dir, boost_lib_dir = excons.GetDirs("boost") static = (excons.GetArgument("boost-static", 0, int) != 0) boost_libprefix = excons.GetArgument("boost-prefix", "") boost_libsuffix = excons.GetArgument("boost-suffix", "") useautolink = False if sys.platform == "win32": useautolink = (excons.GetArgument("boost-autolink", 1, int) != 0) libargs = {} for lib in libs: incdir, libdir = excons.GetDirs("boost-%s" % lib) libname = excons.GetArgument("boost-%s-name" % lib, None) if libname is None: libprefix = excons.GetArgument("boost-%s-prefix" % lib, boost_libprefix) libsuffix = excons.GetArgument("boost-%s-suffix" % lib, boost_libsuffix) libname = "%sboost_%s%s" % (libprefix, lib, libsuffix) libstatic = (excons.GetArgument("boost-%s-static" % lib, (1 if static else 0), int) != 0) autolinklib = False if sys.platform == "win32": autolinklib = (excons.GetArgument("boost-%s-autolink" % lib, (1 if useautolink else 0), int) != 0) libargs[lib] = { "incdir": incdir, "libdir": libdir, "name": libname, "static": libstatic, "autolink": autolinklib } def _RealRequire(env): if boost_inc_dir: env.Append(CPPPATH=boost_inc_dir) if boost_lib_dir: env.Append(LIBPATH=boost_lib_dir) autolinkcount = 0 defs = [] # All libs but Boost.Python are statically linked by default # => use BOOST_PYTHON_STATIC_LIB to enable static linking # Libraries are auto-linked on windows by default # => disable for all libraries using BOOST_ALL_NO_LIB # => disable for a specific lib using BOOST_[libraryname]_NO_LIB for lib in libs: incdir = libargs[lib]["incdir"] libdir = libargs[lib]["libdir"] libname = libargs[lib]["name"] libstatic = libargs[lib]["static"] autolinklib = libargs[lib]["autolink"] if incdir: env.Append(CPPPATH=[incdir]) if libdir: env.Append(LIBPATH=[libdir]) if sys.platform == "win32": if not autolinklib: defs.append("BOOST_%s_NO_LIB" % lib.upper()) else: autolinkcount += 1 if libstatic: if lib == "thread": # Not to confure with the 'LIB' meaning of BOOST_xxx_NO_LIB defs.append("BOOST_THREAD_USE_LIB") elif lib == "python": # Boost.Python is dynamically linked by 'default' defs.append("BOOST_PYTHON_STATIC_LIB") else: # Should not have to make a special case of Boost.Thread anymore, but # for backward compatibility sake if lib == "thread": defs.append("BOOST_THREAD_USE_DLL") elif lib != "python": defs.append("BOOST_%s_DYN_LINK" % lib.upper()) if not autolinklib: excons.Link(env, libname, static=libstatic, force=True, silent=True) if sys.platform == "win32" and autolinkcount == 0: defs.append("BOOST_ALL_NO_LIB") env.Append(CPPDEFINES=defs) excons.AddHelpOptions(boost=GetOptionsString()) return _RealRequire
def Build(name, config=None, target=None): if GetOption("clean"): return True ccf = ConfigCachePath(name) cof = OutputsCachePath(name) if not os.path.isfile(ccf): return False success = False outfiles = set() if config is None: config = excons.mode_dir if target is None: target = "install" cmd = "cd \"%s\" %s cmake --build . --config %s --target %s" % ( BuildDir(name), CmdSep, config, target) extraargs = "" njobs = GetOption("num_jobs") if njobs > 1: if sys.platform == "win32": extraargs += " /m:%d" % njobs else: extraargs += " -j %d" % njobs if excons.GetArgument("show-cmds", 0, int): if sys.platform == "win32": extraargs += " /v:n" # normal verbosity else: extraargs += " V=1" else: if sys.platform == "win32": extraargs += " /v:m" # minimal verbosity if extraargs: cmd += " --" + extraargs excons.Print("Run Command: %s" % cmd, tool="cmake") p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = "" while p.poll() is None: r = p.stdout.readline(512) buf += r lines = buf.split("\n") if len(lines) > 1: buf = lines[-1] ParseOutputsInLines(lines[:-1], outfiles) ParseOutputsInLines(buf.split("\n"), outfiles) excons.Print(buf, tool="cmake") # Write list of outputed files if p.returncode == 0: with open(cof, "w") as f: lst = list(outfiles) lst.sort() f.write("\n".join( excons.NormalizedRelativePaths(lst, excons.out_dir))) return True else: if os.path.isfile(cof): os.remove(cof) return False
def Require(ilmthread=None, iexmath=None, python=None, halfonly=False): if not halfonly: if ilmthread is None: ilmthread = (excons.GetArgument("ilmbase-thread", 1, int) != 0) if iexmath is None: iexmath = (excons.GetArgument("ilmbase-iexmath", 1, int) != 0) if python is None: python = (excons.GetArgument("ilmbase-python", 0, int) != 0) else: ilmthread = False iexmath = False python = False ilmbase_libsuffix = excons.GetArgument("ilmbase-suffix", "") ilmbase_libprefix = excons.GetArgument("ilmbase-prefix", "") pyilmbase_inc, pyilmbase_lib, pyilmbase_libprefix, pyilmbase_libsuffix = "", "", "", "" if python: pyilmbase_inc, pyilmbase_lib = excons.GetDirs("ilmbase-python") if pyilmbase_inc and not pyilmbase_inc.endswith("OpenEXR"): pyilmbase_inc += "/OpenEXR" pyilmbase_libprefix = excons.GetArgument("ilmbase-python-prefix", ilmbase_libprefix) pyilmbase_libsuffix = excons.GetArgument("ilmbase-python-suffix", ilmbase_libsuffix) ilmbase_inc, ilmbase_lib = excons.GetDirs("ilmbase") if ilmbase_inc and not ilmbase_inc.endswith("OpenEXR"): ilmbase_inc += "/OpenEXR" static = (excons.GetArgument("ilmbase-static", 0, int) != 0) pystatic = static if python: pystatic = (excons.GetArgument("ilmbase-python-static", (1 if static else 0), int) != 0) excons.AddHelpOptions(ilmbase=GetOptionsString()) def _RealRequire(env): # Add python bindings first if python: if pystatic: env.Append(CPPDEFINES=["PLATFORM_BUILD_STATIC"]) if sys.platform != "win32": env.Append(CPPDEFINES=["PLATFORM_VISIBILITY_AVAILABLE"]) if pyilmbase_inc: env.Append(CPPPATH=[pyilmbase_inc, os.path.dirname(pyilmbase_inc)]) if pyilmbase_lib: env.Append(LIBPATH=[pyilmbase_lib]) excons.Link(env, "%sPyImath%s" % (pyilmbase_libprefix, pyilmbase_libsuffix), static=pystatic, silent=True) excons.Link(env, "%sPyIex%s" % (pyilmbase_libprefix, pyilmbase_libsuffix), static=pystatic, silent=True) if ilmbase_inc: env.Append(CPPPATH=[ilmbase_inc, os.path.dirname(ilmbase_inc)]) if ilmbase_lib: env.Append(LIBPATH=[ilmbase_lib]) if sys.platform == "win32" and not static: env.Append(CPPDEFINES=["OPENEXR_DLL"]) if ilmthread: # ilmthread will be False if halfonly is True libname = "%sIlmThread%s" % (ilmbase_libprefix, ilmbase_libsuffix) excons.Link(env, libname, static=static, force=True, silent=True) if not halfonly: libname = "%sImath%s" % (ilmbase_libprefix, ilmbase_libsuffix) excons.Link(env, libname, static=static, force=True, silent=True) if iexmath: # iexmath will be False if halfonly is True libname = "%sIexMath%s" % (ilmbase_libprefix, ilmbase_libsuffix) excons.Link(env, libname, static=static, force=True, silent=True) if not halfonly: libname = "%sIex%s" % (ilmbase_libprefix, ilmbase_libsuffix) excons.Link(env, libname, static=static, force=True, silent=True) libname = "%sHalf%s" % (ilmbase_libprefix, ilmbase_libsuffix) excons.Link(env, libname, static=static, force=True, silent=True) return _RealRequire
def IsStaticallyLinked(lib): static = (excons.GetArgument("boost-static", 0, int) != 0) return (excons.GetArgument("boost-%s-static" % lib, (1 if static else 0), int) != 0)
def Build(name, target=None): if GetOption("clean"): return True ccf = ConfigCachePath(name) cof = OutputsCachePath(name) if not os.path.isfile(ccf): return False outfiles = set() symlinks = {} success = False if target is None: target = "install" njobs = GetOption("num_jobs") cmd = "cd \"%s\"; make" % BuildDir(name) if njobs > 1: cmd += " -j %d" % njobs if excons.GetArgument("show-cmds", 0, int): cmd += " V=1" cmd += " %s" % target excons.Print("Run Command: %s" % cmd, tool="automake") p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = "" while p.poll() is None: r = p.stdout.readline(512) buf += r lines = buf.split("\n") if len(lines) > 1: buf = lines[-1] ParseOutputsInLines(lines[:-1], outfiles, symlinks) ParseOutputsInLines(buf.split("\n"), outfiles, symlinks) excons.Print(buf, tool="automake") if p.returncode == 0: with open(cof, "w") as f: lst = list(outfiles) # Add symlinks ll = len(lst) for i in xrange(ll): bn = os.path.basename(lst[i]) if bn in symlinks: dn = os.path.dirname(lst[i]) for l in symlinks[bn]: sln = dn + "/" + l if not sln in lst: lst.append(sln) #print("ADD - %s" % sln) lst.sort() f.write("\n".join( excons.NormalizedRelativePaths(lst, excons.out_dir))) return True else: if os.path.isfile(cof): os.remove(cof) return False
def _RealRequire(env): global ThreadSafe_exp, Szlib_exp, Zlib_exp, hdf5_confs hdf5_inc, hdf5_lib = excons.GetDirs("hdf5") if hdf5_inc: env.Append(CPPPATH=[hdf5_inc]) if hdf5_lib: env.Append(LIBPATH=[hdf5_lib]) hdf5_libname = excons.GetArgument("hdf5-libname", None) if not hdf5_libname: hdf5_libsuffix = excons.GetArgument("hdf5-libsuffix", "") hdf5_basename = ("hdf5" if sys.platform != "win32" else "libhdf5") hdf5_libname = hdf5_basename + hdf5_libsuffix hdf5hl_libname = hdf5_basename + "_hl" + hdf5_libsuffix else: hdf5hl_libname = hdf5_libname + "_hl" if hl: env.Append(LIBS=[hdf5hl_libname, hdf5_libname]) else: env.Append(LIBS=[hdf5_libname]) hdf5_static = (excons.GetArgument("hdf5-static", 0, int) != 0) hdf5_threadsafe = False hdf5_szip = False hdf5_zlib = False h5conf = None if hdf5_inc: # Note: On Fedora 14, H5pubconf.h has been renamed to H5pubconf-64.h # -> be slightly more flexible when looking up this file lst = filter(lambda x: os.path.basename(x).startswith("H5pubconf"), glob.glob(hdf5_inc + "/*.h")) if len(lst) > 0: h5conf = lst[0].replace("\\", "/") else: # Look in current include paths for d in env["CPPPATH"]: lst = filter( lambda x: os.path.basename(x).startswith("H5pubconf"), glob.glob(d + "/*.h")) if len(lst) > 0: h5conf = lst[0].replace("\\", "/") break quiet = not verbose if h5conf: if h5conf in hdf5_confs: hdf5_threadsafe = hdf5_confs[h5conf]["threadsafe"] hdf5_zlib = hdf5_confs[h5conf]["zlib"] hdf5_szip = hdf5_confs[h5conf]["szip"] quiet = True else: if verbose: excons.PrintOnce("Reading configuration header '%s'..." % h5conf, tool="hdf5") f = open(h5conf, "r") for l in f.readlines(): l = l.strip() if ThreadSafe_exp.match(l): hdf5_threadsafe = True elif Szip_exp.match(l): hdf5_szip = True elif Zlib_exp.match(l): hdf5_zlib = True hdf5_confs[h5conf] = { "threadsafe": hdf5_threadsafe, "zlib": hdf5_zlib, "szip": hdf5_szip } f.close() if not quiet: if hdf5_threadsafe: excons.PrintOnce("Thread safe", tool="hdf5") if hdf5_zlib: excons.PrintOnce("Using zlib", tool="hdf5") if hdf5_szip: excons.PrintOnce("Using szip", tool="hdf5") else: excons.WarnOnce("Could not find configuration header", tool="hdf5") if hdf5_static: if not quiet: excons.PrintOnce("Static build", tool="hdf5") if hdf5_threadsafe: threads.Require(env) if hdf5_zlib: if excons.GetArgument("zlib-static", None) is None: if not quiet: excons.PrintOnce("Force static zlib", tool="hdf5") excons.SetArgument("zlib-static", 1) zlib.Require(env) if hdf5_szip: szip_static = excons.GetArgument("szip-static", None) if szip_static is None: if not quiet: excons.PrintOnce("Force static szip", tool="hdf5") excons.SetArgument("szip-static", 1) szip.Require(env)
def Configure(name, topdir=None, opts={}, min_mscver=None, flags=None): if SCons.Script.GetOption("clean"): return True if topdir is None: topdir = os.path.abspath(".") bld = BuildDir(name) relpath = os.path.relpath(topdir, bld) cmd = "cd \"%s\" %s %s " % (bld, CmdSep, excons.GetArgument("with-cmake", "cmake")) env = None if sys.platform == "win32": try: mscver = float(excons.GetArgument("mscver", "10.0")) if min_mscver is not None and mscver < min_mscver: mscver = min_mscver if mscver == 9.0: cmd += "-G \"Visual Studio 9 2008 Win64\" " elif mscver == 10.0: cmd += "-G \"Visual Studio 10 2010 Win64\" " elif mscver == 11.0: cmd += "-G \"Visual Studio 11 2012 Win64\" " elif mscver == 12.0: cmd += "-G \"Visual Studio 12 2013 Win64\" " elif mscver == 14.0: cmd += "-G \"Visual Studio 14 2015 Win64\" " elif mscver == 14.1: cmd += "-G \"Visual Studio 15 2017 Win64\" " elif mscver == 14.2: cmd += "-G \"Visual Studio 16 2019 Win64\" " else: excons.Print("Unsupported visual studio version %s" % mscver, tool="cmake") return False except: return False else: _env = excons.devtoolset.GetDevtoolsetEnv(excons.GetArgument( "devtoolset", ""), merge=True) if _env: env = os.environ.copy() env.update(_env) if flags: if not cmd.endswith(" "): cmd += " " cmd += flags if not flags.endswith(" "): cmd += " " for k, v in opts.iteritems(): cmd += "-D%s=%s " % (k, ("\"%s\"" % v if type(v) in (str, unicode) else v)) cmd += "-DCMAKE_INSTALL_PREFIX=\"%s\" " % excons.OutputBaseDirectory() if sys.platform != "win32": cmd += "-DCMAKE_SKIP_BUILD_RPATH=0 " cmd += "-DCMAKE_BUILD_WITH_INSTALL_RPATH=0 " cmd += "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=0 " if sys.platform == "darwin": cmd += "-DCMAKE_MACOSX_RPATH=1 " cmd += relpath excons.Print("Run Command: %s" % cmd, tool="cmake") p = subprocess.Popen(cmd, env=env, shell=True) p.communicate() return (p.returncode == 0)
def Build(name, config=None, target=None): if SCons.Script.GetOption("clean"): return True ccf = ConfigCachePath(name) cof = OutputsCachePath(name) if not os.path.isfile(ccf): return False outfiles = set() if config is None: config = excons.mode_dir if target is None: target = "install" cmd = "cd \"%s\" %s %s --build . --config %s --target %s" % ( BuildDir(name), CmdSep, excons.GetArgument("with-cmake", "cmake"), config, target) env = None extraargs = "" njobs = SCons.Script.GetOption("num_jobs") if njobs > 1: if sys.platform == "win32": extraargs += " /m:%d" % njobs else: extraargs += " -j %d" % njobs if excons.GetArgument("show-cmds", 0, int): if sys.platform == "win32": extraargs += " /v:n" # normal verbosity else: extraargs += " V=1" else: if sys.platform == "win32": extraargs += " /v:m" # minimal verbosity if extraargs and (sys.platform != "win32" or float(excons.GetArgument("mscver", "10.0")) >= 10.0): cmd += " --" + extraargs if sys.platform != "win32": _env = excons.devtoolset.GetDevtoolsetEnv(excons.GetArgument( "devtoolset", ""), merge=True) if _env: env = os.environ.copy() env.update(_env) excons.Print("Run Command: %s" % cmd, tool="cmake") p = subprocess.Popen(cmd, shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) buf = "" while p.poll() is None: r = p.stdout.readline(512) buf += r lines = buf.split("\n") if len(lines) > 1: buf = lines[-1] ParseOutputsInLines(lines[:-1], outfiles) ParseOutputsInLines(buf.split("\n"), outfiles) excons.Print(buf, tool="cmake") # Write list of outputed files if p.returncode == 0: with open(cof, "w") as f: lst = filter(VC_Filter, outfiles) lst.sort() f.write("\n".join( excons.NormalizedRelativePaths(lst, excons.out_dir))) return True else: if os.path.isfile(cof): os.remove(cof) return False
def SetupEnvironment(env, settings): if sys.platform == "win32": return None name = settings["name"] debug = (excons.GetArgument("debug", 0, int) != 0) opts = settings.get("automake-opts", {}) agenf = excons.abspath("./autogen.sh") conff = excons.abspath("./configure") blddir = automake.BuildDir(name) makef = blddir + "/Makefile" cfgc = automake.ConfigCachePath(name) cexts = [".c", ".h", ".cc", ".hh", ".cpp", ".hpp", ".cxx", ".hxx"] # Override default C/C++ file scanner to avoid SCons being too nosy env.Prepend(SCANNERS=Scanner(function=DummyScanner, skeys=cexts)) env["AUTOMAKE_PROJECT"] = name env["AUTOMAKE_TOPDIR"] = excons.abspath(".") env["AUTOMAKE_OPTIONS"] = opts env["AUTOMAKE_TARGET"] = settings.get("automake-target", "install") env["AUTOMAKE_CONFIGURE"] = conff env["AUTOMAKE_AUTOGEN"] = agenf env["AUTOMAKE_MAKEFILE"] = makef env["AUTOMAKE_CONFIG_CACHE"] = cfgc env["BUILDERS"]["Autoconf"] = Builder( action=Action(AutoconfAction, "Running autoconf ...")) env["BUILDERS"]["AutomakeConfigure"] = Builder( action=Action(ConfigureAction, "Configure using Automake ...")) env["BUILDERS"]["Automake"] = Builder( action=Action(BuildAction, "Build using Automake ...")) # Check if we need to reconfigure if not GetOption("clean"): if not os.path.isdir(blddir): try: os.makedirs(blddir) except: return None doconf = True if os.path.isfile(cfgc): doconf = False with open(cfgc, "r") as f: try: d = eval(f.read()) for k, v in d.iteritems(): if not k in opts or opts[k] != v: doconf = True break if not doconf: for k, v in opts.iteritems(): if not k in d: doconf = True break except: doconf = True if doconf or int(ARGUMENTS.get("reconfigure", "0")) != 0: # Only rewrite cfgc when strictly needed if doconf: with open(cfgc, "w") as f: pprint.pprint(opts, stream=f) if os.path.isfile(makef): os.remove(makef) # Could be a autogen.sh script too acins = [] if os.path.isfile(conff + ".ac"): acins = [conff + ".ac"] elif os.path.isfile(agenf): acins = [agenf] if acins: # Don't clean generated configure env.NoClean(env.Autoconf([conff], acins)) cins = settings.get("automake-cfgs", []) cins.append(conff) cins.append(cfgc) cins.extend(automake.AdditionalConfigureDependencies(name)) cout = [makef] env.AutomakeConfigure(cout, cins) bins = settings.get("automake-srcs", []) bins.extend(cout) expected_outputs = settings.get("automake-outputs", []) expected_outputs = map( lambda x: (x if os.path.isabs(x) else (excons.OutputBaseDirectory() + "/" + x)), expected_outputs) actual_outputs = automake.Outputs(name) bout = list(set(actual_outputs).union( set(expected_outputs))) + [automake.OutputsCachePath(name)] out = env.Automake(bout, bins) automake.CleanOne(name) return out
def SetupEnvironment(env, settings): name = settings["name"] debug = (excons.GetArgument("debug", 0, int) != 0) opts = settings.get("cmake-opts", {}) flags = settings.get("cmake-flags", "") blddir = cmake.BuildDir(name) cmakec = blddir + "/CMakeCache.txt" cfgc = cmake.ConfigCachePath(name) cexts = [".c", ".h", ".cc", ".hh", ".cpp", ".hpp", ".cxx", ".hxx"] # Override default C/C++ file scanner to avoid SCons being too nosy env.Prepend( SCANNERS=SCons.Script.Scanner(function=DummyScanner, skeys=cexts)) env["CMAKE_PROJECT"] = name env["CMAKE_TOPDIR"] = excons.abspath(settings.get("cmake-root", ".")) env["CMAKE_OPTIONS"] = opts env["CMAKE_FLAGS"] = flags env["CMAKE_MIN_MSCVER"] = settings.get("cmake-min-mscver", None) env["CMAKE_CONFIG"] = settings.get("cmake-config", ("debug" if debug else "release")) env["CMAKE_TARGET"] = settings.get("cmake-target", "install") env["CMAKE_CACHE"] = cmakec env["CMAKE_CONFIG_CACHE"] = cfgc env["BUILDERS"]["CMakeConfigure"] = SCons.Script.Builder( action=SCons.Script.Action(ConfigureAction, "Configure using CMake ...")) env["BUILDERS"]["CMake"] = SCons.Script.Builder( action=SCons.Script.Action(BuildAction, "Build using CMake ...")) # Check if we need to reconfigure if not SCons.Script.GetOption("clean"): if not os.path.isdir(blddir): try: os.makedirs(blddir) except: return None doconf = True if os.path.isfile(cfgc): doconf = False with open(cfgc, "r") as f: try: d = eval(f.read()) for k, v in d.iteritems(): if not k in opts or opts[k] != v: doconf = True break if not doconf: for k, v in opts.iteritems(): if not k in d: doconf = True break except: doconf = True if doconf or int(SCons.Script.ARGUMENTS.get("reconfigure", "0")) != 0: # Only rewrite cfgc when strictly needed if doconf: with open(cfgc, "w") as f: pprint.pprint(opts, stream=f) if os.path.isfile(cmakec): os.remove(cmakec) cins = settings.get("cmake-cfgs", []) cins.append(cfgc) cins.extend(cmake.AdditionalConfigureDependencies(name)) cout = [cmakec] env.CMakeConfigure(cout, cins) bins = settings.get("cmake-srcs", []) bins.extend(cout) expected_outputs = settings.get("cmake-outputs", []) expected_outputs = map( lambda x: (x if os.path.isabs(x) else (excons.OutputBaseDirectory() + "/" + x)), expected_outputs) actual_outputs = cmake.Outputs(name) bout = list(set(actual_outputs).union( set(expected_outputs))) + [cmake.OutputsCachePath(name)] out = env.CMake(bout, bins) # Run clean last cmake.CleanOne(name) return out
def Require(ilmthread=None, iexmath=None, python=None): if ilmthread is None: ilmthread = (excons.GetArgument("ilmbase-thread", 1, int) != 0) if iexmath is None: iexmath = (excons.GetArgument("ilmbase-iexmath", 1, int) != 0) if python is None: python = (excons.GetArgument("ilmbase-python", 0, int) != 0) def _RealRequire(env): ilmbase_libsuffix = excons.GetArgument("ilmbase-libsuffix", "") # Add python bindings first if python: pyilmbase_inc, pyilmbase_lib = excons.GetDirs("ilmbase-python") pyilmbase_libsuffix = excons.GetArgument("ilmbase-python-libsuffix", ilmbase_libsuffix) if pyilmbase_inc: if not pyilmbase_inc.endswith("OpenEXR"): pyilmbase_inc += "/OpenEXR" env.Append(CPPPATH=[pyilmbase_inc, os.path.dirname(pyilmbase_inc)]) if pyilmbase_lib: env.Append(LIBPATH=[pyilmbase_lib]) env.Append(LIBS=["PyImath" + pyilmbase_libsuffix]) ilmbase_inc, ilmbase_lib = excons.GetDirs("ilmbase") static = (excons.GetArgument("ilmbase-static", 0, int) != 0) if ilmbase_inc and not ilmbase_inc.endswith("OpenEXR"): ilmbase_inc += "/OpenEXR" libs = [] if ilmthread: libs.append("IlmThread") libs.append("Imath") if iexmath: libs.append("IexMath") libs.append("Iex") libs.append("Half") if ilmbase_libsuffix: libs = map(lambda x: x+ilmbase_libsuffix, libs) if sys.platform == "win32": if not static: env.Append(CPPDEFINES=["OPENEXR_DLL"]) if ilmbase_inc: env.Append(CPPPATH=[ilmbase_inc, os.path.dirname(ilmbase_inc)]) if ilmbase_lib: env.Append(LIBPATH=[ilmbase_lib]) env.Append(LIBS=libs) return _RealRequire
def Require(hl=False, verbose=False): global ThreadSafe_exp, Szlib_exp, Zlib_exp, hdf5_confs hdf5_inc, hdf5_lib = excons.GetDirs("hdf5") hdf5_static = (excons.GetArgument("hdf5-static", 0, int) != 0) hdf5_libname = excons.GetArgument("hdf5-name", None) if not hdf5_libname: hdf5_libprefix = excons.GetArgument("hdf5-prefix", "") hdf5_libsuffix = excons.GetArgument("hdf5-suffix", "") hdf5_basename = ("hdf5" if sys.platform != "win32" else "libhdf5") hdf5_libname = hdf5_basename + hdf5_libsuffix hdf5hl_libname = hdf5_libprefix + hdf5_basename + "_hl" + hdf5_libsuffix else: hdf5hl_libname = hdf5_libname + "_hl" def GetConf(env, incdir): h5conf = None cfg = {"threadsafe": False, "zlib": False, "szip": False} quiet = not verbose if incdir: # Note: On Fedora 14, H5pubconf.h has been renamed to H5pubconf-64.h # -> be slightly more flexible when looking up this file lst = filter(lambda x: os.path.basename(x).startswith("H5pubconf"), excons.glob(incdir + "/*.h")) if len(lst) > 0: h5conf = lst[0].replace("\\", "/") else: # Look in current include paths for d in env["CPPPATH"]: lst = filter( lambda x: os.path.basename(x).startswith("H5pubconf"), excons.glob(d + "/*.h")) if len(lst) > 0: h5conf = lst[0].replace("\\", "/") break if h5conf: if h5conf in hdf5_confs: quiet = True cfg = hdf5_confs[h5conf] else: if verbose: excons.PrintOnce("Reading configuration header '%s'..." % h5conf, tool="hdf5") f = open(h5conf, "r") for l in f.readlines(): l = l.strip() if ThreadSafe_exp.match(l): cfg["threadsafe"] = True elif Szip_exp.match(l): cfg["szip"] = True elif Zlib_exp.match(l): cfg["zlib"] = True hdf5_confs[h5conf] = cfg f.close() if not quiet: if cfg["threadsafe"]: excons.PrintOnce("Thread safe", tool="hdf5") if cfg["zlib"]: excons.PrintOnce("Using zlib", tool="hdf5") if cfg["szip"]: excons.PrintOnce("Using szip", tool="hdf5") else: excons.WarnOnce("Could not find configuration header", tool="hdf5") return (False, cfg) def _RealRequire(env): quiet, cfg = GetConf(env, hdf5_inc) if hdf5_inc: env.Append(CPPPATH=[hdf5_inc]) if hdf5_lib: env.Append(LIBPATH=[hdf5_lib]) if hl: excons.Link(env, hdf5hl_libname, static=hdf5_static, force=True, silent=True) excons.Link(env, hdf5_libname, static=hdf5_static, force=True, silent=True) if hdf5_static: if not quiet: excons.PrintOnce("Static build", tool="hdf5") if cfg["threadsafe"]: threads.Require(env) if cfg["zlib"]: if excons.GetArgument("zlib-static", None) is None: if not quiet: excons.PrintOnce("Force static zlib", tool="hdf5") excons.SetArgument("zlib-static", 1) zlib.Require(env) if cfg["szip"]: if excons.GetArgument("szip-static", None) is None: if not quiet: excons.PrintOnce("Force static szip", tool="hdf5") excons.SetArgument("szip-static", 1) szip.Require(env) excons.AddHelpOptions(hdf5=GetOptionsString()) return _RealRequire
def _RealRequire(env): linklibs = [] defs = [] boost_inc_dir, boost_lib_dir = excons.GetDirs("boost") static = (excons.GetArgument("boost-static", 0, int) != 0) boost_libsuffix = excons.GetArgument("boost-libsuffix", "") useautolink = False autolinkcount = 0 if sys.platform == "win32": useautolink = (excons.GetArgument("boost-autolink", 1, int) != 0) # All libs but Boost.Python are statically linked by default # => use BOOST_PYTHON_STATIC_LIB to enable static linking # Libraries are auto-linked on windows by default # => disable for all libraries using BOOST_ALL_NO_LIB # => disable for a specific lib using BOOST_[libraryname]_NO_LIB for lib in libs: incdir, libdir = excons.GetDirs("boost-%s" % lib) if incdir: env.Append(CPPPATH=[incdir]) if libdir: env.Append(LIBPATH=[libdir]) libname = excons.GetArgument("boost-%s-libname" % lib, None) if not libname: libsuffix = excons.GetArgument("boost-%s-libsuffix" % lib, boost_libsuffix) libname = "boost_%s%s" % (lib, libsuffix) libstatic = (excons.GetArgument("boost-%s-static" % lib, (1 if static else 0), int) != 0) autolinklib = False if sys.platform == "win32": autolinklib = (excons.GetArgument("boost-%s-autolink" % lib, (1 if useautolink else 0), int) != 0) if not autolinklib: defs.append("BOOST_%s_NO_LIB" % lib.upper()) else: autolinkcount += 1 if libstatic: if lib == "thread": # Not to confure with the 'LIB' meaning of BOOST_xxx_NO_LIB defs.append("BOOST_THREAD_USE_LIB") elif lib == "python": # Boost.Python is dynamically linked by 'default' defs.append("BOOST_PYTHON_STATIC_LIB") else: # Should not have to make a special case of Boost.Thread anymore, but # for backward compatibility sake if lib == "thread": defs.append("BOOST_THREAD_USE_DLL") elif lib != "python": defs.append("BOOST_%s_DYN_LINK" % lib.upper()) if not autolinklib: linklibs.append(libname) if sys.platform == "win32" and autolinkcount == 0: defs.append("BOOST_ALL_NO_LIB") env.Append(CPPDEFINES=defs) if boost_inc_dir: env.Append(CPPPATH=boost_inc_dir) if boost_lib_dir: env.Append(LIBPATH=boost_lib_dir) if linklibs: env.Append(LIBS=linklibs)