diff options
Diffstat (limited to 'BuildTools/SCons')
-rw-r--r-- | BuildTools/SCons/SConscript.boot | 295 | ||||
-rw-r--r-- | BuildTools/SCons/SConstruct | 339 | ||||
-rw-r--r-- | BuildTools/SCons/Tools/AppBundle.py | 14 |
3 files changed, 391 insertions, 257 deletions
diff --git a/BuildTools/SCons/SConscript.boot b/BuildTools/SCons/SConscript.boot new file mode 100644 index 0000000..e969def --- /dev/null +++ b/BuildTools/SCons/SConscript.boot @@ -0,0 +1,295 @@ +import sys, os, re, platform, hashlib +sys.path.append(Dir("#/BuildTools/SCons").abspath) + +################################################################################ +# Build variables +################################################################################ + +vars = Variables(os.path.join(Dir("#").abspath, "config.py")) +vars.Add('cc', "C compiler") +vars.Add('cxx', "C++ compiler") +vars.Add('ccflags', "Extra C(++) compiler flags") +vars.Add('link', "Linker") +vars.Add('linkflags', "Extra linker flags") +vars.Add(BoolVariable("ccache", "Use CCache", "no")) +vars.Add(BoolVariable("distcc", "Use DistCC", "no")) +vars.Add('distcc_hosts', "DistCC hosts (overrides DISTCC_HOSTS)") +vars.Add(EnumVariable("test", "Compile and run tests", "none", ["none", "all", "unit", "system"])) +vars.Add(BoolVariable("optimize", "Compile with optimizations turned on", "no")) +vars.Add(BoolVariable("debug", "Compile with debug information", "yes")) +vars.Add(BoolVariable("allow_warnings", "Allow compilation warnings during compilation", "yes")) +vars.Add(BoolVariable("assertions", "Compile with assertions", "yes")) +vars.Add(BoolVariable("max_jobs", "Build with maximum number of parallel jobs", "no")) +vars.Add(EnumVariable("target", "Choose a target platform for compilation", "native", ["native", "iphone-simulator", "iphone-device", "xcode"])) +vars.Add(BoolVariable("swift_mobile", "Build mobile Swift", "no")) +if os.name != "nt" : + vars.Add(BoolVariable("coverage", "Compile with coverage information", "no")) +if os.name == "posix" : + vars.Add(BoolVariable("valgrind", "Run tests with valgrind", "no")) +if os.name == "mac" or (os.name == "posix" and os.uname()[0] == "Darwin"): + vars.Add(BoolVariable("universal", "Create universal binaries", "no")) + vars.Add(BoolVariable("mac105", "Link against the 10.5 frameworks", "no")) +if os.name == "nt" : + vars.Add(PathVariable("vcredist", "MSVC redistributable dir", "", PathVariable.PathAccept)) +if os.name == "nt" : + vars.Add(PackageVariable("bonjour", "Bonjour SDK location", "yes")) +vars.Add(PackageVariable("openssl", "OpenSSL location", "yes")) +vars.Add(PathVariable("boost_includedir", "Boost headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("boost_libdir", "Boost library location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("expat_includedir", "Expat headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("expat_libdir", "Expat library location", None, PathVariable.PathAccept)) +vars.Add("expat_libname", "Expat library name", "libexpat" if os.name == "nt" else "expat") +vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept)) +vars.Add("libidn_libname", "LibIDN library name", "libidn" if os.name == "nt" else "idn") +vars.Add(PathVariable("sqlite_includedir", "SQLite headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("sqlite_libdir", "SQLite library location", None, PathVariable.PathAccept)) +vars.Add("sqlite_libname", "SQLite library name", "libsqlite3" if os.name == "nt" else "sqlite3") +vars.Add(PathVariable("avahi_includedir", "Avahi headers location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("avahi_libdir", "Avahi library location", None, PathVariable.PathAccept)) +vars.Add(PathVariable("qt", "Qt location", "", PathVariable.PathAccept)) +vars.Add(PathVariable("docbook_xml", "DocBook XML", None, PathVariable.PathAccept)) +vars.Add(PathVariable("docbook_xsl", "DocBook XSL", None, PathVariable.PathAccept)) +vars.Add(BoolVariable("build_examples", "Build example programs", "yes")) +vars.Add(BoolVariable("enable_variants", "Build in a separate dir under build/, depending on compile flags", "no")) + +################################################################################ +# Set up default build & configure environment +################################################################################ + +env = Environment(CPPPATH = ["#"], ENV = { + 'PATH' : os.environ['PATH'], + 'LD_LIBRARY_PATH' : os.environ.get("LD_LIBRARY_PATH", ""), + }, variables = vars) + +Help(vars.GenerateHelpText(env)) + +# Default environment variables +env["PLATFORM_FLAGS"] = {} + +# Default custom tools +env.Tool("Test", toolpath = ["#/BuildTools/SCons/Tools"]) +env.Tool("WriteVal", toolpath = ["#/BuildTools/SCons/Tools"]) +env.Tool("BuildVersion", toolpath = ["#/BuildTools/SCons/Tools"]) +env.Tool("Flags", toolpath = ["#/BuildTools/SCons/Tools"]) +if env["PLATFORM"] == "darwin" : + env.Tool("Nib", toolpath = ["#/BuildTools/SCons/Tools"]) + env.Tool("AppBundle", toolpath = ["#/BuildTools/SCons/Tools"]) +if env["PLATFORM"] == "win32" : + env.Tool("WindowsBundle", toolpath = ["#/BuildTools/SCons/Tools"]) + #So we don't need to escalate with UAC + if "TMP" in os.environ.keys() : + env['ENV']['TMP'] = os.environ['TMP'] +env.Tool("SLOCCount", toolpath = ["#/BuildTools/SCons/Tools"]) + +# Max out the number of jobs +if env["max_jobs"] : + try : + import multiprocessing + SetOption("num_jobs", multiprocessing.cpu_count()) + except NotImplementedError : + pass + except ImportError : + pass + +# Default compiler flags +if env.get("distcc", False) : + env["ENV"]["HOME"] = os.environ["HOME"] + env["ENV"]["DISTCC_HOSTS"] = os.environ.get("DISTCC_HOSTS", "") + if "distcc_hosts" in env : + env["ENV"]["DISTCC_HOSTS"] = env["distcc_hosts"] + env["CC"] = "distcc gcc" + env["CXX"] = "distcc g++" +if "cc" in env : + env["CC"] = env["cc"] +if "cxx" in env : + env["CXX"] = env["cxx"] +ccflags = env.get("ccflags", []) +if isinstance(ccflags, str) : + # FIXME: Make the splitting more robust + env["CCFLAGS"] = ccflags.split(" ") +else : + env["CCFLAGS"] = ccflags +if "link" in env : + env["SHLINK"] = env["link"] + env["LINK"] = env["link"] +env["LINKFLAGS"] = env.get("linkflags", []) +# This isn't a real flag (yet) AFAIK. Be sure to append it to the CXXFLAGS +# where you need it +env["OBJCCFLAGS"] = [] +if env["optimize"] : + if env["PLATFORM"] == "win32" : + env.Append(CCFLAGS = ["/O2", "/GL"]) + env.Append(LINKFLAGS = ["/INCREMENTAL:NO", "/LTCG"]) + else : + env.Append(CCFLAGS = ["-O2"]) + +if env["target"] == "xcode" and os.environ["CONFIGURATION"] == "Release" : + env.Append(CCFLAGS = ["-Os"]) + +if env["debug"] : + if env["PLATFORM"] == "win32" : + env.Append(CCFLAGS = ["/Zi", "/MDd"]) + env.Append(LINKFLAGS = ["/DEBUG"]) + else : + env.Append(CCFLAGS = ["-g"]) +elif env["PLATFORM"] == "win32" : + env.Append(CCFLAGS = ["/MD"]) + +if env.get("universal", 0) : + assert(env["PLATFORM"] == "darwin") + env.Append(CCFLAGS = [ + "-isysroot", "/Developer/SDKs/MacOSX10.4u.sdk", + "-arch", "i386", + "-arch", "ppc"]) + env.Append(LINKFLAGS = [ + "-mmacosx-version-min=10.4", + "-isysroot", "/Developer/SDKs/MacOSX10.4u.sdk", + "-arch", "i386", + "-arch", "ppc"]) + +if env.get("mac105", 0) : + assert(env["PLATFORM"] == "darwin") + env.Append(CCFLAGS = [ + "-isysroot", "/Developer/SDKs/MacOSX10.5.sdk", + "-arch", "i386"]) + env.Append(LINKFLAGS = [ + "-mmacosx-version-min=10.5", + "-isysroot", "/Developer/SDKs/MacOSX10.5.sdk", + "-arch", "i386"]) + env.Append(FRAMEWORKS = ["Security"]) + +if not env["assertions"] : + env.Append(CPPDEFINES = ["NDEBUG"]) + +# If we build shared libs on AMD64, we need -fPIC. +# This should have no performance impact om AMD64 +if env["PLATFORM"] == "posix" and platform.machine() == "x86_64" : + env.Append(CCFLAGS = ["-fPIC"]) + +# Warnings +if env["PLATFORM"] == "win32" : + # TODO: Find the ideal set of warnings + #env.Append(CCFLAGS = ["/Wall"]) + pass +else : + env.Append(CXXFLAGS = ["-Wextra", "-Wall", "-Wnon-virtual-dtor", "-Wundef", "-Wold-style-cast", "-Wno-long-long", "-Woverloaded-virtual", "-Wfloat-equal", "-Wredundant-decls"]) + if not env.get("allow_warnings", False) : + env.Append(CXXFLAGS = ["-Werror"]) + gccVersion = env["CCVERSION"].split(".") + if gccVersion >= ["4", "5", "0"] : + env.Append(CXXFLAGS = ["-Wlogical-op"]) + if "clang" in env["CC"] : + env.Append(CXXFLAGS = ["-W#warnings", "-W-Wc++0x-compat", "-Wc++0x-compat", "-Waddress-of-temporary", "-Wambiguous-member-template", "-Warray-bounds", "-Watomic-properties", "-Wbind-to-temporary-copy", "-Wbuiltin-macro-redefined", "-Wc++-compat", "-Wc++0x-extensions", "-Wcomments", "-Wconditional-uninitialized", "-Wconstant-logical-operand", "-Wdeclaration-after-statement", "-Wdeprecated", "-Wdeprecated-implementations", "-Wdeprecated-writable-strings", "-Wduplicate-method-arg", "-Wempty-body", "-Wendif-labels", "-Wenum-compare", "-Wformat=2", "-Wfour-char-constants", "-Wgnu", "-Wincomplete-implementation", "-Winvalid-noreturn", "-Winvalid-offsetof", "-Winvalid-token-paste", "-Wlocal-type-template-args", "-Wmethod-signatures", "-Wmicrosoft", "-Wmissing-declarations", "-Wnon-pod-varargs", "-Wnonfragile-abi2", "-Wnull-dereference", "-Wout-of-line-declaration", "-Woverlength-strings", "-Wpacked", "-Wpointer-arith", "-Wpointer-sign", "-Wprotocol", "-Wreadonly-setter-attrs", "-Wselector", "-Wshift-overflow", "-Wshift-sign-overflow", "-Wstrict-selector-match", "-Wsuper-class-method-mismatch", "-Wtautological-compare", "-Wtypedef-redefinition", "-Wundeclared-selector", "-Wunknown-attributes", "-Wunknown-warning-option", "-Wunnamed-type-template-args", "-Wunused-exception-parameter", "-Wunused-member-function", "-Wused-but-marked-unused", "-Wvariadic-macros"]) +# To enable: +# "-Wheader-hygiene" +# "-Wnon-gcc", +# "-Wweak-vtables", +# "-Wlarge-by-value-copy", + +if env.get("coverage", 0) : + assert(env["PLATFORM"] != "win32") + env.Append(CCFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) + env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) + +if env["PLATFORM"] == "win32" : + env.Append(LIBS = ["user32", "crypt32", "dnsapi", "ws2_32", "wsock32", "Advapi32"]) + env.Append(CCFLAGS = ["/EHsc", "/nologo"]) + # FIXME: We should find a decent solution for MSVS 10 + if int(env["MSVS_VERSION"].split(".")[0]) < 10 : + env["LINKCOM"] = [env["LINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1'] + env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] + +if env["PLATFORM"] == "darwin" and not env["target"] in ["iphone-device", "iphone-simulator", "xcode"] : + env.Append(FRAMEWORKS = ["IOKit", "AppKit", "SystemConfiguration"]) + +# Testing +env["TEST_TYPE"] = env["test"] +if "check" in ARGUMENTS : + env["TEST_TYPE"] = "unit" +env["checker_report"] = ARGUMENTS.get("checker_report", False) +env["TEST"] = (env["TEST_TYPE"] != "none") or env.GetOption("clean") +if env.get("valgrind", 0) : + env["TEST_RUNNER"] = "valgrind --suppressions=QA/valgrind.supp -q --leak-check=full --track-origins=yes " +env["TEST_IGNORE_RESULT"] = "ignore_test_result" in ARGUMENTS +env["TEST_CREATE_LIBRARIES"] = "create_test_libraries" in ARGUMENTS + +# Packaging +env["DIST"] = "dist" in ARGUMENTS or env.GetOption("clean") +for path in ["SWIFT_INSTALLDIR", "SWIFTEN_INSTALLDIR"] : + if ARGUMENTS.get(path, "") : + if os.path.isabs(ARGUMENTS[path]) : + env[path] = Dir(ARGUMENTS[path]).abspath + else : + env[path] = Dir("#/" + ARGUMENTS[path]).abspath + +################################################################################ +# XCode / iPhone / ... +################################################################################ + +target = env["target"] +if target in ["iphone-device", "iphone-simulator", "xcode"] : + # Extract/initialize all the information we need + if target == "xcode" : + # Get the information from the XCode environment + env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = os.environ["PLATFORM_DEVELOPER_BIN_DIR"] + env["XCODE_SDKROOT"] = os.environ["SDKROOT"] + env["XCODE_ARCH_FLAGS"] = sum([["-arch", arch] for arch in os.environ["ARCHS"].split(" ")], []) + # Usae absolute path sources so Xcode can highlight compilation errors in swiften + env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM ${SOURCES.abspath}' + else : + # Hard code values + env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin" + if target == "iphone-device": + env["XCODE_ARCH_FLAGS"] = ["-arch", "armv6", "-arch", "armv7"] + sdkPart = "iPhoneOS" + else : + env["XCODE_ARCH_FLAGS"] = ["-arch", "i386"] + sdkPart = "iPhoneSimulator" + sdkVer = "4.3" + env["XCODE_SDKROOT"] = "/Developer/Platforms/" + sdkPart + ".platform/Developer/SDKs/" + sdkPart + sdkVer + ".sdk" + + # Set the build flags + env["CC"] = "$XCODE_PLATFORM_DEVELOPER_BIN_DIR/gcc" + env["CXX"] = "$XCODE_PLATFORM_DEVELOPER_BIN_DIR/g++" + env["OBJCCFLAGS"] = ["-fobjc-abi-version=2", "-fobjc-legacy-dispatch"] + env["LD"] = env["CC"] + env.Append(CCFLAGS = env["XCODE_ARCH_FLAGS"] + ["-fvisibility=hidden"]) + env.Append(LINKFLAGS = env["XCODE_ARCH_FLAGS"]) + env.Append(CPPFLAGS = ["-isysroot", "$XCODE_SDKROOT"]) + env.Append(FRAMEWORKS = ["CoreFoundation", "Foundation", "UIKit", "CoreGraphics"]) + env.Append(LINKFLAGS = env["XCODE_ARCH_FLAGS"] + ["-isysroot", "$XCODE_SDKROOT", "-L\"$XCODE_SDKROOT/usr/lib\"", "-F\"$XCODE_SDKROOT/System/Library/Frameworks\"", "-F\"$XCODE_SDKROOT/System/Library/PrivateFrameworks\""]) + # Bit of a hack, because BOOST doesn't know the endianness for ARM + env.Append(CPPDEFINES = ["_LITTLE_ENDIAN"]) + +# CCache +if env.get("ccache", False) : + env["ENV"]["HOME"] = os.environ["HOME"] + for var in os.environ : + if var.startswith("CCACHE_") : + env["ENV"][var] = os.environ[var] + if env.get("CC", "") != "" : + env["CC"] = "ccache " + env["CC"] + else : + env["CC"] = "ccache gcc" + if env.get("CXX", "") != "" : + env["CXX"] = "ccache " + env["CXX"] + else : + env["CC"] = "ccache g++" + +conf_env = env.Clone() + +Export("env") +Export("conf_env") + +variant = "" +if env["enable_variants"] : + fingerprint = ",".join([flag for flag in env["CXXFLAGS"] + env["CCFLAGS"] if not flag.startswith("-W") and not flag.startswith("-fvisibility")]) + variant = "build/" + fingerprint + if not os.path.exists(Dir("#/build").abspath) : + os.mkdir(Dir("#/build").abspath) + if os.path.exists(Dir("#/build/current").abspath) : + os.unlink(Dir("#/build/current").abspath) + os.symlink(os.path.basename(variant), Dir("#/build/current").abspath) + +Return("variant") diff --git a/BuildTools/SCons/SConstruct b/BuildTools/SCons/SConstruct index bc7781b..88a195a 100644 --- a/BuildTools/SCons/SConstruct +++ b/BuildTools/SCons/SConstruct @@ -1,263 +1,17 @@ import sys, os, re, platform -sys.path.append(Dir("BuildTools/SCons").abspath) import SCons.SConf -################################################################################ -# Build variables -################################################################################ - -vars = Variables(os.path.join(Dir("#").abspath, "config.py")) -vars.Add('cc', "C compiler") -vars.Add('cxx', "C++ compiler") -vars.Add('ccflags', "Extra C(++) compiler flags") -vars.Add('link', "Linker") -vars.Add('linkflags', "Extra linker flags") -vars.Add(BoolVariable("ccache", "Use CCache", "no")) -vars.Add(BoolVariable("distcc", "Use DistCC", "no")) -vars.Add('distcc_hosts', "DistCC hosts (overrides DISTCC_HOSTS)") -vars.Add(EnumVariable("test", "Compile and run tests", "none", ["none", "all", "unit", "system"])) -vars.Add(BoolVariable("optimize", "Compile with optimizations turned on", "no")) -vars.Add(BoolVariable("debug", "Compile with debug information", "yes")) -vars.Add(BoolVariable("allow_warnings", "Allow compilation warnings during compilation", "yes")) -vars.Add(BoolVariable("max_jobs", "Build with maximum number of parallel jobs", "no")) -vars.Add(EnumVariable("target", "Choose a target platform for compilation", "native", ["native", "iphone-simulator", "iphone-device", "xcode"])) -vars.Add(BoolVariable("swift_mobile", "Build mobile Swift", "no")) -if os.name != "nt" : - vars.Add(BoolVariable("coverage", "Compile with coverage information", "no")) -if os.name == "posix" : - vars.Add(BoolVariable("valgrind", "Run tests with valgrind", "no")) -if os.name == "mac" or (os.name == "posix" and os.uname()[0] == "Darwin"): - vars.Add(BoolVariable("universal", "Create universal binaries", "no")) - vars.Add(BoolVariable("mac105", "Link against the 10.5 frameworks", "no")) -if os.name == "nt" : - vars.Add(PathVariable("vcredist", "MSVC redistributable dir", "", PathVariable.PathAccept)) -if os.name == "nt" : - vars.Add(PackageVariable("bonjour", "Bonjour SDK location", "yes")) -vars.Add(PackageVariable("openssl", "OpenSSL location", "yes")) -vars.Add(PathVariable("boost_includedir", "Boost headers location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("boost_libdir", "Boost library location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("expat_includedir", "Expat headers location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("expat_libdir", "Expat library location", None, PathVariable.PathAccept)) -vars.Add("expat_libname", "Expat library name", "libexpat" if os.name == "nt" else "expat") -vars.Add(PathVariable("libidn_includedir", "LibIDN headers location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("libidn_libdir", "LibIDN library location", None, PathVariable.PathAccept)) -vars.Add("libidn_libname", "LibIDN library name", "libidn" if os.name == "nt" else "idn") -vars.Add(PathVariable("avahi_includedir", "Avahi headers location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("avahi_libdir", "Avahi library location", None, PathVariable.PathAccept)) -vars.Add(PathVariable("qt", "Qt location", "", PathVariable.PathAccept)) -vars.Add(PathVariable("docbook_xml", "DocBook XML", None, PathVariable.PathAccept)) -vars.Add(PathVariable("docbook_xsl", "DocBook XSL", None, PathVariable.PathAccept)) - -################################################################################ -# Set up default build & configure environment -################################################################################ - -env = Environment(CPPPATH = ["#"], ENV = { - 'PATH' : os.environ['PATH'], - 'LD_LIBRARY_PATH' : os.environ.get("LD_LIBRARY_PATH", ""), - }, variables = vars) - -Help(vars.GenerateHelpText(env)) +Import("env", "conf_env") -# Default environment variables -env["PLATFORM_FLAGS"] = {} - -# Default custom tools -env.Tool("Test", toolpath = ["#/BuildTools/SCons/Tools"]) -env.Tool("WriteVal", toolpath = ["#/BuildTools/SCons/Tools"]) -env.Tool("BuildVersion", toolpath = ["#/BuildTools/SCons/Tools"]) -env.Tool("Flags", toolpath = ["#/BuildTools/SCons/Tools"]) -if env["PLATFORM"] == "darwin" : - env.Tool("Nib", toolpath = ["#/BuildTools/SCons/Tools"]) - env.Tool("AppBundle", toolpath = ["#/BuildTools/SCons/Tools"]) -if env["PLATFORM"] == "win32" : - env.Tool("WindowsBundle", toolpath = ["#/BuildTools/SCons/Tools"]) - #So we don't need to escalate with UAC - if "TMP" in os.environ.keys() : - env['ENV']['TMP'] = os.environ['TMP'] -env.Tool("SLOCCount", toolpath = ["#/BuildTools/SCons/Tools"]) +root = Dir("../..").abspath # Override SConscript to handle tests oldSConscript = SConscript def SConscript(*arguments, **keywords) : - if not keywords.get("test_only", False) or env["TEST"] : - return apply(oldSConscript, arguments, keywords) + if not keywords.get("test_only", False) or env["TEST"] : + return apply(oldSConscript, arguments, keywords) +env.SConscript = SConscript -# Max out the number of jobs -if env["max_jobs"] : - try : - import multiprocessing - SetOption("num_jobs", multiprocessing.cpu_count()) - except NotImplementedError : - pass - -# Default compiler flags -if env.get("distcc", False) : - env["ENV"]["HOME"] = os.environ["HOME"] - env["ENV"]["DISTCC_HOSTS"] = os.environ.get("DISTCC_HOSTS", "") - if "distcc_hosts" in env : - env["ENV"]["DISTCC_HOSTS"] = env["distcc_hosts"] - env["CC"] = "distcc gcc" - env["CXX"] = "distcc g++" -if env.get("ccache", False) : - env["ENV"]["HOME"] = os.environ["HOME"] - for var in os.environ : - if var.startswith("CCACHE_") : - env["ENV"][var] = os.environ[var] - env["CC"] = "ccache gcc" - env["CXX"] = "ccache g++" -if "cc" in env : - env["CC"] = env["cc"] -if "cxx" in env : - env["CXX"] = env["cxx"] -ccflags = env.get("ccflags", []) -if isinstance(ccflags, str) : - # FIXME: Make the splitting more robust - env["CCFLAGS"] = ccflags.split(" ") -else : - env["CCFLAGS"] = ccflags -if "link" in env : - env["SHLINK"] = env["link"] - env["LINK"] = env["link"] -env["LINKFLAGS"] = env.get("linkflags", []) -# This isn't a real flag (yet) AFAIK. Be sure to append it to the CXXFLAGS -# where you need it -env["OBJCCFLAGS"] = [] -if env["optimize"] : - if env["PLATFORM"] == "win32" : - env.Append(CCFLAGS = ["/O2", "/GL"]) - env.Append(LINKFLAGS = ["/INCREMENTAL:NO", "/LTCG"]) - else : - env.Append(CCFLAGS = ["-O2"]) - -if env["debug"] : - if env["PLATFORM"] == "win32" : - env.Append(CCFLAGS = ["/Zi", "/MDd"]) - env.Append(LINKFLAGS = ["/DEBUG"]) - else : - env.Append(CCFLAGS = ["-g"]) -elif env["PLATFORM"] == "win32" : - env.Append(CCFLAGS = ["/MD"]) - -if env.get("universal", 0) : - assert(env["PLATFORM"] == "darwin") - env.Append(CCFLAGS = [ - "-isysroot", "/Developer/SDKs/MacOSX10.4u.sdk", - "-arch", "i386", - "-arch", "ppc"]) - env.Append(LINKFLAGS = [ - "-mmacosx-version-min=10.4", - "-isysroot", "/Developer/SDKs/MacOSX10.4u.sdk", - "-arch", "i386", - "-arch", "ppc"]) - -if env.get("mac105", 0) : - assert(env["PLATFORM"] == "darwin") - env.Append(CCFLAGS = [ - "-isysroot", "/Developer/SDKs/MacOSX10.5.sdk", - "-arch", "i386"]) - env.Append(LINKFLAGS = [ - "-mmacosx-version-min=10.5", - "-isysroot", "/Developer/SDKs/MacOSX10.5.sdk", - "-arch", "i386"]) - env.Append(FRAMEWORKS = ["Security"]) - -# If we build shared libs on AMD64, we need -fPIC. -# This should have no performance impact om AMD64 -if env["PLATFORM"] == "posix" and platform.machine() == "x86_64" : - env.Append(CCFLAGS = ["-fPIC"]) - -# Warnings -if env["PLATFORM"] == "win32" : - # TODO: Find the ideal set of warnings - #env.Append(CCFLAGS = ["/Wall"]) - pass -else : - env.Append(CXXFLAGS = ["-Wextra", "-Wall", "-Wnon-virtual-dtor", "-Wundef", "-Wold-style-cast", "-Wno-long-long", "-Woverloaded-virtual", "-Wfloat-equal", "-Wredundant-decls"]) - if not env.get("allow_warnings", False) : - env.Append(CXXFLAGS = ["-Werror"]) - gccVersion = env["CCVERSION"].split(".") - if gccVersion >= ["4", "5", "0"] : - env.Append(CCFLAGS = ["-Wlogical-op"]) - -if env.get("coverage", 0) : - assert(env["PLATFORM"] != "win32") - env.Append(CCFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) - env.Append(LINKFLAGS = ["-fprofile-arcs", "-ftest-coverage"]) - -if env["PLATFORM"] == "win32" : - env.Append(LIBS = ["user32", "crypt32", "dnsapi", "ws2_32", "wsock32"]) - env.Append(CCFLAGS = ["/EHsc", "/nologo"]) - # FIXME: We should find a decent solution for MSVS 10 - if int(env["MSVS_VERSION"].split(".")[0]) < 10 : - env["LINKCOM"] = [env["LINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1'] - env["SHLINKCOM"] = [env["SHLINKCOM"], 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] - -if env["PLATFORM"] == "darwin" and not env["target"] in ["iphone-device", "iphone-simulator", "xcode"] : - env.Append(FRAMEWORKS = ["IOKit", "AppKit"]) - -# Testing -env["TEST_TYPE"] = env["test"] -if "check" in ARGUMENTS : - env["TEST_TYPE"] = "unit" -env["checker_report"] = ARGUMENTS.get("checker_report", False) -env["TEST"] = (env["TEST_TYPE"] != "none") or env.GetOption("clean") -if env.get("valgrind", 0) : - env["TEST_RUNNER"] = "valgrind --suppressions=QA/valgrind.supp -q --leak-check=full --track-origins=yes " -env["TEST_IGNORE_RESULT"] = "ignore_test_result" in ARGUMENTS - -# Packaging -env["DIST"] = "dist" in ARGUMENTS or env.GetOption("clean") -for path in ["SWIFT_INSTALLDIR", "SWIFTEN_INSTALLDIR"] : - if ARGUMENTS.get(path, "") : - if os.path.isabs(ARGUMENTS[path]) : - env[path] = Dir(ARGUMENTS[path]).abspath - else : - env[path] = Dir("#/" + ARGUMENTS[path]).abspath - -################################################################################ -# XCode / iPhone / ... -################################################################################ - -target = env["target"] -if target in ["iphone-device", "iphone-simulator", "xcode"] : - # Extract/initialize all the information we need - if target == "xcode" : - # Get the information from the XCode environment - env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = os.environ["PLATFORM_DEVELOPER_BIN_DIR"] - env["XCODE_SDKROOT"] = os.environ["SDKROOT"] - env["XCODE_ARCH_FLAGS"] = sum([["-arch", arch] for arch in os.environ["ARCHS"].split(" ")], []) - else : - # Hard code values - env["XCODE_PLATFORM_DEVELOPER_BIN_DIR"] = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin" - if target == "iphone-device": - env["XCODE_ARCH_FLAGS"] = ["-arch", "armv6"] - sdkPart = "iPhoneOS" - else : - env["XCODE_ARCH_FLAGS"] = ["-arch", "i386"] - sdkPart = "iPhoneSimulator" - sdkVer = "4.0" - env["XCODE_SDKROOT"] = "/Developer/Platforms/" + sdkPart + ".platform/Developer/SDKs/" + sdkPart + sdkVer + ".sdk" - - # Set the build flags - env["CC"] = "$XCODE_PLATFORM_DEVELOPER_BIN_DIR/gcc" - env["CXX"] = "$XCODE_PLATFORM_DEVELOPER_BIN_DIR/g++" - env["OBJCCFLAGS"] = ["-fobjc-abi-version=2", "-fobjc-legacy-dispatch"] - env["LD"] = env["CC"] - env.Append(CCFLAGS = env["XCODE_ARCH_FLAGS"]) - env.Append(LINKFLAGS = env["XCODE_ARCH_FLAGS"]) - env.Append(CPPFLAGS = ["-isysroot", "$XCODE_SDKROOT"]) - env.Append(FRAMEWORKS = ["CoreFoundation", "Foundation", "UIKit", "CoreGraphics"]) - env.Append(LINKFLAGS = env["XCODE_ARCH_FLAGS"] + ["-isysroot", "$XCODE_SDKROOT", "-L\"$XCODE_SDKROOT/usr/lib\"", "-F\"$XCODE_SDKROOT/System/Library/Frameworks\"", "-F\"$XCODE_SDKROOT/System/Library/PrivateFrameworks\""]) - # Bit of a hack, because BOOST doesn't know the endianness for ARM - env.Append(CPPDEFINES = ["_LITTLE_ENDIAN"]) - -conf_env = env.Clone() - -Export("env") -Export("conf_env") - - ################################################################################ # Extend the default build environment (not affecting the configure env) # @@ -317,9 +71,32 @@ def checkObjCHeader(context, header) : # Platform configuration ################################################################################ +env.Append(CPPPATH = [root]) + if ARGUMENTS.get("force-configure", 0) : SCons.SConf.SetCacheMode("force") +def CheckPKG(context, name): + context.Message( 'Checking for package %s... ' % name ) + ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0] + context.Result( ret ) + return ret + +def CheckVersion(context, library, version, define, header, value) : + context.Message("Checking " + library + " version (>= " + version + ") ...") + ret = context.TryRun(""" +#include <%(header)s> +#include <stdio.h> + +int main(int argc, char* argv[]) { + printf("%%d\\n", %(define)s); + return 0; +} +""" % { "header" : header, "define": define }, ".c") + ok = ret[0] and int(ret[1]) >= value + context.Result(ok) + return ok + conf = Configure(conf_env) if not conf.CheckCXX() or not conf.CheckCC() : @@ -404,7 +181,7 @@ env["HAVE_XSS"] = 0 if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : xss_flags = { "LIBPATH": ["/usr/X11R6/lib"], - "LIBS": ["X11", "Xss"] + "LIBS": ["Xss"] } xss_env = conf_env.Clone() xss_env.MergeFlags(xss_flags) @@ -414,6 +191,31 @@ if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : env["XSS_FLAGS"] = xss_flags conf.Finish() +# GConf +env["HAVE_GCONF"] = 0 +if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" : + gconf_env = conf_env.Clone() + conf = Configure(gconf_env, custom_tests = {"CheckPKG": CheckPKG}) + if conf.CheckPKG("gconf-2.0") : + gconf_bare_env = Environment() + gconf_bare_env.ParseConfig('pkg-config --cflags gconf-2.0 gobject-2.0 --libs gconf-2.0 gobject-2.0') + gconf_flags = { + "LIBS": gconf_bare_env["LIBS"], + "CCFLAGS": gconf_bare_env["CCFLAGS"], + "CPPPATH": gconf_bare_env["CPPPATH"], + "CPPDEFINES": gconf_bare_env.get("CPPDEFINES", []), + } + gconf_env.MergeFlags(gconf_flags) + if conf.CheckCHeader("gconf/gconf-client.h") and conf.CheckLib("gconf-2") : + env["HAVE_GCONF"] = 1 + env["GCONF_FLAGS"] = { + "LIBS": gconf_env["LIBS"], + "CCFLAGS": gconf_env["CCFLAGS"], + "CPPPATH": gconf_env["CPPPATH"], + "CPPDEFINES": gconf_env.get("CPPDEFINES", []), + } + conf.Finish() + # Sparkle env["HAVE_SPARKLE"] = 0 if env["PLATFORM"] == "darwin" : @@ -451,8 +253,9 @@ if env["PLATFORM"] == "win32" : env["HAVE_SNARL"] = True # LibXML -conf = Configure(conf_env) +conf = Configure(conf_env, custom_tests = {"CheckVersion": CheckVersion}) if 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 env["LIBXML_FLAGS"] = { "LIBS": ["xml2"] } conf.Finish() @@ -460,8 +263,9 @@ conf.Finish() if not env.get("HAVE_LIBXML", 0) : libxml_env = conf_env.Clone() libxml_env.Append(CPPPATH = ["/usr/include/libxml2"]) - conf = Configure(libxml_env) + conf = Configure(libxml_env, custom_tests = {"CheckVersion": CheckVersion}) if 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 env["LIBXML_FLAGS"] = { "CPPPATH": ["/usr/include/libxml2"], "LIBS": ["xml2"] } conf.Finish() @@ -507,6 +311,23 @@ else : env["LIBIDN_BUNDLED"] = 1 conf.Finish() +# 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() + # Lua env["LUA_BUNDLED"] = 1 @@ -558,7 +379,10 @@ if use_openssl and openssl_conf.CheckCHeader("openssl/ssl.h") : env["OPENSSL_FLAGS"]["LIBS"] = ["libeay32MD", "ssleay32MD"] else: env["OPENSSL_FLAGS"]["LIBS"] = ["ssl", "crypto"] -elif target in ("iphone-device", "iphone-simulator", "xcode") : + if env["PLATFORM"] == "darwin" : + 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 : @@ -621,6 +445,9 @@ if env.Dir("#/.git").exists() : # Project files ################################################################################ +# Build tools +env.SConscript(dirs = ["#/BuildTools/CLang"]) + # Modules modules = [] for dir in os.listdir(Dir("#/3rdParty").abspath) : @@ -642,7 +469,7 @@ for dir in os.listdir(Dir("#").abspath) : 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"] : env["SCONS_STAGE"] = stage - SConscript(dirs = map(lambda x : "#/" + x, modules)) + SConscript(dirs = map(lambda x : root + "/" + x, modules)) # SLOCCount if ARGUMENTS.get("sloccount", False) : diff --git a/BuildTools/SCons/Tools/AppBundle.py b/BuildTools/SCons/Tools/AppBundle.py index c271575..6a343f6 100644 --- a/BuildTools/SCons/Tools/AppBundle.py +++ b/BuildTools/SCons/Tools/AppBundle.py @@ -1,7 +1,7 @@ import SCons.Util, os.path def generate(env) : - def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}) : + def createAppBundle(env, bundle, version = "1.0", resources = [], frameworks = [], info = {}, handlesXMPPURIs = False) : bundleDir = bundle + ".app" bundleContentsDir = bundleDir + "/Contents" resourcesDir = bundleContentsDir + "/Resources" @@ -32,6 +32,18 @@ def generate(env) : for key, value in infoDict.items() : plist += "<key>" + key + "</key>\n" plist += "<string>" + value.encode("utf-8") + "</string>\n" + if handlesXMPPURIs : + plist += """<key>CFBundleURLTypes</key> +<array> + <dict> + <key>CFBundleURLName</key> + <string>XMPP URL</string> + <key>CFBundleURLSchemes</key> + <array> + <string>xmpp</string> + </array> + </dict> +</array>\n""" plist += """</dict> </plist> """ |