Skip to content

Commit 088c5a5

Browse files
Revert "Add support for the debug runtime in MSVC builds."
This reverts commit 0f25fd0. It turned out that in my testing I was still setting the runtime to release mode, which ended up linking the Debug runtime to code that was built for the release runtime. This surpisingly worked out, but is not a great solution in the end
1 parent 0f25fd0 commit 088c5a5

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

cmake/CxxQt.cmake

+18-26
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ function(cxx_qt_import_crate)
4545
message(VERBOSE "CXX_QT_QT_MODULES: ${IMPORT_CRATE_QT_MODULES}")
4646
endif()
4747

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+
4866
foreach(CRATE ${__cxx_qt_imported_crates})
4967
# Join modules by a comma so that we can pass easily via an env variable
5068
#
@@ -110,34 +128,8 @@ function(cxx_qt_import_crate)
110128
# This can cause CMake to emit the wrong link order, with Qt before the static library, which then fails to build with ld.bfd
111129
# https://stackoverflow.com/questions/51333069/how-do-the-library-selection-rules-differ-between-gold-and-the-standard-bfd-li
112130
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()
124131
endforeach()
125132

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-
141133
endfunction()
142134

143135

0 commit comments

Comments
 (0)