Install MSVC debug information for resource object libraries

Building against a static debug MSVC Qt produced LNK4099 warnings (PDB
was not found with object file).

This was because we did not install the .pdb files for the object
libraries that are created for Qt resources.  Now, these .pdb files are
named like the object library targets and are installed next to the
object files.

Fixes: QTBUG-97699
Change-Id: I7e23f8392b7ac657be1d2fb3b33e051ae2e4d407
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 75eb08711ef7a51305b4daad411548a2b6b4f8c6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Joerg Bornemann 2021-11-29 21:18:43 +01:00 committed by Qt Cherry-pick Bot
parent 4e669763bd
commit 67a9a9fb67
2 changed files with 32 additions and 1 deletions

View File

@ -26,6 +26,7 @@ function(qt_internal_add_resource target resourceName)
EXPORT_NAME_PREFIX "${INSTALL_CMAKE_NAMESPACE}${target}"
)
qt_internal_install_resource_pdb_files("${out_targets}")
qt_internal_record_rcc_object_files("${target}" "${out_targets}"
INSTALL_DIRECTORY "${INSTALL_LIBDIR}")
endif()
@ -90,3 +91,20 @@ function(qt_internal_record_rcc_object_files target resource_targets)
qt_internal_link_internal_platform_for_object_library("${out_target}")
endforeach()
endfunction()
function(qt_internal_install_resource_pdb_files objlib_targets)
if(NOT MSVC OR NOT QT_WILL_INSTALL)
return()
endif()
foreach(target IN LISTS objlib_targets)
qt_internal_set_compile_pdb_names(${target})
get_target_property(generated_cpp_file_relative_path
${target}
_qt_resource_generated_cpp_relative_path)
get_filename_component(rel_obj_file_dir "${generated_cpp_file_relative_path}" DIRECTORY)
qt_internal_install_pdb_files(${target}
"${INSTALL_LIBDIR}/objects-$<CONFIG>/${target}/${rel_obj_file_dir}")
endforeach()
endfunction()

View File

@ -640,7 +640,7 @@ endfunction()
function(qt_internal_set_compile_pdb_names target)
if(MSVC)
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "STATIC_LIBRARY")
if(target_type STREQUAL "STATIC_LIBRARY" OR target_type STREQUAL "OBJECT_LIBRARY")
set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME "${INSTALL_CMAKE_NAMESPACE}${target}")
set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME_DEBUG "${INSTALL_CMAKE_NAMESPACE}${target}d")
endif()
@ -708,6 +708,19 @@ function(qt_internal_install_pdb_files target install_dir_path)
qt_install(FILES "${compile_time_pdb_file_path}"
DESTINATION "${install_dir_path}" OPTIONAL)
elseif(target_type STREQUAL "OBJECT_LIBRARY")
get_target_property(pdb_dir "${target}" COMPILE_PDB_OUTPUT_DIRECTORY)
if(NOT pdb_dir)
get_target_property(pdb_dir "${target}" BINARY_DIR)
if(QT_GENERATOR_IS_MULTI_CONFIG)
qt_path_join(pdb_dir "${pdb_dir}" "$<CONFIG>")
endif()
endif()
set(pdb_name "${INSTALL_CMAKE_NAMESPACE}${target}$<$<CONFIG:Debug>:d>.pdb")
qt_path_join(compile_time_pdb_file_path "${pdb_dir}" "${pdb_name}")
qt_install(FILES "${compile_time_pdb_file_path}"
DESTINATION "${install_dir_path}" OPTIONAL)
endif()
endif()
endfunction()