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/QtTargetHelpers.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/QtTargetHelpers.cmake')
-rw-r--r-- | cmake/QtTargetHelpers.cmake | 62 |
1 files changed, 62 insertions, 0 deletions
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() |