9
9
def options (opts ):
10
10
opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
11
11
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 ))
12
13
13
14
14
15
def exists (env ):
@@ -37,6 +38,11 @@ def generate(env):
37
38
env ["CC" ] = "clang-cl"
38
39
env ["CXX" ] = "clang-cl"
39
40
41
+ if env ["use_static_cpp" ]:
42
+ env .Append (CCFLAGS = ["/MT" ])
43
+ else :
44
+ env .Append (CCFLAGS = ["/MD" ])
45
+
40
46
elif sys .platform == "win32" or sys .platform == "msys" :
41
47
env ["use_mingw" ] = True
42
48
mingw .generate (env )
@@ -45,6 +51,18 @@ def generate(env):
45
51
env ["SHLIBPREFIX" ] = ""
46
52
# Want dll suffix
47
53
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
+
48
66
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
49
67
my_spawn .configure (env )
50
68
@@ -60,15 +78,15 @@ def generate(env):
60
78
# Want dll suffix
61
79
env ["SHLIBSUFFIX" ] = ".dll"
62
80
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
+ )
73
91
74
92
env .Append (CPPDEFINES = ["WINDOWS_ENABLED" ])
0 commit comments