diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-09-29 22:07:33 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-10-06 10:07:02 +0200 |
commit | e6fd92816dcbddcd9c28676815cf134b31291ea9 (patch) | |
tree | 415a1d6759b451c3ce58b5bebb8e0e4185f84f96 /cmake | |
parent | 00807f1fe5a20f5c23fbac104212c4a983837db9 (diff) |
CMake: Install PDB debug info for MSVC builds
Supports installing linker generated debug info for shared libraries
and executables, as well as compiler generated debug info for static
libraries.
Works with Ninja Multi-Config as well, with the caveat that the files
are installed optionally, aka the install rule will not error out if
a pdb file is not present. This is necessary, because it's not
possible to create per-config install rules properly.
Fixes: QTBUG-87006
Change-Id: I95e91a6557eb0ee0f882103be54cd38795c349f7
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/Qt3rdPartyLibraryHelpers.cmake | 1 | ||||
-rw-r--r-- | cmake/QtModuleHelpers.cmake | 6 | ||||
-rw-r--r-- | cmake/QtPluginHelpers.cmake | 1 | ||||
-rw-r--r-- | cmake/QtTargetHelpers.cmake | 62 | ||||
-rw-r--r-- | cmake/QtToolHelpers.cmake | 1 |
5 files changed, 71 insertions, 0 deletions
diff --git a/cmake/Qt3rdPartyLibraryHelpers.cmake b/cmake/Qt3rdPartyLibraryHelpers.cmake index 41c4ad6fa7..9944d47daf 100644 --- a/cmake/Qt3rdPartyLibraryHelpers.cmake +++ b/cmake/Qt3rdPartyLibraryHelpers.cmake @@ -244,6 +244,7 @@ function(qt_internal_add_3rdparty_library target) CONFIG_INSTALL_DIR "${config_install_dir}" ) endif() + qt_internal_install_pdb_files("${target}" "${INSTALL_LIBDIR}") endfunction() function(qt_install_3rdparty_library_wrap_config_extra_file target) diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index c9ef2397a9..dfafa7eec9 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -589,6 +589,12 @@ set(QT_CMAKE_EXPORT_NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE})") qt_finalize_framework_headers_copy(${target}) endif() + set(pdb_install_dir "${INSTALL_BINDIR}") + if(NOT is_shared_lib) + set(pdb_install_dir "${INSTALL_LIBDIR}") + endif() + qt_internal_install_pdb_files(${target} "${pdb_install_dir}") + qt_describe_module(${target}) qt_add_list_file_finalizer(qt_finalize_module ${target} ${arg_INTERNAL_MODULE} ${header_module}) endfunction() diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index f00fcbd2a6..691735afe4 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -267,6 +267,7 @@ function(qt_internal_add_plugin target) qt_internal_add_linker_version_script(${target}) qt_add_list_file_finalizer(qt_finalize_plugin ${target} "${install_directory}") + qt_internal_install_pdb_files(${target} "${install_directory}") endfunction() function(qt_finalize_plugin target install_directory) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index d542eaafb8..bbcd768495 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -191,6 +191,7 @@ function(qt_set_common_target_properties target) target_link_options(${target} INTERFACE "LINKER:-static") endif() endif() + qt_internal_set_compile_pdb_names("${target}") endfunction() # Set common, informational target properties. @@ -479,3 +480,64 @@ function(qt_internal_create_tracepoints name tracepoints_file) qt_configure_file(OUTPUT "${header_path}" CONTENT "#include <private/qtrace_p.h>\n") endif() endfunction() + +function(qt_internal_set_compile_pdb_names target) + if(MSVC) + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL "STATIC_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() + endif() +endfunction() + +# Installs pdb files for given target into the specified install dir. +# +# MSVC generates 2 types of pdb files: +# - compile-time generated pdb files (compile flag /Zi + /Fd<pdb_name>) +# - link-time genereated pdb files (link flag /debug + /PDB:<pdb_name>) +# +# CMake allows changing the names of each of those pdb file types by setting +# the COMPILE_PDB_NAME_<CONFIG> and PDB_NAME_<CONFIG> properties. If they are +# left empty, CMake will compute the default names itself (or rather in certain cases +# leave it up to te compiler), without actually setting the property values. +# +# For installation purposes, CMake only provides a generator expression to the +# link time pdb file path, not the compile path one, which means we have to compute the +# path to the compile path pdb files ourselves. +# See https://gitlab.kitware.com/cmake/cmake/-/issues/18393 for details. +# +# For shared libraries and executables, we install the linker provided pdb file via the +# TARGET_PDB_FILE generator expression. +# +# For static libraries there is no linker invocation, so we need to install the compile +# time pdb file. We query the ARCHIVE_OUTPUT_DIRECTORY property of the target to get the +# path to the pdb file, and reconstruct the file name. We use a generator expression +# to append a possible debug suffix, in order to allow installation of all Release and +# Debug pdb files when using Ninja Multi-Config. +function(qt_internal_install_pdb_files target install_dir_path) + if(MSVC) + get_target_property(target_type ${target} TYPE) + + if(target_type STREQUAL "SHARED_LIBRARY" + OR target_type STREQUAL "EXECUTABLE" + OR target_type STREQUAL "MODULE_LIBRARY") + qt_install(FILES "$<TARGET_PDB_FILE:${target}>" + DESTINATION "${install_dir_path}" + OPTIONAL) + + elseif(target_type STREQUAL "STATIC_LIBRARY") + get_target_property(lib_dir "${target}" ARCHIVE_OUTPUT_DIRECTORY) + if(NOT lib_dir) + message(FATAL_ERROR + "Can't install pdb file for static library ${target}. " + "The ARCHIVE_OUTPUT_DIRECTORY path is not known.") + endif() + set(pdb_name "${INSTALL_CMAKE_NAMESPACE}${target}$<$<CONFIG:Debug>:d>.pdb") + qt_path_join(compile_time_pdb_file_path "${lib_dir}" "${pdb_name}") + + qt_install(FILES "${compile_time_pdb_file_path}" + DESTINATION "${install_dir_path}" OPTIONAL) + endif() + endif() +endfunction() diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index ac5412461d..5a812a3a45 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -197,6 +197,7 @@ function(qt_internal_add_tool target_name) if(QT_FEATURE_separate_debug_info AND (UNIX OR MINGW)) qt_enable_separate_debug_info(${target_name} ${INSTALL_BINDIR}) endif() + qt_internal_install_pdb_files(${target_name} "${INSTALL_BINDIR}") endfunction() function(qt_export_tools module_name) |