Skip to content

Commit f690046

Browse files
philippremyservantftransperfect
authored andcommitted
FIX: Explicitly set MSVC runtime library versions
This commit adapts the project to the new handling of CMP0091: (1) Explicitly sets the msvcrt flags based on the current configuration (Debug, Non-Debug; Static or Shared Libraries) (2) Explicitly sets the appropriate nvcc "--compiler-flags" to pass through the current msvcrt configuration when compiling CUDA code Fixes linker errors if compiling CUDA code with MSVC as host compiler when cmake_minimum_required() is > 3.15. Unifies MSVC runtime library selection throughout the project. Signed-off-by: Philipp Remy <[email protected]>
1 parent 6cc6e32 commit f690046

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ if (WIN32)
136136
add_definitions(-DNOMINMAX)
137137
add_definitions(-D_USE_MATH_DEFINES)
138138
if (MSVC)
139+
# MSVC library version
140+
cmake_policy(SET CMP0091 NEW) # Manually choose msvcrt version
141+
if(BUILD_SHARED_LIBS)
142+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
143+
else()
144+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
145+
endif()
139146
add_compile_options(/bigobj)
140147
add_compile_options(/MP)
141148
endif()

src/cmake/Helpers.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,27 @@ function(alicevision_add_library library_name)
4040
endif()
4141

4242
elseif (BUILD_SHARED_LIBS)
43-
cuda_add_library(${library_name} SHARED ${LIBRARY_SOURCES} OPTIONS --compiler-options "-fPIC")
43+
if(MSVC)
44+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
45+
set(CUDA_LIB_OPTIONS --compiler-options "/MDd")
46+
else()
47+
set(CUDA_LIB_OPTIONS --compiler-options "/MD")
48+
endif()
49+
else()
50+
set(CUDA_LIB_OPTIONS --compiler-options "-fPIC")
51+
endif()
52+
cuda_add_library(${library_name} SHARED ${LIBRARY_SOURCES} OPTIONS ${CUDA_LIB_OPTIONS})
4453
else()
45-
cuda_add_library(${library_name} ${LIBRARY_SOURCES})
54+
if(MSVC)
55+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
56+
set(CUDA_LIB_OPTIONS --compiler-options "/MTd")
57+
else()
58+
set(CUDA_LIB_OPTIONS --compiler-options "/MT")
59+
endif()
60+
else()
61+
set(CUDA_LIB_OPTIONS --compiler-options "-fPIC")
62+
endif()
63+
cuda_add_library(${library_name} ${LIBRARY_SOURCES} OPTIONS ${CUDA_LIB_OPTIONS})
4664
endif()
4765

4866
if (ALICEVISION_REMOVE_ABSOLUTE)

0 commit comments

Comments
 (0)