CMake: Port the 'separate_debug_info' feature

For this, we have to uninline the separate_debug_info configure test,
because supporting the conversion of this in configurejson2cmake is not
worth the hassle.

Separate debug information can be turned on for a target by calling the
function qt_enable_separate_debug_info. For Qt's shared libraries and
tools separate debug information is generated if the
'separate_debug_info' feature is manually turned on.

Change-Id: Ic2ffc15efef3794dc0aa42f3d853ef6d651a751c
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2020-02-26 11:41:20 +01:00
parent a3d0ef019a
commit d0911d0a92
10 changed files with 129 additions and 13 deletions

View File

@ -234,6 +234,8 @@ qt_copy_or_install(FILES
cmake/QtPlatformSupport.cmake cmake/QtPlatformSupport.cmake
cmake/QtPlatformAndroid.cmake cmake/QtPlatformAndroid.cmake
cmake/QtPostProcess.cmake cmake/QtPostProcess.cmake
cmake/QtSeparateDebugInfo.Info.plist.in
cmake/QtSeparateDebugInfo.cmake
cmake/QtSetup.cmake cmake/QtSetup.cmake
cmake/QtModuleConfig.cmake.in cmake/QtModuleConfig.cmake.in
cmake/QtModuleDependencies.cmake.in cmake/QtModuleDependencies.cmake.in

View File

@ -1,4 +1,5 @@
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
include(QtSeparateDebugInfo)
# Install locations: # Install locations:
set(INSTALL_BINDIR "bin" CACHE STRING "Executables [PREFIX/bin]") set(INSTALL_BINDIR "bin" CACHE STRING "Executables [PREFIX/bin]")
@ -1611,6 +1612,10 @@ function(qt_add_module target)
endif() endif()
endif() endif()
if(QT_FEATURE_separate_debug_info AND is_shared_lib AND (UNIX OR MINGW))
qt_enable_separate_debug_info(${target} ${INSTALL_LIBDIR})
endif()
if (ANDROID) if (ANDROID)
qt_android_apply_arch_suffix("${target}") qt_android_apply_arch_suffix("${target}")
endif() endif()
@ -3339,6 +3344,10 @@ function(qt_add_tool name)
EXPORT "${INSTALL_CMAKE_NAMESPACE}${arg_TOOLS_TARGET}ToolsTargets" EXPORT "${INSTALL_CMAKE_NAMESPACE}${arg_TOOLS_TARGET}ToolsTargets"
DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS})
endif() endif()
if(QT_FEATURE_separate_debug_info AND (UNIX OR MINGW))
qt_enable_separate_debug_info(${name} ${INSTALL_BINDIR})
endif()
endfunction() endfunction()
function(qt_create_tracepoints name tracePointsFile) function(qt_create_tracepoints name tracePointsFile)

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,73 @@
include(CMakeFindBinUtils)
set(QtSeparateDebugInfo_cmake_DIR ${CMAKE_CURRENT_LIST_DIR})
# Enable separate debug information for the given target
function(qt_enable_separate_debug_info target installDestination)
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(
"${QtSeparateDebugInfo_cmake_DIR}/QtSeparateDebugInfo.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}>")
qt_install(DIRECTORY ${debug_info_bundle_dir} DESTINATION ${installDestination})
else()
set(debug_info_target "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.${debug_info_suffix}")
qt_install(FILES ${debug_info_target} DESTINATION ${installDestination})
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()

View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.14.0)
project(objcopytest LANGUAGES CXX)
include(CMakeFindBinUtils)
add_executable(objcopytest main.cpp)
add_custom_command(
TARGET objcopytest
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $<TARGET_FILE:objcopytest> objcopytest.debug
COMMAND ${CMAKE_OBJCOPY} --strip-debug $<TARGET_FILE:objcopytest>
COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=objcopytest.debug $<TARGET_FILE:objcopytest>)

View File

@ -0,0 +1 @@
int main() {}

View File

@ -0,0 +1,7 @@
TARGET = objcopytest
SOURCES += main.cpp
load(resolve_target)
QMAKE_POST_LINK += \
$$QMAKE_OBJCOPY --only-keep-debug $$QMAKE_RESOLVED_TARGET objcopytest.debug && \
$$QMAKE_OBJCOPY --strip-debug $$QMAKE_RESOLVED_TARGET && \
$$QMAKE_OBJCOPY --add-gnu-debuglink=objcopytest.debug $$QMAKE_RESOLVED_TARGET

View File

@ -127,6 +127,10 @@ int main(int argc, char **argv)
"# FIXME: qmake: ['TEMPLATE = lib', 'CONFIG += dll bsymbolic_functions', 'isEmpty(QMAKE_LFLAGS_BSYMBOLIC_FUNC): error("Nope")'] "# FIXME: qmake: ['TEMPLATE = lib', 'CONFIG += dll bsymbolic_functions', 'isEmpty(QMAKE_LFLAGS_BSYMBOLIC_FUNC): error("Nope")']
) )
qt_config_compile_test("separate_debug_info"
LABEL "separate debug information support"
PROJECT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/config.tests/separate_debug_info")
# signaling_nan # signaling_nan
qt_config_compile_test(signaling_nan qt_config_compile_test(signaling_nan
LABEL "Signaling NaN for doubles" LABEL "Signaling NaN for doubles"
@ -367,6 +371,12 @@ qt_feature("force_debug_info"
AUTODETECT CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR RelWithDebInfo IN_LIST CMAKE_CONFIGURATION_TYPES AUTODETECT CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR RelWithDebInfo IN_LIST CMAKE_CONFIGURATION_TYPES
) )
qt_feature_config("force_debug_info" QMAKE_PRIVATE_CONFIG) qt_feature_config("force_debug_info" QMAKE_PRIVATE_CONFIG)
qt_feature("separate_debug_info" PUBLIC
LABEL "Split off debug information"
AUTODETECT OFF
CONDITION ( QT_FEATURE_shared ) AND ( QT_FEATURE_debug OR QT_FEATURE_debug_and_release OR QT_FEATURE_force_debug_info ) AND ( APPLE OR TEST_separate_debug_info )
)
qt_feature_config("separate_debug_info" QMAKE_PUBLIC_QT_CONFIG)
qt_feature("appstore-compliant" PUBLIC qt_feature("appstore-compliant" PUBLIC
LABEL "App store compliance" LABEL "App store compliance"
PURPOSE "Disables code that is not allowed in platform app stores" PURPOSE "Disables code that is not allowed in platform app stores"

View File

@ -460,17 +460,7 @@
}, },
"separate_debug_info": { "separate_debug_info": {
"label": "separate debug information support", "label": "separate debug information support",
"type": "compile", "type": "compile"
"test": {
"qmake": [
"TARGET = objcopytest",
"load(resolve_target)",
"QMAKE_POST_LINK += \\",
" $$QMAKE_OBJCOPY --only-keep-debug $$QMAKE_RESOLVED_TARGET objcopytest.debug && \\",
" $$QMAKE_OBJCOPY --strip-debug $$QMAKE_RESOLVED_TARGET && \\",
" $$QMAKE_OBJCOPY --add-gnu-debuglink=objcopytest.debug $$QMAKE_RESOLVED_TARGET"
]
}
}, },
"gc_binaries": { "gc_binaries": {
"label": "support for split sections and linker garbage collection", "label": "support for split sections and linker garbage collection",

View File

@ -696,7 +696,6 @@ def parseTest(ctx, test, data, cm_fh):
"sun-iconv", "sun-iconv",
"precomile_header", "precomile_header",
"reduce_exports", "reduce_exports",
"separate_debug_info", # FIXME: see if cmake can do this
"gc_binaries", "gc_binaries",
"libinput_axis_api", "libinput_axis_api",
"wayland-scanner", "wayland-scanner",
@ -827,7 +826,6 @@ def parseFeature(ctx, feature, data, cm_fh):
"sanitizer": None, "sanitizer": None,
"sanitize_thread": None, "sanitize_thread": None,
"sanitize_undefined": None, "sanitize_undefined": None,
"separate_debug_info": None,
"shared": {"condition": "BUILD_SHARED_LIBS"}, "shared": {"condition": "BUILD_SHARED_LIBS"},
"silent": None, "silent": None,
"sql-sqlite": {"condition": "QT_FEATURE_datestring AND SQLite3_FOUND"}, "sql-sqlite": {"condition": "QT_FEATURE_datestring AND SQLite3_FOUND"},