@@ -251,19 +251,33 @@ else()
251
251
add_win_flangrt_runtime (STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN )
252
252
add_win_flangrt_runtime (STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN )
253
253
254
- # Unittests link against LLVMSupport which is using CMake's default runtime
255
- # library selection, which is either MultiThreadedDLL or MultiThreadedDebugDLL
256
- # depending on the configuration. They have to match or linking will fail.
254
+ # Unittests link against LLVMSupport. If CMAKE_MSVC_RUNTIME_LIBRARY is set,
255
+ # that will have been used for LLVMSupport so it must also be used here.
256
+ # Otherwise this will use CMake's default runtime library selection, which
257
+ # is either MultiThreadedDLL or MultiThreadedDebugDLL depending on the configuration.
258
+ # They have to match or linking will fail.
257
259
if (GENERATOR_IS_MULTI_CONFIG )
258
260
# We cannot select an ALIAS library because it may be different
259
261
# per configuration. Fallback to CMake's default.
260
262
add_win_flangrt_runtime (STATIC unittest "" EXCLUDE_FROM_ALL )
261
263
else ()
262
- string (TOLOWER ${CMAKE_BUILD_TYPE} build_type )
263
- if (build_type STREQUAL "debug" )
264
- add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg )
265
- else ()
266
- add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic )
267
- endif ()
264
+ # Check if CMAKE_MSVC_RUNTIME_LIBRARY was set.
265
+ if (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreaded" )
266
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.static )
267
+ elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL" )
268
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic )
269
+ elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebug" )
270
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.static_dbg )
271
+ elseif (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDebugDLL" )
272
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg )
273
+ else ()
274
+ # Default based on the build type.
275
+ string (TOLOWER ${CMAKE_BUILD_TYPE} build_type )
276
+ if (build_type STREQUAL "debug" )
277
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic_dbg )
278
+ else ()
279
+ add_library (flang_rt.runtime.unittest ALIAS flang_rt.runtime.dynamic )
280
+ endif ()
281
+ endif ()
268
282
endif ()
269
283
endif ()
0 commit comments