Ejemplo n.º 1
0
def getEnvironment(defaultDebug: bool = True,
                   libraries: bool = True,
                   stdlib: str = "c++17",
                   useSan=True,
                   customVariables=None):
    variables = Script.Variables()
    variables.AddVariables(
        BoolVariable(
            "debug",
            "Build with the debug flag and reduced optimization. `export LUNASCONS_DEBUG=true` to default debug to true",
            os.getenv("LUNASCONS_DEBUG",
                      "False").lower() in ["true", "1", "yes"]),
        BoolVariable("systemCompiler",
                     "Whether to use CXX/CC from the environment variables.",
                     True),
        ("profile", "Which profile to use for Conan, if Conan is enabled",
         "default"), ("settings", "Settings for Conan.", None),
        ("options", "Options for Conan", None),
        ("buildDir",
         "Build directory. Defaults to build/. This variable CANNOT be empty",
         "build/"),
        ("dynamic",
         "(Windows only!) Whether to use /MT or /MD. False for MT, true for MD",
         False), BoolVariable("coverage", "Adds the --coverage option", False))

    if (customVariables != None):
        if (type(customVariables) is not list):
            raise RuntimeError("customVariables has to be a list")
        for variable in customVariables:
            variables.Add(variable)

    envVars = {"PATH": os.environ["PATH"]}
    if "TEMP" in os.environ:
        envVars["TEMP"] = os.environ["TEMP"]

    tools = []
    if "windows" in platform.platform().lower():
        if "CXX" in os.environ and os.environ["CXX"] in ["clang++", "g++"]:
            tools.append("mingw")  # Preliminary MinGW mitigation
        else:
            tools = None
    else:
        tools = None
    env = Environment(variables=variables, ENV=envVars, tools=tools)

    (compiler, argType) = getCompiler(env)
    print("Detected compiler: {}. Running debug: {}".format(
        compiler, env["debug"]))

    if "TERM" in os.environ:
        env["ENV"]["TERM"] = os.environ["TERM"]

    if (env["PLATFORM"] == "win32" and compiler != "clang-cl"
            and compiler != "msvc"):
        print("Forcing MinGW mode")
        # We also need to normalize the compiler afterwards.
        # MinGW forces GCC
        CXX = env["CXX"]
        CC = env["CC"]
        Tool("mingw")(env)
        env["CXX"] = CXX
        env["CC"] = CC

    path = env["buildDir"]
    if (path == ""):
        raise RuntimeError("buildDir cannot be empty.")
    print("Building in {}".format(path))

    compileFlags = ""

    if (argType == ZEnvFile.CompilerType.POSIX):
        compileFlags += "-std=" + stdlib + " -pedantic -Wall -Wextra -Wno-c++11-narrowing"
        if env["debug"] == True:
            compileFlags += " -g -O0 "
            if env["coverage"] == True:
                compileFlags += " --coverage "
                env.Append(LINKFLAGS=["--coverage"])

        else:
            compileFlags += " -O3 "
    else:
        # Note to self: /W4 and /Wall spews out warnings for dependencies. Roughly equivalent to -Wall -Wextra on stereoids
        compileFlags += "/std:" + stdlib + " /W3 /EHsc /FS "
        if env["debug"] == True:
            env.Append(LINKFLAGS=["/DEBUG"])
            env.Append(
                CXXFLAGS=["/MTd" if not env["dynamic"] else "MDd", "/Zi"])
        else:
            compileFlags += " /O2 " + ("/MT"
                                       if not env["dynamic"] else "/MD") + " "
    env.Append(CXXFLAGS=compileFlags.split(" "))

    zEnv = ZEnvFile.ZEnv(env, path, env["debug"], compiler, argType, variables)
    if env["debug"] == True and useSan:
        if argType == ZEnvFile.CompilerType.POSIX:
            zEnv.environment.Append(CXXFLAGS=["-fsanitize=undefined"])

        if env["PLATFORM"] != "win32":
            zEnv.environment.Append(LINKFLAGS=["-fsanitize=undefined"])
        elif (compiler != "msvc"):
            print(
                "WARNING: Windows detected. MinGW doesn't have libubsan. Using crash instead (-fsanitize-undefined-trap-on-error)"
            )
            zEnv.environment.Append(
                CXXFLAGS=["-fsanitize-undefined-trap-on-error"])
    return zEnv
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
from SCons.Script import Repository, Environment
# Mount code directories
Repository(['#./vendor/ceedling/vendor/unity/src'])

CCCOM = '$CC -c $_CCCOMCOM $SOURCE -o $TARGET '
CPPPATH = ['#./vendor/ceedling/vendor/unity/src', '#./include']
CPPFLAGS = ['-g', '-std=c99', '-pedantic', '-Wall', '-DTEST']
UNITYHELPDIR = '#./vendor/ceedling/vendor/unity/auto'

env_test = Environment()
env_test.Append(UNITYHELPDIR=UNITYHELPDIR, )

env_test.Replace(
    CCCOM=CCCOM,
    CPPPATH=CPPPATH,
    CPPFLAGS=CPPFLAGS,
)