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)