-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] Use CMAKE_MSVC_RUNTIME_LIBRARY to apply /MT #6484
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just left one small request to move this code back down inside the if(BUILD_CPP_TEST)
block.
Don't worry about the failing CI jobs... they're flaky and the failures are unrelated to your changes.
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") | ||
endforeach() | ||
# Use /MT flag to statically link the C runtime | ||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hcho3 could you please look into https://dev.azure.com/lightgbm-ci/lightgbm-ci/_build/results?buildId=16422&view=logs&j=1f4df553-f999-5fff-c6fe-71123c872ae2&t=3537c7a9-e1e2-54d5-18f4-f7d9e02b9f6d?
boosting.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in test_array_args.obj [D:\a\1\s\build\testlightgbm.vcxproj]
Does this maybe need to be set earlier, before the target is declared, to affect the flags? I'm not really sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this has to be set before targets are created.
Use the built-in flag
CMAKE_MSVC_RUNTIME_LIBRARY
in CMake to robustly handle the linking mode for the Windows C runtime (/MD
vs/MT
). See https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html