Skip to content

Commit e086355

Browse files
committed
cmake: set MSVC_RUNTIME_LIBRARY to MultiThreadedDLL
As Rust always uses the non-debug Windows runtime for MSVC targets. Related to KDAB#682 Related to KDAB#676
1 parent 918665c commit e086355

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

examples/demo_threading/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ corrosion_set_env_vars(${CRATE}
4242
)
4343

4444
add_library(${APP_NAME}_lib INTERFACE)
45+
46+
# Rust always links against non-debug Windows runtime on *-msvc targets
47+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
48+
# https://github.com/rust-lang/rust/issues/39016
49+
set_target_properties(${APP_NAME}_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
50+
4551
target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
4652
target_link_libraries(${APP_NAME}_lib INTERFACE
4753
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>"

examples/qml_features/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ corrosion_set_env_vars(${CRATE}
4242
"QMAKE=${QMAKE}"
4343
)
4444
add_library(${APP_NAME}_lib INTERFACE)
45+
46+
# Rust always links against non-debug Windows runtime on *-msvc targets
47+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
48+
# https://github.com/rust-lang/rust/issues/39016
49+
set_target_properties(${APP_NAME}_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
50+
4551
target_include_directories(${APP_NAME}_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
4652
target_link_libraries(${APP_NAME}_lib INTERFACE
4753
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>"

examples/qml_minimal/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ corrosion_set_env_vars(${CRATE}
6464
# the include paths and linked libraries for both of those.
6565
add_library(${APP_NAME}_lib INTERFACE)
6666

67+
# Rust always links against non-debug Windows runtime on *-msvc targets
68+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
69+
# https://github.com/rust-lang/rust/issues/39016
70+
set_target_properties(${APP_NAME}_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
71+
6772
# Include the headers generated by the Rust library's build script. Each
6873
# crate gets its own subdirectory under CXXQT_EXPORT_DIR. This allows you
6974
# to include headers generated by multiple crates without risk of one crate

tests/basic_cxx_only/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ corrosion_set_env_vars(${CRATE}
3131
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3232
"QMAKE=${QMAKE}"
3333
)
34-
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
35-
target_link_libraries(${CRATE} INTERFACE
34+
add_library(basic-cxx-only_lib INTERFACE)
35+
36+
# Rust always links against non-debug Windows runtime on *-msvc targets
37+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
38+
# https://github.com/rust-lang/rust/issues/39016
39+
set_target_properties(basic-cxx-only_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
40+
41+
target_include_directories(basic-cxx-only_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
42+
target_link_libraries(basic-cxx-only_lib INTERFACE
43+
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>"
3644
Qt::Core
3745
Qt::Gui
3846
Qt::Qml
@@ -44,6 +52,6 @@ add_executable(${APP_NAME}
4452
)
4553
target_include_directories(${APP_NAME} PRIVATE cpp)
4654
target_link_libraries(${APP_NAME} PRIVATE
47-
${CRATE}
55+
basic-cxx-only_lib
4856
Qt::Test
4957
)

tests/basic_cxx_qt/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,23 @@ corrosion_set_env_vars(${CRATE}
3030
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3131
"QMAKE=${QMAKE}"
3232
)
33-
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
34-
target_link_libraries(${CRATE} INTERFACE
33+
add_library(basic-cxx-qt_lib INTERFACE)
34+
35+
# Rust always links against non-debug Windows runtime on *-msvc targets
36+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
37+
# https://github.com/rust-lang/rust/issues/39016
38+
set_target_properties(basic-cxx-qt_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
39+
40+
target_include_directories(basic-cxx-qt_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
41+
target_link_libraries(basic-cxx-qt_lib INTERFACE
42+
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>"
3543
Qt::Core
3644
Qt::Gui
3745
Qt::Qml
3846
)
3947

4048
add_executable(${APP_NAME} cpp/main.cpp)
4149
target_link_libraries(${APP_NAME} PRIVATE
42-
${CRATE}
50+
basic-cxx-qt_lib
4351
Qt::Test
4452
)

tests/qt_types_standalone/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ corrosion_set_env_vars(${CRATE}
3131
"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}"
3232
"QMAKE=${QMAKE}"
3333
)
34+
add_library(qt-types-standalone_lib INTERFACE)
35+
36+
# Rust always links against non-debug Windows runtime on *-msvc targets
37+
# https://github.com/corrosion-rs/corrosion/blob/master/doc/src/common_issues.md#linking-debug-cc-libraries-into-rust-fails-on-windows-msvc-targets
38+
# https://github.com/rust-lang/rust/issues/39016
39+
set_target_properties(qt-types-standalone_lib PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
40+
41+
target_include_directories(qt-types-standalone_lib INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
42+
target_link_libraries(qt-types-standalone_lib INTERFACE
43+
"$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>"
44+
Qt::Core
45+
Qt::Gui
46+
Qt::Qml
47+
)
48+
3449
target_include_directories(${CRATE} INTERFACE "${CXXQT_EXPORT_DIR}/${CRATE}")
3550
target_link_libraries(${CRATE} INTERFACE
3651
Qt::Core
@@ -77,6 +92,6 @@ add_executable(${APP_NAME}
7792
target_include_directories(${APP_NAME} PRIVATE cpp)
7893

7994
target_link_libraries(${APP_NAME} PRIVATE
80-
${CRATE}
95+
qt-types-standalone_lib
8196
Qt::Test
8297
)

0 commit comments

Comments
 (0)