@@ -45,24 +45,6 @@ function(cxx_qt_import_crate)
45
45
message (VERBOSE "CXX_QT_QT_MODULES: ${IMPORT_CRATE_QT_MODULES} " )
46
46
endif ()
47
47
48
- if ((NOT CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING)
49
- AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
50
- AND (CMAKE_BUILD_TYPE STREQUAL "Debug" )
51
- AND (NOT (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL" )))
52
- message (WARNING
53
- " CXX-Qt Warning: CMAKE_MSVC_RUNTIME_LIBRARY not set in MSVC Debug build!\n \n "
54
- " To fix this, set CMAKE_MSVC_RUNTIME_LIBRARY=\" MultiThreadedDLL\" when configuring.\n \n "
55
- " When building with MSVC in Debug, the CMAKE_MSVC_RUNTIME_LIBRARY variable should be set to \" MultiThreadedDLL\"\n "
56
- " This needs to be done before configuring any target that links to a Rust target.\n "
57
- " Otherwise, you may encounter linker errors when linking to Rust targets, like:\n \n "
58
- " error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in ...\n \n "
59
- " See also:\n "
60
- " https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets\n "
61
- " and: https://github.com/KDAB/cxx-qt/pull/683\n \n "
62
- " To suppress this warning set CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING to ON"
63
- )
64
- endif ()
65
-
66
48
foreach (CRATE ${__cxx_qt_imported_crates} )
67
49
# Join modules by a comma so that we can pass easily via an env variable
68
50
#
@@ -128,8 +110,34 @@ function(cxx_qt_import_crate)
128
110
# This can cause CMake to emit the wrong link order, with Qt before the static library, which then fails to build with ld.bfd
129
111
# https://stackoverflow.com/questions/51333069/how-do-the-library-selection-rules-differ-between-gold-and-the-standard-bfd-li
130
112
target_link_libraries (${CRATE} -static INTERFACE ${IMPORT_CRATE_QT_MODULES} )
113
+
114
+ if ((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
115
+ AND (CMAKE_BUILD_TYPE STREQUAL "Debug" )
116
+ AND (NOT (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL" )))
117
+ # MSVC(Debug): Tell the linker not to link to the MultiThreadedDLL runtime and use the Debug version instead
118
+ # This is a new workaround for this issue:
119
+ # https://corrosion-rs.github.io/corrosion/common_issues.html#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
120
+ # As outlined in this comment:
121
+ # https://github.com/rust-lang/rust/issues/39016#issuecomment-2521395154
122
+ target_link_options (${CRATE} -static INTERFACE /NODEFAULTLIB:msvcrt /DEFAULTLIB:msvcrtd)
123
+ endif ()
131
124
endforeach ()
132
125
126
+ if ((NOT CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING)
127
+ AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
128
+ AND (CMAKE_BUILD_TYPE STREQUAL "Debug" )
129
+ AND (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL" ))
130
+ message (WARNING
131
+ " CXX-Qt Warning: CMAKE_MSVC_RUNTIME_LIBRARY should no longer be set in MSVC Debug build!\n \n "
132
+ " In previous versions of CXX-Qt it was necessary to set CMAKE_MSVC_RUNTIME_LIBRARY=\" MultiThreadedDLL\" .\n "
133
+ " Starting with CXX-Qt 0.7.2, this has been fixed and is no longer necessary or recommended.\n \n "
134
+
135
+ " See also:\n "
136
+ " https://github.com/KDAB/cxx-qt/issues/1234\n \n "
137
+ " To suppress this warning set CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING to ON"
138
+ )
139
+ endif ()
140
+
133
141
endfunction ()
134
142
135
143
0 commit comments