2022-06-06 13:09:32 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import my_spawn
|
2022-07-04 15:50:54 +00:00
|
|
|
|
|
|
|
from SCons.Tool import msvc, mingw
|
2022-06-06 13:09:32 +00:00
|
|
|
from SCons.Variables import *
|
|
|
|
|
|
|
|
|
|
|
|
def options(opts):
|
|
|
|
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
|
2022-07-09 14:24:32 +00:00
|
|
|
opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
|
2023-04-02 14:46:40 +00:00
|
|
|
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
base = None
|
2022-07-04 15:50:54 +00:00
|
|
|
if not env["use_mingw"] and msvc.exists(env):
|
2022-06-06 13:09:32 +00:00
|
|
|
if env["arch"] == "x86_64":
|
|
|
|
env["TARGET_ARCH"] = "amd64"
|
|
|
|
elif env["arch"] == "x86_32":
|
|
|
|
env["TARGET_ARCH"] = "x86"
|
2022-07-04 15:50:54 +00:00
|
|
|
env["is_msvc"] = True
|
2022-12-20 14:22:29 +00:00
|
|
|
|
|
|
|
# MSVC, linker, and archiver.
|
2022-07-04 15:50:54 +00:00
|
|
|
msvc.generate(env)
|
2022-12-20 14:22:29 +00:00
|
|
|
env.Tool("mslib")
|
|
|
|
env.Tool("mslink")
|
|
|
|
|
2022-09-11 11:12:44 +00:00
|
|
|
env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
|
2023-08-16 09:47:19 +00:00
|
|
|
env.Append(CCFLAGS=["/utf-8"])
|
2022-09-11 17:25:22 +00:00
|
|
|
|
2022-07-09 14:24:32 +00:00
|
|
|
if env["use_clang_cl"]:
|
|
|
|
env["CC"] = "clang-cl"
|
|
|
|
env["CXX"] = "clang-cl"
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-04-02 14:46:40 +00:00
|
|
|
if env["use_static_cpp"]:
|
|
|
|
env.Append(CCFLAGS=["/MT"])
|
|
|
|
else:
|
|
|
|
env.Append(CCFLAGS=["/MD"])
|
|
|
|
|
2022-06-06 13:09:32 +00:00
|
|
|
elif sys.platform == "win32" or sys.platform == "msys":
|
|
|
|
env["use_mingw"] = True
|
2022-07-04 15:50:54 +00:00
|
|
|
mingw.generate(env)
|
2022-06-06 13:09:32 +00:00
|
|
|
# Don't want lib prefixes
|
|
|
|
env["IMPLIBPREFIX"] = ""
|
|
|
|
env["SHLIBPREFIX"] = ""
|
|
|
|
# Want dll suffix
|
|
|
|
env["SHLIBSUFFIX"] = ".dll"
|
2023-04-02 14:46:40 +00:00
|
|
|
|
|
|
|
env.Append(CCFLAGS=["-Wwrite-strings"])
|
|
|
|
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
|
|
|
|
if env["use_static_cpp"]:
|
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-static",
|
|
|
|
"-static-libgcc",
|
|
|
|
"-static-libstdc++",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-06-06 13:09:32 +00:00
|
|
|
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
|
|
|
|
my_spawn.configure(env)
|
|
|
|
|
|
|
|
else:
|
|
|
|
env["use_mingw"] = True
|
|
|
|
# Cross-compilation using MinGW
|
|
|
|
prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
|
|
|
|
env["CXX"] = prefix + "-w64-mingw32-g++"
|
|
|
|
env["CC"] = prefix + "-w64-mingw32-gcc"
|
|
|
|
env["AR"] = prefix + "-w64-mingw32-ar"
|
|
|
|
env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
|
|
|
|
env["LINK"] = prefix + "-w64-mingw32-g++"
|
|
|
|
# Want dll suffix
|
|
|
|
env["SHLIBSUFFIX"] = ".dll"
|
|
|
|
|
2023-04-02 14:46:40 +00:00
|
|
|
env.Append(CCFLAGS=["-Wwrite-strings"])
|
|
|
|
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
|
|
|
|
if env["use_static_cpp"]:
|
|
|
|
env.Append(
|
|
|
|
LINKFLAGS=[
|
|
|
|
"-static",
|
|
|
|
"-static-libgcc",
|
|
|
|
"-static-libstdc++",
|
|
|
|
]
|
|
|
|
)
|
2023-07-22 12:46:14 +00:00
|
|
|
|
|
|
|
env.Append(CPPDEFINES=["WINDOWS_ENABLED"])
|