Skip to content

Commit c47bd60

Browse files
authored
Merge pull request #1203 from dsnopek/1082-update
Statically link mingw/msvc runtime libraries on Windows
2 parents 5834e16 + a745c2a commit c47bd60

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

tools/targets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ def generate(env):
6060
env.Append(CCFLAGS=["/Zi", "/FS"])
6161
env.Append(LINKFLAGS=["/DEBUG:FULL"])
6262

63-
if env["optimize"] == "speed" or env["optimize"] == "speed_trace":
63+
if env["optimize"] == "speed":
6464
env.Append(CCFLAGS=["/O2"])
6565
env.Append(LINKFLAGS=["/OPT:REF"])
66+
elif env["optimize"] == "speed_trace":
67+
env.Append(CCFLAGS=["/O2"])
68+
env.Append(LINKFLAGS=["/OPT:REF", "/OPT:NOICF"])
6669
elif env["optimize"] == "size":
6770
env.Append(CCFLAGS=["/O1"])
6871
env.Append(LINKFLAGS=["/OPT:REF"])
69-
70-
if env["optimize"] == "debug" or env["optimize"] == "none":
71-
env.Append(CCFLAGS=["/MDd", "/Od"])
72-
else:
73-
env.Append(CCFLAGS=["/MD"])
72+
elif env["optimize"] == "debug" or env["optimize"] == "none":
73+
env.Append(CCFLAGS=["/Od"])
7474

7575
else:
7676
if env["debug_symbols"]:

tools/windows.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
def options(opts):
1010
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
1111
opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
12+
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
1213

1314

1415
def exists(env):
@@ -37,6 +38,11 @@ def generate(env):
3738
env["CC"] = "clang-cl"
3839
env["CXX"] = "clang-cl"
3940

41+
if env["use_static_cpp"]:
42+
env.Append(CCFLAGS=["/MT"])
43+
else:
44+
env.Append(CCFLAGS=["/MD"])
45+
4046
elif sys.platform == "win32" or sys.platform == "msys":
4147
env["use_mingw"] = True
4248
mingw.generate(env)
@@ -45,6 +51,18 @@ def generate(env):
4551
env["SHLIBPREFIX"] = ""
4652
# Want dll suffix
4753
env["SHLIBSUFFIX"] = ".dll"
54+
55+
env.Append(CCFLAGS=["-Wwrite-strings"])
56+
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
57+
if env["use_static_cpp"]:
58+
env.Append(
59+
LINKFLAGS=[
60+
"-static",
61+
"-static-libgcc",
62+
"-static-libstdc++",
63+
]
64+
)
65+
4866
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
4967
my_spawn.configure(env)
5068

@@ -60,15 +78,15 @@ def generate(env):
6078
# Want dll suffix
6179
env["SHLIBSUFFIX"] = ".dll"
6280

63-
# These options are for a release build even using target=debug
64-
env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
65-
env.Append(
66-
LINKFLAGS=[
67-
"--static",
68-
"-Wl,--no-undefined",
69-
"-static-libgcc",
70-
"-static-libstdc++",
71-
]
72-
)
81+
env.Append(CCFLAGS=["-Wwrite-strings"])
82+
env.Append(LINKFLAGS=["-Wl,--no-undefined"])
83+
if env["use_static_cpp"]:
84+
env.Append(
85+
LINKFLAGS=[
86+
"-static",
87+
"-static-libgcc",
88+
"-static-libstdc++",
89+
]
90+
)
7391

7492
env.Append(CPPDEFINES=["WINDOWS_ENABLED"])

0 commit comments

Comments
 (0)