cmake build: Create DebugInfo component with separate debug info

When building with RelWithDebInfo. The CMake code is adapted from
corresponding (internal) functions from Qt 6.
Also let the scripts create an additional *-debug.7z with the debug
info.

Task-number: QTCREATORBUG-24916
Change-Id: Ibc3c8c0013718b9c5e868136e5ce01e1e99f84c4
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Eike Ziller
2020-11-12 11:27:34 +01:00
parent 8f4532daae
commit eb4d230e38
6 changed files with 214 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ set(QT_CREATOR_API_DEFINED TRUE)
set(IDE_QT_VERSION_MIN "5.14.0") set(IDE_QT_VERSION_MIN "5.14.0")
include(${CMAKE_CURRENT_LIST_DIR}/QtCreatorAPIInternal.cmake) include(${CMAKE_CURRENT_LIST_DIR}/QtCreatorAPIInternal.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/QtcSeparateDebugInfo.cmake)
set(IDE_APP_PATH "${_IDE_APP_PATH}") # The target path of the IDE application (relative to CMAKE_INSTALL_PREFIX). set(IDE_APP_PATH "${_IDE_APP_PATH}") # The target path of the IDE application (relative to CMAKE_INSTALL_PREFIX).
set(IDE_APP_TARGET "${_IDE_APP_TARGET}") # The IDE application name. set(IDE_APP_TARGET "${_IDE_APP_TARGET}") # The IDE application name.
@@ -241,6 +242,8 @@ function(add_qtc_library name)
OPTIONAL OPTIONAL
) )
qtc_enable_separate_debug_info(${name} "${IDE_LIBRARY_PATH}")
if (library_type STREQUAL "SHARED") if (library_type STREQUAL "SHARED")
set(target_prefix ${CMAKE_SHARED_LIBRARY_PREFIX}) set(target_prefix ${CMAKE_SHARED_LIBRARY_PREFIX})
if (WIN32) if (WIN32)
@@ -483,6 +486,8 @@ function(add_qtc_plugin target_name)
OPTIONAL OPTIONAL
) )
qtc_enable_separate_debug_info(${target_name} "${plugin_dir}")
if (_arg_EXPORT) if (_arg_EXPORT)
# export of external plugins # export of external plugins
install(EXPORT ${export} install(EXPORT ${export}
@@ -714,6 +719,8 @@ function(add_qtc_executable name)
) )
endif() endif()
qtc_enable_separate_debug_info(${name} "${_DESTINATION}")
update_cached_list(__QTC_INSTALLED_EXECUTABLES update_cached_list(__QTC_INSTALLED_EXECUTABLES
"${_DESTINATION}/${name}${CMAKE_EXECUTABLE_SUFFIX}") "${_DESTINATION}/${name}${CMAKE_EXECUTABLE_SUFFIX}")

View File

@@ -0,0 +1,16 @@
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.${BUNDLE_ID}</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}</string>
<key>CFBundleVersion</key>
<string>${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}</string>
</dict>
</plist>

View File

@@ -0,0 +1,159 @@
if(CMAKE_VERSION VERSION_LESS 3.17.0)
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
endif()
# Enable separate debug information for the given target
# when doing RelWithDebInfo build
function(qtc_enable_separate_debug_info target installDestination)
if (NOT CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
return()
endif()
if (NOT UNIX AND NOT MINGW)
qtc_internal_install_pdb_files(${target} ${installDestination})
return()
endif()
get_target_property(target_type ${target} TYPE)
if (NOT target_type STREQUAL "MODULE_LIBRARY" AND
NOT target_type STREQUAL "SHARED_LIBRARY" AND
NOT target_type STREQUAL "EXECUTABLE")
return()
endif()
get_property(target_source_dir TARGET ${target} PROPERTY SOURCE_DIR)
get_property(skip_separate_debug_info DIRECTORY "${target_source_dir}" PROPERTY _qt_skip_separate_debug_info)
if (skip_separate_debug_info)
return()
endif()
unset(commands)
if(APPLE)
find_program(DSYMUTIL_PROGRAM dsymutil)
set(copy_bin ${DSYMUTIL_PROGRAM})
set(strip_bin ${CMAKE_STRIP})
set(debug_info_suffix dSYM)
set(copy_bin_out_arg --flat -o)
set(strip_args -S)
else()
set(copy_bin ${CMAKE_OBJCOPY})
set(strip_bin ${CMAKE_OBJCOPY})
if(QNX)
set(debug_info_suffix sym)
set(debug_info_keep --keep-file-symbols)
set(strip_args "--strip-debug -R.ident")
else()
set(debug_info_suffix debug)
set(debug_info_keep --only-keep-debug)
set(strip_args --strip-debug)
endif()
endif()
if(APPLE)
get_target_property(is_framework ${target} FRAMEWORK)
if(is_framework)
set(debug_info_bundle_dir "$<TARGET_BUNDLE_DIR:${target}>.${debug_info_suffix}")
set(BUNDLE_ID Qt${target})
else()
set(debug_info_bundle_dir "$<TARGET_FILE:${target}>.${debug_info_suffix}")
set(BUNDLE_ID ${target})
endif()
set(debug_info_contents_dir "${debug_info_bundle_dir}/Contents")
set(debug_info_target_dir "${debug_info_contents_dir}/Resources/DWARF")
configure_file(
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/QtcSeparateDebugInfo.Info.plist.in"
"Info.dSYM.plist"
)
list(APPEND commands
COMMAND ${CMAKE_COMMAND} -E make_directory ${debug_info_target_dir}
COMMAND ${CMAKE_COMMAND} -E copy "Info.dSYM.plist" "${debug_info_contents_dir}/Info.plist"
)
set(debug_info_target "${debug_info_target_dir}/$<TARGET_FILE_BASE_NAME:${target}>")
install(DIRECTORY ${debug_info_bundle_dir}
DESTINATION ${installDestination}
COMPONENT DebugInfo
EXCLUDE_FROM_ALL
)
else()
set(debug_info_target "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${debug_info_suffix}")
install(FILES ${debug_info_target}
DESTINATION ${installDestination}
COMPONENT DebugInfo
EXCLUDE_FROM_ALL
)
endif()
list(APPEND commands
COMMAND ${copy_bin} ${debug_info_keep} $<TARGET_FILE:${target}>
${copy_bin_out_arg} ${debug_info_target}
COMMAND ${strip_bin} ${strip_args} $<TARGET_FILE:${target}>
)
if(NOT APPLE)
list(APPEND commands
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${debug_info_target} $<TARGET_FILE:${target}>
)
endif()
if(NOT CMAKE_HOST_WIN32)
list(APPEND commands
COMMAND chmod -x ${debug_info_target}
)
endif()
add_custom_command(
TARGET ${target}
POST_BUILD
${commands}
)
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(qtc_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")
install(FILES "$<TARGET_PDB_FILE:${target}>"
DESTINATION "${install_dir_path}"
OPTIONAL
COMPONENT DebugInfo
EXCLUDE_FROM_ALL
)
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")
set(compile_time_pdb_file_path "${lib_dir}/${pdb_name}")
install(FILES "${compile_time_pdb_file_path}"
DESTINATION "${install_dir_path}"
OPTIONAL
COMPONENT DebugInfo
EXCLUDE_FROM_ALL
)
endif()
endif()
endfunction()

View File

@@ -103,7 +103,9 @@ def get_arguments():
action='append', dest='config_args', default=[]) action='append', dest='config_args', default=[])
parser.add_argument('--zip-infix', help='Adds an infix to generated zip files, use e.g. for a build number.', parser.add_argument('--zip-infix', help='Adds an infix to generated zip files, use e.g. for a build number.',
default='') default='')
return parser.parse_args() args = parser.parse_args()
args.with_debug_info = args.build_type == 'RelWithDebInfo'
return args
def build_qtcreator(args, paths): def build_qtcreator(args, paths):
if not os.path.exists(paths.build): if not os.path.exists(paths.build):
@@ -175,6 +177,10 @@ def build_qtcreator(args, paths):
common.check_print_call(['cmake', '--install', '.', '--prefix', paths.dev_install, common.check_print_call(['cmake', '--install', '.', '--prefix', paths.dev_install,
'--component', 'Devel'], '--component', 'Devel'],
paths.build) paths.build)
if args.with_debug_info:
common.check_print_call(['cmake', '--install', '.', '--prefix', paths.debug_install,
'--component', 'DebugInfo'],
paths.build)
if not args.no_docs: if not args.no_docs:
common.check_print_call(['cmake', '--install', '.', '--prefix', paths.install, common.check_print_call(['cmake', '--install', '.', '--prefix', paths.install,
'--component', 'qch_docs'], '--component', 'qch_docs'],
@@ -245,6 +251,11 @@ def package_qtcreator(args, paths):
os.path.join(paths.result, 'qtcreator' + args.zip_infix + '_dev.7z'), os.path.join(paths.result, 'qtcreator' + args.zip_infix + '_dev.7z'),
'*'], '*'],
paths.dev_install) paths.dev_install)
if args.with_debug_info:
common.check_print_call(['7z', 'a', '-mmt2',
os.path.join(paths.result, 'qtcreator' + args.zip_infix + '-debug.7z'),
'*'],
paths.debug_install)
if common.is_windows_platform(): if common.is_windows_platform():
common.check_print_call(['7z', 'a', '-mmt2', common.check_print_call(['7z', 'a', '-mmt2',
os.path.join(paths.result, 'wininterrupt' + args.zip_infix + '.7z'), os.path.join(paths.result, 'wininterrupt' + args.zip_infix + '.7z'),
@@ -271,8 +282,8 @@ def package_qtcreator(args, paths):
def get_paths(args): def get_paths(args):
Paths = collections.namedtuple('Paths', Paths = collections.namedtuple('Paths',
['qt', 'src', 'build', ['qt', 'src', 'build',
'install', 'dev_install', 'wininterrupt_install', 'install', 'dev_install', 'debug_install',
'qtcreatorcdbext_install', 'result', 'wininterrupt_install', 'qtcreatorcdbext_install', 'result',
'elfutils', 'llvm']) 'elfutils', 'llvm'])
build_path = os.path.abspath(args.build) build_path = os.path.abspath(args.build)
install_path = os.path.join(build_path, 'install') install_path = os.path.join(build_path, 'install')
@@ -281,6 +292,7 @@ def get_paths(args):
build=os.path.join(build_path, 'build'), build=os.path.join(build_path, 'build'),
install=os.path.join(install_path, 'qt-creator'), install=os.path.join(install_path, 'qt-creator'),
dev_install=os.path.join(install_path, 'qt-creator-dev'), dev_install=os.path.join(install_path, 'qt-creator-dev'),
debug_install=os.path.join(install_path, 'qt-creator-debug'),
wininterrupt_install=os.path.join(install_path, 'wininterrupt'), wininterrupt_install=os.path.join(install_path, 'wininterrupt'),
qtcreatorcdbext_install=os.path.join(install_path, 'qtcreatorcdbext'), qtcreatorcdbext_install=os.path.join(install_path, 'qtcreatorcdbext'),
result=build_path, result=build_path,

View File

@@ -59,7 +59,9 @@ def get_arguments():
action='store_true', default=False) action='store_true', default=False)
parser.add_argument('--build-type', help='Build type to pass to CMake (defaults to RelWithDebInfo)', parser.add_argument('--build-type', help='Build type to pass to CMake (defaults to RelWithDebInfo)',
default='RelWithDebInfo') default='RelWithDebInfo')
return parser.parse_args() args = parser.parse_args()
args.with_debug_info = args.build_type == 'RelWithDebInfo'
return args
def build(args, paths): def build(args, paths):
if not os.path.exists(paths.build): if not os.path.exists(paths.build):
@@ -117,6 +119,10 @@ def build(args, paths):
common.check_print_call(['cmake', '--install', '.', '--prefix', paths.dev_install, common.check_print_call(['cmake', '--install', '.', '--prefix', paths.dev_install,
'--component', 'Devel'], '--component', 'Devel'],
paths.build) paths.build)
if args.with_debug_info:
common.check_print_call(['cmake', '--install', '.', '--prefix', paths.debug_install,
'--component', 'DebugInfo'],
paths.build)
def package(args, paths): def package(args, paths):
if not os.path.exists(paths.result): if not os.path.exists(paths.result):
@@ -127,11 +133,15 @@ def package(args, paths):
common.check_print_call(['7z', 'a', '-mmt2', common.check_print_call(['7z', 'a', '-mmt2',
os.path.join(paths.result, args.name + '_dev.7z'), '*'], os.path.join(paths.result, args.name + '_dev.7z'), '*'],
paths.dev_install) paths.dev_install)
if args.with_debug_info:
common.check_print_call(['7z', 'a', '-mmt2',
os.path.join(paths.result, args.name + '-debug.7z'), '*'],
paths.debug_install)
def get_paths(args): def get_paths(args):
Paths = collections.namedtuple('Paths', Paths = collections.namedtuple('Paths',
['qt', 'src', 'build', 'qt_creator', ['qt', 'src', 'build', 'qt_creator',
'install', 'dev_install', 'result']) 'install', 'dev_install', 'debug_install', 'result'])
build_path = os.path.abspath(args.build) build_path = os.path.abspath(args.build)
install_path = os.path.join(build_path, 'install') install_path = os.path.join(build_path, 'install')
result_path = os.path.abspath(args.output_path) if args.output_path else build_path result_path = os.path.abspath(args.output_path) if args.output_path else build_path
@@ -141,6 +151,7 @@ def get_paths(args):
qt_creator=os.path.abspath(args.qtc_path), qt_creator=os.path.abspath(args.qtc_path),
install=os.path.join(install_path, args.name), install=os.path.join(install_path, args.name),
dev_install=os.path.join(install_path, args.name + '-dev'), dev_install=os.path.join(install_path, args.name + '-dev'),
debug_install=os.path.join(install_path, args.name + '-debug'),
result=result_path) result=result_path)
def main(): def main():

View File

@@ -78,6 +78,8 @@ file(COPY
${PROJECT_SOURCE_DIR}/cmake/QtCreatorAPIInternal.cmake ${PROJECT_SOURCE_DIR}/cmake/QtCreatorAPIInternal.cmake
${PROJECT_SOURCE_DIR}/cmake/FindQt5.cmake ${PROJECT_SOURCE_DIR}/cmake/FindQt5.cmake
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${PROJECT_SOURCE_DIR}/cmake/QtcSeparateDebugInfo.cmake
${PROJECT_SOURCE_DIR}/cmake/QtcSeparateDebugInfo.Info.plist.in
DESTINATION ${CMAKE_BINARY_DIR}/cmake DESTINATION ${CMAKE_BINARY_DIR}/cmake
) )
@@ -91,6 +93,8 @@ install(
${PROJECT_SOURCE_DIR}/cmake/QtCreatorAPIInternal.cmake ${PROJECT_SOURCE_DIR}/cmake/QtCreatorAPIInternal.cmake
${PROJECT_SOURCE_DIR}/cmake/FindQt5.cmake ${PROJECT_SOURCE_DIR}/cmake/FindQt5.cmake
${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in
${PROJECT_SOURCE_DIR}/cmake/QtcSeparateDebugInfo.cmake
${PROJECT_SOURCE_DIR}/cmake/QtcSeparateDebugInfo.Info.plist.in
${CMAKE_BINARY_DIR}/cmake/QtCreatorConfig.cmake ${CMAKE_BINARY_DIR}/cmake/QtCreatorConfig.cmake
DESTINATION lib/cmake/QtCreator DESTINATION lib/cmake/QtCreator
COMPONENT Devel EXCLUDE_FROM_ALL COMPONENT Devel EXCLUDE_FROM_ALL