diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2023-12-14 15:59:21 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-16 04:50:40 +0000 |
commit | 8304e2080982b5b174f5de48199e65417309e72e (patch) | |
tree | e58098457e3a243ee1a684e8895bbd80a97995d5 /cmake | |
parent | c662dadd4a1543758f57bcf4a98e270d75b398ba (diff) |
CMake: Export additional target info props for object libraries
For some reason when building a user project in Release mode, when Qt
was built with -DCMAKE_CONFIGURATION_TYPES=RelWithDebInfo;Debug on
MSVC, will result in linking of Debug object libraries into the user
project.
This does not happen in the same configuration on macOS.
My guess is there is a difference in the logic on which configuration
to choose between the platforms, perhaps based on package lookup order
or something else.
This was observed with qtgrpc's
ProtobufWellKnownTypes_type_registration object library (which is only
built on Windows as an object library).
The issue can be fixed if we explicitly generate per-config imported
location information for object libraries, just like we do for regular
libraries.
That way we'll have uniform build type information for all target
types.
Fixes: QTBUG-119708
Change-Id: I9020b7743cea65bbd92cadd5f570b7e38e999bd4
Reviewed-by: 🌴 Alexey Edelev 🌴 <alexey.edelev@qt.io>
(cherry picked from commit 3b71f9dc297f73d140f3c185c67476df5e0266a5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 88662fa7e4b3909eb1037299882c63616a368440)
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtTargetHelpers.cmake | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index c9775ae384..98ac4cc29c 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -808,9 +808,8 @@ endif() endif() # INTERFACE libraries don't have IMPORTED_LOCATION-like properties. - # OBJECT libraries have properties like IMPORTED_OBJECTS instead. # Skip the rest of the processing for those. - if(target_type STREQUAL "INTERFACE_LIBRARY" OR target_type STREQUAL "OBJECT_LIBRARY") + if(target_type STREQUAL "INTERFACE_LIBRARY") continue() endif() @@ -868,6 +867,9 @@ endif()\n") set(write_implib FALSE) set(write_soname FALSE) + set(write_objects FALSE) + set(write_location TRUE) + if(target_type STREQUAL "SHARED_LIBRARY") if(WIN32) set(write_implib TRUE) @@ -876,24 +878,41 @@ endif()\n") else() set(write_soname TRUE) endif() + elseif(target_type STREQUAL "OBJECT_LIBRARY") + set(write_objects TRUE) + set(write_location FALSE) endif() if(NOT "${uc_release_cfg}" STREQUAL "") - string(APPEND content "get_target_property(_qt_imported_location ${full_target} IMPORTED_LOCATION_${uc_release_cfg})\n") + if(write_location) + string(APPEND content "get_target_property(_qt_imported_location ${full_target} IMPORTED_LOCATION_${uc_release_cfg})\n") + endif() if(write_implib) string(APPEND content "get_target_property(_qt_imported_implib ${full_target} IMPORTED_IMPLIB_${uc_release_cfg})\n") endif() if(write_soname) string(APPEND content "get_target_property(_qt_imported_soname ${full_target} IMPORTED_SONAME_${uc_release_cfg})\n") endif() + if(write_objects) + string(APPEND content "get_target_property(_qt_imported_objects ${full_target} IMPORTED_OBJECTS_${uc_release_cfg})\n") + # We generate CLR props as well, because that's what CMake generates for object + # libraries with CMake 3.27. They are usually empty strings though, aka "". + string(APPEND content "get_target_property(_qt_imported_clr ${full_target} IMPORTED_COMMON_LANGUAGE_RUNTIME_${uc_release_cfg})\n") + endif() + endif() + if(write_location) + string(APPEND content "get_target_property(_qt_imported_location_default ${full_target} IMPORTED_LOCATION_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") endif() - string(APPEND content "get_target_property(_qt_imported_location_default ${full_target} IMPORTED_LOCATION_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") if(write_implib) string(APPEND content "get_target_property(_qt_imported_implib_default ${full_target} IMPORTED_IMPLIB_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") endif() if(write_soname) string(APPEND content "get_target_property(_qt_imported_soname_default ${full_target} IMPORTED_SONAME_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") endif() + if(write_objects) + string(APPEND content "get_target_property(_qt_imported_objects_default ${full_target} IMPORTED_OBJECTS_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") + string(APPEND content "get_target_property(_qt_imported_clr_default ${full_target} IMPORTED_COMMON_LANGUAGE_RUNTIME_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n") + endif() foreach(config ${configurations_to_export} "") string(TOUPPER "${config}" ucconfig) if("${config}" STREQUAL "") @@ -908,10 +927,12 @@ endif()\n") set_property(TARGET ${full_target} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${ucconfig}) ") endif() - string(APPEND content " + if(write_location) + string(APPEND content " if(_qt_imported_location${var_suffix}) set_property(TARGET ${full_target} PROPERTY IMPORTED_LOCATION${property_suffix} \"$\{_qt_imported_location${var_suffix}}\") endif()") + endif() if(write_implib) string(APPEND content " if(_qt_imported_implib${var_suffix}) @@ -924,6 +945,16 @@ if(_qt_imported_soname${var_suffix}) set_property(TARGET ${full_target} PROPERTY IMPORTED_SONAME${property_suffix} \"$\{_qt_imported_soname${var_suffix}}\") endif()") endif() + if(write_objects) + string(APPEND content " +if(_qt_imported_objects${var_suffix}) + set_property(TARGET ${full_target} PROPERTY IMPORTED_OBJECTS${property_suffix} \"$\{_qt_imported_objects${var_suffix}}\") +endif()") + string(APPEND content " +if(_qt_imported_clr${var_suffix}) + set_property(TARGET ${full_target} PROPERTY IMPORTED_COMMON_LANGUAGE_RUNTIME${property_suffix} \"$\{_qt_imported_clr${var_suffix}}\") +endif()") + endif() string(APPEND content "\n") endforeach() endforeach() @@ -934,6 +965,10 @@ unset(_qt_imported_location) unset(_qt_imported_location_default) unset(_qt_imported_soname) unset(_qt_imported_soname_default) +unset(_qt_imported_objects) +unset(_qt_imported_objects_default) +unset(_qt_imported_clr) +unset(_qt_imported_clr_default) unset(_qt_imported_configs)") endif() |