1
0
mirror of synced 2025-01-31 12:03:46 +01:00

build: Compress debug info (#1719)

This PR compress the debug info in the ELF files built.

This has no impact on the packages (e.g. .deb files) because they themselves have compression, but once installed in the filesystem, they this compression will be beneficial

The compression is opportunistic, happens automatically when possible

For some reason, the web version doesn't work with this (most compiler tests after this seem to fail ?) so it is disabled there

More information: https://github.com/WerWolv/ImHex/issues/1714#issuecomment-2131373826
This commit is contained in:
iTrooz 2024-05-26 20:48:14 +02:00 committed by GitHub
parent 974c4ba040
commit 0b0bf90e0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

View File

@ -21,6 +21,7 @@ option(IMHEX_REPLACE_DWARF_WITH_PDB "Remove DWARF information from binaries
option(IMHEX_ENABLE_STD_ASSERTS "Enable debug asserts in the C++ std library. (Breaks Plugin ABI!)" OFF) option(IMHEX_ENABLE_STD_ASSERTS "Enable debug asserts in the C++ std library. (Breaks Plugin ABI!)" OFF)
option(IMHEX_ENABLE_UNIT_TESTS "Enable building unit tests" OFF) option(IMHEX_ENABLE_UNIT_TESTS "Enable building unit tests" OFF)
option(IMHEX_ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" OFF) option(IMHEX_ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" OFF)
option(IMHEX_COMPRESS_DEBUG_INFO "Compress debug information" ON )
set(IMHEX_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}") set(IMHEX_BASE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_MODULE_PATH "${IMHEX_BASE_FOLDER}/cmake/modules") set(CMAKE_MODULE_PATH "${IMHEX_BASE_FOLDER}/cmake/modules")

View File

@ -531,6 +531,31 @@ function(downloadImHexPatternsFiles dest)
endfunction() endfunction()
# Compress debug info. See https://github.com/WerWolv/ImHex/issues/1714 for relevant problem
macro(setupDebugCompressionFlag)
include(CheckCXXCompilerFlag)
include(CheckLinkerFlag)
check_cxx_compiler_flag(-gz=zstd ZSTD_AVAILABLE_COMPILER)
check_linker_flag(CXX -gz=zstd ZSTD_AVAILABLE_LINKER)
check_cxx_compiler_flag(-gz COMPRESS_AVAILABLE_COMPILER)
check_linker_flag(CXX -gz COMPRESS_AVAILABLE_LINKER)
if (NOT DEBUG_COMPRESSION_FLAG) # Cache variable
if (ZSTD_AVAILABLE_COMPILER AND ZSTD_AVAILABLE_LINKER)
message("Using Zstd compression for debug info because both compiler and linker support it")
set(DEBUG_COMPRESSION_FLAG "-gz=zstd" CACHE STRING "Cache to use for debug info compression")
elseif (COMPRESS_AVAILABLE_COMPILER AND COMPRESS_AVAILABLE_LINKER)
message("Using default compression for debug info because both compiler and linker support it")
set(DEBUG_COMPRESSION_FLAG "-gz" CACHE STRING "Cache to use for debug info compression")
else()
message("No compression available for debug info")
endif()
endif()
set(IMHEX_COMMON_FLAGS "${IMHEX_COMMON_FLAGS} ${DEBUG_COMPRESSION_FLAG}")
endmacro()
macro(setupCompilerFlags target) macro(setupCompilerFlags target)
# IMHEX_COMMON_FLAGS: flags common for C, C++, Objective C, etc.. compilers # IMHEX_COMMON_FLAGS: flags common for C, C++, Objective C, etc.. compilers
@ -566,6 +591,10 @@ macro(setupCompilerFlags target)
set(IMHEX_C_CXX_FLAGS "${IMHEX_C_CXX_FLAGS} -pthread -Wno-dollar-in-identifier-extension -Wno-pthreads-mem-growth") set(IMHEX_C_CXX_FLAGS "${IMHEX_C_CXX_FLAGS} -pthread -Wno-dollar-in-identifier-extension -Wno-pthreads-mem-growth")
endif () endif ()
if (IMHEX_COMPRESS_DEBUG_INFO)
setupDebugCompressionFlag()
endif()
# Set actual CMake flags # Set actual CMake flags
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${IMHEX_COMMON_FLAGS} ${IMHEX_C_CXX_FLAGS}") set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${IMHEX_COMMON_FLAGS} ${IMHEX_C_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IMHEX_COMMON_FLAGS} ${IMHEX_C_CXX_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${IMHEX_COMMON_FLAGS} ${IMHEX_C_CXX_FLAGS}")

1
dist/web/Dockerfile vendored
View File

@ -59,6 +59,7 @@ cmake /imhex
-DIMHEX_OFFLINE_BUILD=ON \ -DIMHEX_OFFLINE_BUILD=ON \
-DIMHEX_STATIC_LINK_PLUGINS=ON \ -DIMHEX_STATIC_LINK_PLUGINS=ON \
-DIMHEX_EXCLUDE_PLUGINS="script_loader" \ -DIMHEX_EXCLUDE_PLUGINS="script_loader" \
-DIMHEX_COMPRESS_DEBUG_INFO=OFF \
-DNATIVE_CMAKE_C_COMPILER=gcc \ -DNATIVE_CMAKE_C_COMPILER=gcc \
-DNATIVE_CMAKE_CXX_COMPILER=g++ \ -DNATIVE_CMAKE_CXX_COMPILER=g++ \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \