Skip to content

Commit f9c02f3

Browse files
committed
Align MSVC runtime (MD[d], MT) options to engine godotengine#1647
Engine has an option to link to MDd debug_crt add flag to SCons options Add flag to CMAKE options
1 parent a42b363 commit f9c02f3

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

cmake/windows.cmake

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Windows platform
1010
function( windows_options )
1111

1212
option( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
13+
option( GODOT_DEBUG_CRT "Compile with MSVC's debug CRT (/MDd)" OFF )
1314

14-
# The below scons variables are controlled via toolchain files instead
15+
# The below scons variables are controlled via toolchain files instead
1516
# "mingw_prefix" "MinGW prefix"
1617
# "use_llvm" "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)"
1718
# "use_mingw" "Use the MinGW compiler instead of MSVC - only effective on Windows"
@@ -23,27 +24,20 @@ function( windows_generate TARGET_NAME )
2324
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
2425
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
2526
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
27+
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )
2628

2729
set_target_properties( ${TARGET_NAME}
2830
PROPERTIES
2931
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
32+
MSVC_RUNTIME_LIBRARY "$<IF:${DEBUG_CRT},MultiThreadedDebugDLL,$<IF:${STATIC_CPP},MultiThreaded,MultiThreadedDLL>>"
3033
)
3134

3235
target_compile_definitions( ${TARGET_NAME}
3336
PUBLIC
3437
WINDOWS_ENABLED
35-
$<${IS_MSVC}:
36-
TYPED_METHOD_BIND
37-
NOMINMAX
38-
>
38+
$<${IS_MSVC}: TYPED_METHOD_BIND NOMINMAX >
3939
)
4040

41-
target_compile_options( ${TARGET_NAME}
42-
PUBLIC
43-
$<${IS_MSVC}:
44-
$<IF:${STATIC_CPP},/MT,/MD>$<${IS_DEV}:d> # Link microsoft runtime
45-
>
46-
)
4741
target_link_options( ${TARGET_NAME}
4842
PUBLIC
4943

tools/windows.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def options(opts):
7878
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
7979
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
8080
opts.Add(BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr.", True))
81+
opts.Add(BoolVariable("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False))
8182
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)", False))
8283
opts.Add("mingw_prefix", "MinGW prefix", mingw)
8384

@@ -117,10 +118,14 @@ def generate(env):
117118
env["CC"] = "clang-cl"
118119
env["CXX"] = "clang-cl"
119120

120-
if env["use_static_cpp"]:
121-
env.Append(CCFLAGS=["/MT"])
121+
if env["debug_crt"]:
122+
# Always use dynamic runtime, static debug CRT breaks thread_local.
123+
env.AppendUnique(CCFLAGS=["/MDd"])
122124
else:
123-
env.Append(CCFLAGS=["/MD"])
125+
if env["use_static_cpp"]:
126+
env.AppendUnique(CCFLAGS=["/MT"])
127+
else:
128+
env.AppendUnique(CCFLAGS=["/MD"])
124129

125130
if env["silence_msvc"] and not env.GetOption("clean"):
126131
silence_msvc(env)

0 commit comments

Comments
 (0)