Skip to content

Commit e4d1add

Browse files
committed
Align MSVC runtime (MD[d], MT) options to engine #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 e4d1add

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

cmake/windows.cmake

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ function( windows_options )
1111

1212
option( GODOT_USE_STATIC_CPP "Link MinGW/MSVC C++ runtime libraries statically" ON )
1313

14-
# The below scons variables are controlled via toolchain files instead
15-
# "mingw_prefix" "MinGW prefix"
16-
# "use_llvm" "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)"
17-
# "use_mingw" "Use the MinGW compiler instead of MSVC - only effective on Windows"
14+
option( GODOT_DEBUG_CRT "Compile with MSVC's debug CRT (/MDd)" OFF )
15+
1816
endfunction()
1917

2018
function( windows_generate TARGET_NAME )
@@ -23,27 +21,21 @@ function( windows_generate TARGET_NAME )
2321
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
2422
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
2523
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
24+
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )
2625

2726
set_target_properties( ${TARGET_NAME}
2827
PROPERTIES
2928
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
29+
INTERFACE_MSVC_RUNTIME_LIBRARY
30+
"$<IF:${DEBUG_CRT},MultiThreadedDebugDLL,$<IF:${STATIC_CPP},MultiThreaded,MultiThreadedDLL>>"
3031
)
3132

3233
target_compile_definitions( ${TARGET_NAME}
3334
PUBLIC
3435
WINDOWS_ENABLED
35-
$<${IS_MSVC}:
36-
TYPED_METHOD_BIND
37-
NOMINMAX
38-
>
36+
$<${IS_MSVC}: TYPED_METHOD_BIND NOMINMAX >
3937
)
4038

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-
)
4739
target_link_options( ${TARGET_NAME}
4840
PUBLIC
4941

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)