@@ -17,7 +17,7 @@ if(NOT Corrosion_FOUND)
17
17
endif ()
18
18
19
19
function (cxx_qt_import_crate )
20
- cmake_parse_arguments (IMPORT_CRATE "" "CXX_QT_EXPORT_DIR;QMAKE" "" ${ARGN} )
20
+ cmake_parse_arguments (IMPORT_CRATE "" "CXX_QT_EXPORT_DIR;QMAKE" "QT_MODULES " ${ARGN} )
21
21
22
22
corrosion_import_crate (IMPORTED_CRATES __cxx_qt_imported_crates ${IMPORT_CRATE_UNPARSED_ARGUMENTS} )
23
23
@@ -37,12 +37,27 @@ function(cxx_qt_import_crate)
37
37
endif ()
38
38
endif ()
39
39
40
+ if (NOT DEFINED IMPORT_CRATE_QT_MODULES )
41
+ message (FATAL_ERROR "Missing QT_MODULES argument! You must specify at least one Qt module to link to." )
42
+ else ()
43
+ message (VERBOSE "CXX_QT_QT_MODULES: ${IMPORT_CRATE_QT_MODULES} " )
44
+ endif ()
45
+
40
46
foreach (CRATE ${__cxx_qt_imported_crates} )
47
+ # Join modules by a comma so that we can pass easily via an env variable
48
+ #
49
+ # TODO: can we instead read the module from _qt_config_module_name or
50
+ # _qt_public_module_interface_name of the target, but need to consider
51
+ # private modules too
52
+ list (JOIN IMPORT_CRATE_QT_MODULES "," IMPORT_CRATE_QT_MODULES_STR )
53
+
41
54
corrosion_set_env_vars (${CRATE}
42
55
# Tell cxx-qt-build where to export the data
43
56
"CXX_QT_EXPORT_DIR=${IMPORT_CRATE_CXX_QT_EXPORT_DIR} "
44
57
# Tell cxx-qt-build which crate to export
45
58
"CXX_QT_EXPORT_CRATE_${CRATE} =1"
59
+ # Tell cxx-qt-build which Qt modules we are using
60
+ "CXX_QT_QT_MODULES=${IMPORT_CRATE_QT_MODULES_STR} "
46
61
"QMAKE=${IMPORT_CRATE_QMAKE} "
47
62
$< $< BOOL:${CMAKE_RUSTC_WRAPPER} > :RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER} > )
48
63
@@ -75,6 +90,14 @@ function(cxx_qt_import_crate)
75
90
# See also the "Linking Object Libraries" and "Linking Object Libraries via $<TARGET_OBJECTS>" sections:
76
91
# https://cmake.org/cmake/help/latest/command/target_link_libraries.html
77
92
target_link_libraries (${CRATE} INTERFACE ${CRATE} _initializers $< TARGET_OBJECTS:${CRATE} _initializers> )
93
+
94
+ # Link the static library to Qt
95
+ # Note that we cannot do this on the final CRATE target as this is an interface
96
+ # which depends on the static library. If we do target_link_libraries on the ${CRATE} target,
97
+ # the static library will not actually depend on the Qt modules, but be a kind of "sibling dependency", which CMake may reorder.
98
+ # This can cause CMake to emit the wrong link order, with Qt before the static library, which then fails to build with ld.bfd
99
+ # https://stackoverflow.com/questions/51333069/how-do-the-library-selection-rules-differ-between-gold-and-the-standard-bfd-li
100
+ target_link_libraries (${CRATE} -static INTERFACE ${IMPORT_CRATE_QT_MODULES} )
78
101
endforeach ()
79
102
80
103
endfunction ()
0 commit comments