Skip to content

Commit

Permalink
Correct debug info installing
Browse files Browse the repository at this point in the history
  • Loading branch information
expipiplus1 committed Dec 4, 2024
1 parent cffff8d commit cbc9119
Showing 1 changed file with 21 additions and 43 deletions.
64 changes: 21 additions & 43 deletions cmake/SlangTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ function(slang_add_target dir type)

if(generate_split_debug_info)
if(MSVC)
# MSVC handling
target_compile_options(
${target}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:/Z7>
Expand All @@ -256,35 +255,31 @@ function(slang_add_target dir type)
)

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
# macOS - use dsymutil
# macOS - use dsymutil with --flat to create separate debug file
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND dsymutil $<TARGET_FILE:${target}>
COMMAND
dsymutil --flat $<TARGET_FILE:${target}> -o
$<TARGET_FILE:${target}>.dwarf
COMMAND chmod 644 $<TARGET_FILE:${target}>.dwarf
COMMAND ${CMAKE_STRIP} -S $<TARGET_FILE:${target}>
WORKING_DIRECTORY ${output_dir}
VERBATIM
)
else()
# Linux/Unix - use GNU debug info splitting
target_link_options(
${target}
PRIVATE
$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:
-Wl,--build-id=sha1
>
)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND
${CMAKE_OBJCOPY} --only-keep-debug
$<TARGET_FILE:${target}> $<TARGET_FILE:${target}>.debug
COMMAND chmod 644 $<TARGET_FILE:${target}>.debug
$<TARGET_FILE:${target}> $<TARGET_FILE:${target}>.dwarf
COMMAND chmod 644 $<TARGET_FILE:${target}>.dwarf
COMMAND
${CMAKE_STRIP} --strip-debug $<TARGET_FILE:${target}>
COMMAND
${CMAKE_OBJCOPY}
--add-gnu-debuglink=$<TARGET_FILE:${target}>.debug
--add-gnu-debuglink=$<TARGET_FILE:${target}>.dwarf
$<TARGET_FILE:${target}>
WORKING_DIRECTORY ${output_dir}
VERBATIM
Expand Down Expand Up @@ -523,43 +518,26 @@ function(slang_add_target dir type)

# Install debug info only if target is being installed
if((ARG_INSTALL OR ARG_INSTALL_COMPONENT) AND generate_split_debug_info)
# Determine correct destination based on target type
if(type STREQUAL "EXECUTABLE" OR WIN32)
set(debug_dest ${runtime_subdir})
else()
set(debug_dest ${library_subdir})
endif()

if(MSVC)
# Install PDB files for MSVC
install(
FILES $<TARGET_PDB_FILE:${target}>
DESTINATION ${debug_dest}
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT ${debug_component}
EXCLUDE_FROM_ALL
OPTIONAL
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
# macOS dSYM installation
install(
DIRECTORY "$<TARGET_FILE:${target}>.dSYM"
DESTINATION ${debug_dest}
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT ${debug_component}
EXCLUDE_FROM_ALL
OPTIONAL
)
set(debug_file $<TARGET_PDB_FILE:${target}>)
else()
# Linux/Unix debug file installation
install(
FILES "$<TARGET_FILE:${target}>.debug"
DESTINATION ${debug_dest}
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT ${debug_component}
EXCLUDE_FROM_ALL
OPTIONAL
)
set(debug_file "$<TARGET_FILE:${target}>.dwarf")
endif()

install(
FILES ${debug_file}
DESTINATION ${debug_dest}
CONFIGURATIONS Debug RelWithDebInfo
COMPONENT ${debug_component}
EXCLUDE_FROM_ALL
OPTIONAL
)
endif()
endfunction()

Expand Down

0 comments on commit cbc9119

Please sign in to comment.