Skip to content

Commit

Permalink
Use CMAKE_MSVC_RUNTIME_LIBRARY to consistently handle linking mode fo…
Browse files Browse the repository at this point in the history
…r MSVC runtime (#687)

* Use CMAKE_MSVC_RUNTIME_LIBRARY to consistently handle linking mode for MSVC runtime

* Require CMake 3.15+
  • Loading branch information
hcho3 authored Jun 14, 2024
1 parent 1ef6649 commit 1334185
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

project(dmlc VERSION 0.3 LANGUAGES C CXX)

Expand Down Expand Up @@ -130,16 +130,6 @@ if(USE_OPENMP)
endif()

find_package(OpenMP REQUIRED)

# For CMake < 3.9, we need to make target OpenMP::OpenMP_CXX ourselves
if(NOT TARGET OpenMP::OpenMP_CXX)
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
target_link_libraries(dmlc PRIVATE OpenMP::OpenMP_CXX)
endif()

Expand Down Expand Up @@ -199,14 +189,12 @@ target_compile_definitions(dmlc PUBLIC -DDMLC_CORE_USE_CMAKE)
# compiler flags
if(MSVC)
target_compile_definitions(dmlc PUBLIC -DDMLC_USE_CXX11=1)
if(NOT BUILD_SHARED_LIBS AND NOT DMLC_FORCE_SHARED_CRT)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
if(DMLC_FORCE_SHARED_CRT)
message(STATUS "DMLC-Core: Using dynamically linked MSVC runtime...")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
message(STATUS "DMLC-Core: Using statically linked MSVC runtime...")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
else()
Expand Down

0 comments on commit 1334185

Please sign in to comment.