From 00d6edd2c27710458fec3aa17b12a7d3ef75dcd1 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Wed, 3 Jul 2024 20:41:25 -0700 Subject: [PATCH] [CMake] Use CMAKE_MSVC_RUNTIME_LIBRARY to apply /MT (#6484) --- CMakeLists.txt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9ff8a14a653..09eaaa214261 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,11 @@ if(__INTEGRATE_OPENCL) endif() endif() +if(BUILD_CPP_TEST AND MSVC) + # Use /MT flag to statically link the C runtime + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() + if(USE_CUDA) find_package(CUDAToolkit 11.0 REQUIRED) include_directories(${CUDAToolkit_INCLUDE_DIRS}) @@ -685,18 +690,6 @@ if(BUILD_CPP_TEST) file(GLOB CPP_TEST_SOURCES tests/cpp_tests/*.cpp) if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") - set( - CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() endif() add_executable(testlightgbm ${CPP_TEST_SOURCES}) target_link_libraries(testlightgbm PRIVATE lightgbm_objs lightgbm_capi_objs GTest::GTest)