diff options
Diffstat (limited to 'BuildTools/SCons/SConstruct')
-rw-r--r-- | BuildTools/SCons/SConstruct | 331 |
1 files changed, 260 insertions, 71 deletions
diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index e91dd6e..d314ff3 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -34,5 +34,5 @@ def colorize(command, target, color) : return " " + prefix + command + suffix + " " + target -if int(ARGUMENTS.get("V", 0)) == 0: +if int(ARGUMENTS.get("V", 0)) == 0 and not ARGUMENTS.get("dump_trace", False) : env["CCCOMSTR"] = colorize("CC", "$TARGET", "green") env["SHCCCOMSTR"] = colorize("CC", "$TARGET", "green") @@ -43,4 +43,5 @@ if int(ARGUMENTS.get("V", 0)) == 0: env["ARCOMSTR"] = colorize("AR", "$TARGET", "red") env["RANLIBCOMSTR"] = colorize("RANLIB", "$TARGET", "red") + env["PCHCOMSTR"] = colorize("PCH", "$TARGET", "blue") env["QT4_RCCCOMSTR"] = colorize("RCC", "$TARGET", "blue") env["QT4_UICCOMSTR"] = colorize("UIC", "$TARGET", "blue") @@ -72,6 +73,4 @@ def checkObjCHeader(context, header) : ################################################################################ -env.Append(CPPPATH = [root]) - if ARGUMENTS.get("force-configure", 0) : SCons.SConf.SetCacheMode("force") @@ -85,4 +84,10 @@ def CheckPKG(context, name): def CheckVersion(context, library, version, define, header, value) : context.Message("Checking " + library + " version (>= " + version + ") ...") + version = GetVersion(context, define, header) + ok = version >= value + context.Result(ok) + return ok + +def GetVersion(context, define, header, extension = ".c") : ret = context.TryRun(""" #include <%(header)s> @@ -93,8 +98,10 @@ int main(int argc, char* argv[]) { return 0; } -""" % { "header" : header, "define": define }, ".c") - ok = ret[0] and int(ret[1]) >= value - context.Result(ok) - return ok +""" % { "header" : header, "define": define }, extension) + if ret[0] : + return int(ret[1]) + else : + return -1 + conf = Configure(conf_env) @@ -105,6 +112,25 @@ if not conf.CheckCXX() or not conf.CheckCC() : env["HAVE_ZLIB"] = True -if conf.CheckLib("z") : - env["ZLIB_FLAGS"] = {"LIBS": ["z"]} +zlib_flags = {} +zlib_okay = False +if env.get("zlib_libdir", None) : + zlib_flags["LIBPATH"] = [env["zlib_libdir"]] + zlib_okay = True +if env.get("zlib_includedir", None) : + zlib_flags["CPPPATH"] = [env["zlib_includedir"]] + zlib_okay = True +if env.get("zlib_libfile", None) : + zlib_flags["LIBS"] = [File(env["zlib_libfile"])] + zlib_okay = True +elif zlib_okay : + zlib_flags["LIBS"] = ["z"] +if (not zlib_okay) and conf.CheckLib("z") : + zlib_flags["LIBS"] = ["z"] + zlib_okay = True +if zlib_okay : + env["ZLIB_FLAGS"] = zlib_flags +elif not env.get("zlib_bundled_enable", True) : + print "Error: Zlib not found and zlib_bundled_enable is false" + Exit(1) else : env["ZLIB_BUNDLED"] = True @@ -126,7 +152,8 @@ if conf.CheckLib("c") : env["PLATFORM_FLAGS"]["LIBS"] = env["PLATFORM_FLAGS"].get("LIBS", []) + ["c"] -if conf.CheckLib("stdc++") : +# Even if you find stdc++ on HP-UX, it is the wrong one for aCC +if env["PLATFORM"] != "hpux" : + if conf.CheckLib("stdc++", language='CXX') : env["PLATFORM_FLAGS"]["LIBS"] = env["PLATFORM_FLAGS"].get("LIBS", []) + ["stdc++"] - conf.Finish() @@ -134,9 +161,8 @@ conf.Finish() boost_conf_env = conf_env.Clone() boost_flags = {} -boost_flags["CPPDEFINES"] = [("BOOST_FILESYSTEM_VERSION", "2")] if env.get("boost_libdir", None) : boost_flags["LIBPATH"] = [env["boost_libdir"]] if env.get("boost_includedir", None) : - if env["PLATFORM"] == "win32" : + if env["PLATFORM"] == "win32" or env["PLATFORM"] == "hpux" or env["PLATFORM"] == "sunos" : boost_flags["CPPPATH"] = [env["boost_includedir"]] else : @@ -146,5 +172,5 @@ if env.get("boost_includedir", None) : boost_conf_env.MergeFlags(boost_flags) conf = Configure(boost_conf_env) -boostLibs = [("signals", None), ("thread", None), ("regex", None), ("program_options", None), ("filesystem", None), ("system", "system/system_error.hpp"), ("date_time", "date_time/date.hpp")] +boostLibs = [("signals", None), ("system", "system/system_error.hpp"), ("thread", None), ("regex", None), ("program_options", None), ("filesystem", None), ("serialization", "archive/text_oarchive.hpp"), ("date_time", "date_time/date.hpp")] allLibsPresent = True libNames = [] @@ -159,7 +185,7 @@ for (lib, header) in boostLibs : if env["PLATFORM"] != "win32" : libName = "boost_" + lib - if not conf.CheckLib(libName) : + if not conf.CheckLib(libName, language='CXX') : libName += "-mt" - if not conf.CheckLib(libName) : + if not conf.CheckLib(libName, language='CXX') : allLibsPresent = False break @@ -172,4 +198,8 @@ if allLibsPresent : # FIXME: Remove this workaround when UUID is available in most distros env["BOOST_BUNDLED_UUID_ONLY"] = True + env["BOOST_FLAGS"]["CPPDEFINES"] = ["BOOST_SIGNALS_NO_DEPRECATION_WARNING"] +elif not env.get("boost_bundled_enable", True) : + print "Error: Boost not found and boost_bundled_enable is false" + Exit(1) else : env["BOOST_BUNDLED"] = True @@ -194,5 +224,5 @@ if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : # GConf env["HAVE_GCONF"] = 0 -if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : +if env.get("try_gconf", True) and env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : gconf_env = conf_env.Clone() conf = Configure(gconf_env, custom_tests = {"CheckPKG": CheckPKG}) @@ -255,5 +285,5 @@ if env["PLATFORM"] == "win32" : # LibXML conf = Configure(conf_env, custom_tests = {"CheckVersion": CheckVersion}) -if conf.CheckCHeader("libxml/parser.h") and conf.CheckLib("xml2") : +if env.get("try_libxml", True) and conf.CheckCHeader("libxml/parser.h") and conf.CheckLib("xml2") : #and conf.CheckVersion("LibXML", "2.6.23", "LIBXML_VERSION", "libxml/xmlversion.h", 20623) : env["HAVE_LIBXML"] = 1 @@ -261,5 +291,5 @@ if conf.CheckCHeader("libxml/parser.h") and conf.CheckLib("xml2") : conf.Finish() -if not env.get("HAVE_LIBXML", 0) : +if env.get("try_libxml", True) and not env.get("HAVE_LIBXML", 0) : libxml_env = conf_env.Clone() libxml_env.Append(CPPPATH = ["/usr/include/libxml2"]) @@ -272,5 +302,5 @@ if not env.get("HAVE_LIBXML", 0) : # Expat -if not env.get("HAVE_LIBXML",0) : +if env.get("try_expat", True) and not env.get("HAVE_LIBXML",0) : expat_conf_env = conf_env.Clone() expat_flags = {} @@ -295,4 +325,29 @@ if not env.get("HAVE_EXPAT", 0) and not env.get("HAVE_LIBXML", 0) : env["EXPAT_BUNDLED"] = True +################################################################################ +# IDN library +################################################################################ + +env["NEED_IDN"] = env.get("need_idn", True) + +# ICU +icu_env = conf_env.Clone() +use_icu = bool(env["icu"]) +icu_prefix = "" +if isinstance(env["icu"], str) : + icu_prefix = env["icu"] +icu_flags = {} +if icu_prefix : + icu_flags = { "CPPPATH": [os.path.join(icu_prefix, "include")] } + icu_flags["LIBPATH"] = [os.path.join(icu_prefix, "lib")] + icu_env.MergeFlags(icu_flags) + +icu_conf = Configure(icu_env) +if use_icu and icu_conf.CheckCHeader("unicode/usprep.h") : + env["HAVE_ICU"] = 1 + env["ICU_FLAGS"] = icu_flags + env["ICU_FLAGS"]["LIBS"] = ["icuuc"] +icu_conf.Finish() + # LibIDN libidn_conf_env = conf_env.Clone() @@ -304,61 +359,127 @@ if env.get("libidn_includedir", None) : libidn_conf_env.MergeFlags(libidn_flags) conf = Configure(libidn_conf_env) -if conf.CheckCHeader("idna.h") and conf.CheckLib(env["libidn_libname"]) : +if env.get("try_libidn", True) and not env.get("HAVE_ICU") and conf.CheckCHeader("idna.h") and conf.CheckLib(env["libidn_libname"]) : env["HAVE_LIBIDN"] = 1 env["LIBIDN_FLAGS"] = { "LIBS": [env["libidn_libname"]] } env["LIBIDN_FLAGS"].update(libidn_flags) -else : - env["LIBIDN_BUNDLED"] = 1 conf.Finish() +# Fallback to bundled LibIDN +if not env.get("HAVE_ICU", False) and not env.get("HAVE_LIBIDN", False) : + if env.get("libidn_bundled_enable", True) : + env["HAVE_LIBIDN"] = 1 + env["LIBIDN_BUNDLED"] = 1 + elif env.get("need_idn", True): + print "Error: ICU and LIBIDN not found, and libidn_bundled_enable is false" + Exit(1) + else: + print "Proceeding without an IDN library because need_idn was false. This will break all internal binaries" + +# Unbound +if env["unbound"] : + env["LDNS_BUNDLED"] = 1 + env["UNBOUND_BUNDLED"] = 1 +else : + env["LDNS_FLAGS"] = {} + env["UNBOUND_FLAGS"] = {} + # LibMiniUPnPc -if env["experimental"] : - #libminiupnpc_conf_env = conf_env.Clone() - #conf = Configure(libminiupnpc_conf_env) - #if conf.CheckCHeader("miniupnpc.h") and conf.CheckLib(env["libminiupnpc_libname"]) : - # print "NOT IMPLEMENTED YET" - #else : +if env["experimental_ft"] : + libminiupnpc_flags = {"CPPPATH": ["/usr/include/miniupnpc/"]} + libminiupnpc_conf_env = conf_env.Clone() + if env.get("libminiupnpc_libdir", None) : + libminiupnpc_flags["LIBPATH"] = [env["libminiupnpc_libdir"]] + if env.get("libminiupnpc_includedir", None) : + libminiupnpc_flags["CPPPATH"] = [env["libminiupnpc_includedir"]] + libminiupnpc_conf_env.MergeFlags(libminiupnpc_flags) + conf = Configure(libminiupnpc_conf_env) + if conf.CheckCHeader("miniupnpc.h") and conf.CheckLib(env["libminiupnpc_libname"]) and False : + # ^ False because APIs aren't stable + env["HAVE_LIBMINIUPNPC"] = 1 + env["LIBMINIUPNPC_FLAGS"] = { "LIBS": ["miniupnpc"] } + env["LIBMINIUPNPC_FLAGS"].update(libminiupnpc_flags) + else : env["LIBMINIUPNPC_BUNDLED"] = 1 - #conf.Finish() + conf.Finish() else : env["LIBMINIUPNPC_FLAGS"] = {} # LibNATPMP -if env["experimental"] : - #libnatpmp_conf_env = conf_env.Clone() - #conf = Configure(libnatpmp_conf_env) - #if conf.CheckCHeader("natpmp.h") and conf.CheckLib(env["libnatpmp_libname"]) : - # print "NOT IMPLEMENTED YET" - #else : +if env["experimental_ft"] : + libnatpmp_flags = {} + libnatpmp_conf_env = conf_env.Clone() + if env.get("libnatpmp_libdir", None) : + libnatpmp_flags["LIBPATH"] = [env["libnatpmp_libdir"]] + if env.get("libnatpmp_includedir", None) : + libnatpmp_flags["CPPPATH"] = [env["libnatpmp_includedir"]] + libnatpmp_conf_env.MergeFlags(libnatpmp_flags) + conf = Configure(libnatpmp_conf_env) + if conf.CheckCHeader("natpmp.h") and conf.CheckLib(env["libnatpmp_libname"]) and False: + # ^ False because APIs aren't stable + env["HAVE_LIBNATPMP"] = 1 + env["LIBNATPMP_FLAGS"] = { "LIBS": ["natpmp"] } + env["LIBNATPMP_FLAGS"].update(libnatpmp_flags) + else : env["LIBNATPMP_BUNDLED"] = 1 - #conf.Finish() + conf.Finish() else : env["LIBNATPMP_FLAGS"] = {} # SQLite -#sqlite_conf_env = conf_env.Clone() -#sqlite_flags = {} -#if env.get("sqlite_libdir", None) : -# sqlite_flags["LIBPATH"] = [env["sqlite_libdir"]] -#if env.get("sqlite_includedir", None) : -# sqlite_flags["CPPPATH"] = [env["sqlite_includedir"]] -#sqlite_conf_env.MergeFlags(sqlite_flags) -#conf = Configure(sqlite_conf_env) -#if conf.CheckCHeader("sqlite3.h") and conf.CheckLib(env["sqlite_libname"]) : -# env["HAVE_SQLITE"] = 1 -# env["SQLITE_FLAGS"] = { "LIBS": [env["sqlite_libname"]] } -# env["SQLITE_FLAGS"].update(sqlite_flags) -#else : -# env["SQLITE_BUNDLED"] = 1 -#conf.Finish() +if env["experimental"] : + sqlite_conf_env = conf_env.Clone() + sqlite_flags = {} + if env.get("sqlite_libdir", None) : + sqlite_flags["LIBPATH"] = [env["sqlite_libdir"]] + if env.get("sqlite_includedir", None) : + sqlite_flags["CPPPATH"] = [env["sqlite_includedir"]] + sqlite_conf_env.MergeFlags(sqlite_flags) + conf = Configure(sqlite_conf_env) + if conf.CheckCHeader("sqlite3.h") and conf.CheckLib(env["sqlite_libname"]) and not env.get("sqlite_force_bundled", False): + env["HAVE_SQLITE"] = 1 + env["SQLITE_FLAGS"] = { "LIBS": [env["sqlite_libname"]] } + env["SQLITE_FLAGS"].update(sqlite_flags) + else : + env["SQLITE_BUNDLED"] = 1 + conf.Finish() +else : + env["SQLITE_FLAGS"] = {} + # Lua +lua_conf_env = conf_env.Clone() +lua_flags = {} +if env.get("lua_libdir", None) : + lua_flags["LIBPATH"] = [env["lua_libdir"]] +if env.get("lua_includedir", None) : + lua_flags["CPPPATH"] = [env["lua_includedir"]] +lua_conf_env.MergeFlags(lua_flags) +conf = Configure(lua_conf_env) +if not env.get("lua_force_bundled", False) and conf.CheckLibWithHeader(env["lua_libname"], "lua.hpp", "cxx", autoadd = 0) : + env["HAVE_LUA"] = 1 + env["LUA_FLAGS"] = { "LIBS": [env["lua_libname"]] } + lua_version = GetVersion(conf, "LUA_VERSION_NUM", "lua.h") + if lua_version > 0 : + env["LUA_FLAGS"]["LUA_VERSION"] = str(lua_version // 100) + "." + str(lua_version % 100) + else : + print "Warning: Unable to determine Lua version. Not installing Lua libraries." + env["LUA_FLAGS"].update(lua_flags) +else : env["LUA_BUNDLED"] = 1 +conf.Finish() # Readline -conf = Configure(conf_env) -if conf.CheckCHeader(["stdio.h", "readline/readline.h"]) and conf.CheckLib("readline") : - env["HAVE_READLINE"] = True - env["READLINE_FLAGS"] = { "LIBS": ["readline"] } +editline_conf_env = conf_env.Clone() +editline_flags = {} +if env.get("editline_libdir", None) : + editline_flags["LIBPATH"] = [env["editline_libdir"]] +if env.get("editline_includedir", None) : + editline_flags["CPPPATH"] = [env["editline_includedir"]] +editline_conf_env.MergeFlags(editline_flags) +conf = Configure(editline_conf_env) +if conf.CheckLibWithHeader(env["editline_libname"], ["stdio.h", "editline/readline.h"], "c") : + env["HAVE_EDITLINE"] = 1 + env["EDITLINE_FLAGS"] = { "LIBS": [env["editline_libname"]] } + env["EDITLINE_FLAGS"].update(editline_flags) conf.Finish() @@ -372,5 +493,5 @@ if env.get("avahi_includedir", None) : avahi_conf_env.MergeFlags(avahi_flags) conf = Configure(avahi_conf_env) -if conf.CheckCHeader("avahi-client/client.h") and conf.CheckLib("avahi-client") and conf.CheckLib("avahi-common") : +if env.get("try_avahi", True) and conf.CheckCHeader("avahi-client/client.h") and conf.CheckLib("avahi-client") and conf.CheckLib("avahi-common") : env["HAVE_AVAHI"] = True env["AVAHI_FLAGS"] = { "LIBS": ["avahi-client", "avahi-common"] } @@ -384,10 +505,24 @@ if env["qt"] : # OpenSSL openssl_env = conf_env.Clone() +if env.get("openssl_force_bundled", False) or env["target"] in ("iphone-device", "iphone-simulator", "xcode", "android") : + env["OPENSSL_BUNDLED"] = True + env["HAVE_OPENSSL"] = True +else : use_openssl = bool(env["openssl"]) -openssl_prefix = env["openssl"] if isinstance(env["openssl"], str) else "" + openssl_prefix = "" + if isinstance(env["openssl"], str) : + openssl_prefix = env["openssl"] openssl_flags = {} if openssl_prefix : + openssl_include = env.get("openssl_include", None) + openssl_libdir = env.get("openssl_libdir", None) + if openssl_include: + openssl_flags = {"CPPPATH":[openssl_include]} + else: openssl_flags = { "CPPPATH": [os.path.join(openssl_prefix, "include")] } - if env["PLATFORM"] == "win32" : + if openssl_libdir: + openssl_flags["LIBPATH"] = [openssl_libdir] + env["OPENSSL_DIR"] = openssl_prefix + elif env["PLATFORM"] == "win32" : openssl_flags["LIBPATH"] = [os.path.join(openssl_prefix, "lib", "VC")] env["OPENSSL_DIR"] = openssl_prefix @@ -400,5 +535,8 @@ if use_openssl and openssl_conf.CheckCHeader("openssl/ssl.h") : env["HAVE_OPENSSL"] = 1 env["OPENSSL_FLAGS"] = openssl_flags - if env["PLATFORM"] == "win32" : + openssl_libnames = env.get("openssl_libnames", None) + if openssl_libnames: + env["OPENSSL_FLAGS"]["LIBS"] = openssl_libnames.split(',') + elif env["PLATFORM"] == "win32" : env["OPENSSL_FLAGS"]["LIBS"] = ["libeay32MD", "ssleay32MD"] else: @@ -407,9 +545,6 @@ if use_openssl and openssl_conf.CheckCHeader("openssl/ssl.h") : if platform.mac_ver()[0].startswith("10.5") : env["OPENSSL_FLAGS"]["FRAMEWORKS"] = ["Security"] -elif env["target"] in ("iphone-device", "iphone-simulator", "xcode") : - env["OPENSSL_BUNDLED"] = True - env["HAVE_OPENSSL"] = True else : - env["OPENSSL_FLAGS"] = "" + env["OPENSSL_FLAGS"] = {} if env["PLATFORM"] == "win32" : env["HAVE_SCHANNEL"] = True @@ -419,6 +554,22 @@ else : openssl_conf.Finish() +#Hunspell +hunspell_env = conf_env.Clone() +hunspell_prefix = isinstance(env.get("hunspell", False), str) and env["hunspell"] or "" +hunspell_flags = {} +if hunspell_prefix : + hunspell_flags = {"CPPPATH":[os.path.join(hunspell_prefix, "include")], "LIBPATH":[os.path.join(hunspell_prefix, "lib")]} +hunspell_env.MergeFlags(hunspell_flags) + +env["HAVE_HUNSPELL"] = 0; +hunspell_conf = Configure(hunspell_env) +if hunspell_conf.CheckCXXHeader("hunspell/hunspell.hxx") and hunspell_conf.CheckLib("hunspell") : + env["HAVE_HUNSPELL"] = 1 + hunspell_flags["LIBS"] = ["hunspell"] + env["HUNSPELL_FLAGS"] = hunspell_flags +hunspell_conf.Finish() + # Bonjour -if env["PLATFORM"] == "darwin" : +if env["PLATFORM"] == "darwin" and env["target"] == "native" : env["HAVE_BONJOUR"] = 1 elif env.get("bonjour", False) : @@ -466,7 +617,35 @@ if env.get("docbook_xsl") : ################################################################################ +try: if env.Dir("#/.git").exists() : - if not env.GetOption("clean") : + if not env.GetOption("clean") and env.get("install_git_hooks", True) : env.Install("#/.git/hooks", Glob("#/BuildTools/Git/Hooks/*")) +except TypeError: + print "You seem to be using Swift in a Git submodule. Not installing hooks." + + +################################################################################ +# Replace #pragma once with proper guards on platforms that require it +################################################################################ + +if ARGUMENTS.get("replace_pragma_once", False) : + env.Tool("ReplacePragmaOnce", toolpath = ["#/BuildTools/SCons/Tools"]) + + def relpath(path, start) : + i = len(os.path.commonprefix([path, start])) + return path[i+1:] + + for actual_root, dirs, files in os.walk(root) : + if "3rdParty" in actual_root : + continue + for file in files : + if not file.endswith(".h") : + continue + include = relpath(os.path.join(actual_root, file), root) + env.ReplacePragmaOnce("#/include/" + include, "#/" + include) + env.Append(CPPPATH = ["#/include"]) +else : + env.Append(CPPPATH = [root]) + ################################################################################ @@ -474,9 +653,14 @@ if env.Dir("#/.git").exists() : ################################################################################ -# Build tools -env.SConscript(dirs = ["#/BuildTools/CLang"]) +if ARGUMENTS.get("dump_trace", False) : + env.SetOption("no_exec", True) + env["TEST"] = True + env["BOOST_BUILD_BCP"] = True + env.Decider(lambda x, y, z : True) + SCons.Node.Python.Value.changed_since_last_build = (lambda x, y, z: True) # Modules modules = [] +if os.path.isdir(Dir("#/3rdParty").abspath) : for dir in os.listdir(Dir("#/3rdParty").abspath) : full_dir = os.path.join(Dir("#/3rdParty").abspath, dir) @@ -494,7 +678,11 @@ for dir in os.listdir(Dir("#").abspath) : modules.append(dir) +# QA comes last +modules.remove("QA") +modules.append("QA") + # Flags env["PROJECTS"] = [m for m in modules if m not in ["Documentation", "QA", "SwifTools"] and not m.startswith("3rdParty")] -for stage in ["flags", "build", "test"] : +for stage in ["flags", "build"] : env["SCONS_STAGE"] = stage SConscript(dirs = map(lambda x : root + "/" + x, modules)) @@ -505,4 +693,5 @@ if ARGUMENTS.get("sloccount", False) : env.SLOCCount("#/" + project) + ################################################################################ # Print summary @@ -524,5 +713,5 @@ print "" print " XML Parsers: " + ' '.join(parsers) -print " TLS Support: " + ("OpenSSL" if env.get("HAVE_OPENSSL",0) else ("Schannel" if env.get("HAVE_SCHANNEL", 0) else "Disabled")) -print " DNSSD Support: " + ("Bonjour" if env.get("HAVE_BONJOUR") else ("Avahi" if env.get("HAVE_AVAHI") else "Disabled")) +print " TLS Support: " + (env.get("HAVE_OPENSSL",0) and "OpenSSL" or env.get("HAVE_SCHANNEL", 0) and "Schannel" or "Disabled") +print " DNSSD Support: " + (env.get("HAVE_BONJOUR") and "Bonjour" or (env.get("HAVE_AVAHI") and "Avahi" or "Disabled")) print |