Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if MSVC Debug build uses wrong runtime #6

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cmake/CxxQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: MIT OR Apache-2.0

option(CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING "Disable checking that the CMAKE_MSVC_RUNTIME_LIBRARY is set when importing Cargo targets in Debug builds with MSVC.")

find_package(Corrosion QUIET)
if(NOT Corrosion_FOUND)
include(FetchContent)
Expand Down Expand Up @@ -43,6 +45,24 @@ function(cxx_qt_import_crate)
message(VERBOSE "CXX_QT_QT_MODULES: ${IMPORT_CRATE_QT_MODULES}")
endif()

if ((NOT CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING)
AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
AND (CMAKE_BUILD_TYPE STREQUAL "Debug")
AND (NOT (CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL "MultiThreadedDLL")))
message(WARNING
" CXX-Qt Warning: CMAKE_MSVC_RUNTIME_LIBRARY not set in MSVC Debug build!\n \n"
" To fix this, set CMAKE_MSVC_RUNTIME_LIBRARY=\"MultiThreadedDLL\" when configuring.\n \n"
" When building with MSVC in Debug, the CMAKE_MSVC_RUNTIME_LIBRARY variable should be set to \"MultiThreadedDLL\"\n"
" This needs to be done before configuring any target that links to a Rust target.\n"
" Otherwise, you may encounter linker errors when linking to Rust targets, like:\n \n"
" error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in ...\n \n"
" See also:\n"
" 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"
" and: https://github.com/KDAB/cxx-qt/pull/683\n \n"
" To suppress this warning set CXX_QT_SUPPRESS_MSVC_RUNTIME_WARNING to ON"
)
endif()

foreach(CRATE ${__cxx_qt_imported_crates})
# Join modules by a comma so that we can pass easily via an env variable
#
Expand Down