Skip to content

Commit

Permalink
[CMake] Use CMAKE_MSVC_RUNTIME_LIBRARY to apply /MT (#6484)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcho3 authored Jul 4, 2024
1 parent a8b7078 commit 00d6edd
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>")
endif()

if(USE_CUDA)
find_package(CUDAToolkit 11.0 REQUIRED)
include_directories(${CUDAToolkit_INCLUDE_DIRS})
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 00d6edd

Please sign in to comment.