Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Align MSVC runtime (MD[d], MT) options to engine #1647

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions cmake/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ function( windows_options )

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

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

endfunction()

function( windows_generate TARGET_NAME )
Expand All @@ -23,10 +21,13 @@ function( windows_generate TARGET_NAME )
set( NOT_MSVC "$<NOT:${IS_MSVC}>" )
set( STATIC_CPP "$<BOOL:${GODOT_USE_STATIC_CPP}>")
set( DISABLE_EXCEPTIONS "$<BOOL:${GODOT_DISABLE_EXCEPTIONS}>")
set( DEBUG_CRT "$<BOOL:${GODOT_DEBUG_CRT}>" )

set_target_properties( ${TARGET_NAME}
PROPERTIES
PDB_OUTPUT_DIRECTORY "$<1:${CMAKE_SOURCE_DIR}/bin>"
INTERFACE_MSVC_RUNTIME_LIBRARY
"$<IF:${DEBUG_CRT},MultiThreadedDebugDLL,$<IF:${STATIC_CPP},MultiThreaded,MultiThreadedDLL>>"
)

target_compile_definitions( ${TARGET_NAME}
Expand All @@ -38,12 +39,6 @@ function( windows_generate TARGET_NAME )
>
)

target_compile_options( ${TARGET_NAME}
PUBLIC
$<${IS_MSVC}:
$<IF:${STATIC_CPP},/MT,/MD>$<${IS_DEV}:d> # Link microsoft runtime
>
)
target_link_options( ${TARGET_NAME}
PUBLIC

Expand Down
11 changes: 8 additions & 3 deletions tools/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def options(opts):
opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
opts.Add(BoolVariable("silence_msvc", "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr.", True))
opts.Add(BoolVariable("debug_crt", "Compile with MSVC's debug CRT (/MDd)", False))
opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)", False))
opts.Add("mingw_prefix", "MinGW prefix", mingw)

Expand Down Expand Up @@ -117,10 +118,14 @@ def generate(env):
env["CC"] = "clang-cl"
env["CXX"] = "clang-cl"

if env["use_static_cpp"]:
env.Append(CCFLAGS=["/MT"])
if env["debug_crt"]:
# Always use dynamic runtime, static debug CRT breaks thread_local.
env.AppendUnique(CCFLAGS=["/MDd"])
else:
env.Append(CCFLAGS=["/MD"])
if env["use_static_cpp"]:
env.AppendUnique(CCFLAGS=["/MT"])
else:
env.AppendUnique(CCFLAGS=["/MD"])

if env["silence_msvc"] and not env.GetOption("clean"):
silence_msvc(env)
Expand Down