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

Use CMAKE_MSVC_RUNTIME_LIBRARY to consistently handle linking mode for MSVC runtime #10344

Closed
hcho3 opened this issue May 29, 2024 · 0 comments · Fixed by #10404
Closed

Use CMAKE_MSVC_RUNTIME_LIBRARY to consistently handle linking mode for MSVC runtime #10344

hcho3 opened this issue May 29, 2024 · 0 comments · Fixed by #10404
Assignees

Comments

@hcho3
Copy link
Collaborator

hcho3 commented May 29, 2024

On the Windows platform, the MSVC (Microsoft Visual C++) runtime can be linked either statically or dynamically. Currently, XGBoost makes this choice by manually editing raw build flags:

foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
set(${variable} "${${variable}}" PARENT_SCOPE)
endif()
endforeach()
set(variables
CMAKE_CUDA_FLAGS
CMAKE_CUDA_FLAGS_DEBUG
CMAKE_CUDA_FLAGS_MINSIZEREL
CMAKE_CUDA_FLAGS_RELEASE
CMAKE_CUDA_FLAGS_RELWITHDEBINFO
)
foreach(variable ${variables})
if(${variable} MATCHES "-MD")
string(REGEX REPLACE "-MD" "-MT" ${variable} "${${variable}}")
set(${variable} "${${variable}}" PARENT_SCOPE)
endif()
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
set(${variable} "${${variable}}" PARENT_SCOPE)
endif()
endforeach()
This approach is brittle and prone to weird breakage, especially when XGBoost is used by a downstream project.

A more robust method is to use the built-in flag CMAKE_MSVC_RUNTIME_LIBRARY to control the linking mode for the MSVC runtime. See https://github.com/dmlc/treelite/blob/260a5d2c22830ec2bdaa5fc6dc186aa6f3b551e7/CMakeLists.txt#L46-L54 for an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant