summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-12-06 15:55:48 +0800
committerGitHub <noreply@github.com>2024-12-06 07:55:48 +0000
commit22b64a446c8c37cc0b3670eb117b64575fc54d2f (patch)
treec61fca70d0973ca0f8ebe7dd908344983e4aca02 /cmake
parent7dabfa76ccfb396e9d2019e2b6e01259d1661dc5 (diff)
Split debug info for all targets (#5732)
* Split debug info for all targets Work towards https://github.com/shader-slang/slang/issues/5724 * release separate debug info Closes https://github.com/shader-slang/slang/issues/5724 * Add split debug info support for MacOS * Add SLANG_ENABLE_SPLIT_DEBUG_INFO option * Sign and package debug info on MacOS * Set --build-id where available * Correct debug info installing * Keep cpack macos signing workaround * Neaten cmake * Disable sccache if building split debug info on Windows * Only repack necessary files on MacOS releases
Diffstat (limited to 'cmake')
-rw-r--r--cmake/CompilerFlags.cmake10
-rw-r--r--cmake/SlangTarget.cmake174
2 files changed, 161 insertions, 23 deletions
diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake
index cd9021cd0..e3ddaa7e0 100644
--- a/cmake/CompilerFlags.cmake
+++ b/cmake/CompilerFlags.cmake
@@ -152,8 +152,14 @@ function(set_default_compile_options target)
add_supported_cxx_flags(${target} PRIVATE ${warning_flags})
- # Don't assume that symbols will be resolved at runtime
- add_supported_cxx_linker_flags(${target} PRIVATE "-Wl,--no-undefined")
+ add_supported_cxx_linker_flags(
+ ${target}
+ PRIVATE
+ # Don't assume that symbols will be resolved at runtime
+ "-Wl,--no-undefined"
+ # No reason not to do this? Useful when using split debug info
+ "-Wl,--build-id"
+ )
set_target_properties(
${target}
diff --git a/cmake/SlangTarget.cmake b/cmake/SlangTarget.cmake
index 4da2cab3b..59d12ab7a 100644
--- a/cmake/SlangTarget.cmake
+++ b/cmake/SlangTarget.cmake
@@ -1,5 +1,5 @@
#
-# A function to make target creation a little more declarative
+# A function to make target specification a little more declarative
#
# See the comments on the options below for usage
#
@@ -21,6 +21,8 @@ function(slang_add_target dir type)
# Don't include any source in this target, this is a complement to
# EXPLICIT_SOURCE, and doesn't interact with EXTRA_SOURCE_DIRS
NO_SOURCE
+ # Don't generate split debug info for this target
+ NO_SPLIT_DEBUG_INFO
)
set(single_value_args
# Set the target name, useful for multiple targets from the same
@@ -49,7 +51,7 @@ function(slang_add_target dir type)
DEBUG_DIR
# Install this target as part of a component
INSTALL_COMPONENT
- # Don't install debug info by default for this target and use this
+ # Override the debug info component name for installation
# explicit name instead, used for externally built things such as
# slang-glslang and slang-llvm which have large pdb files
DEBUG_INFO_INSTALL_COMPONENT
@@ -198,6 +200,15 @@ function(slang_add_target dir type)
PDB_OUTPUT_DIRECTORY "${output_dir}/${runtime_subdir}"
)
+ if(NOT MSVC)
+ set_target_properties(
+ ${target}
+ PROPERTIES
+ COMPILE_OPTIONS
+ "$<$<CONFIG:Debug,RelWithDebInfo>:-fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=${output_dir}>"
+ )
+ endif()
+
#
# Set common compile options and properties
#
@@ -209,6 +220,118 @@ function(slang_add_target dir type)
set_default_compile_options(${target})
endif()
+ # Set debug info options if not disabled
+ # Determine if this target produces a binary that can have debug info
+ if(
+ NOT ARG_NO_SPLIT_DEBUG_INFO
+ AND type MATCHES "^(EXECUTABLE|SHARED|MODULE)$"
+ AND SLANG_ENABLE_SPLIT_DEBUG_INFO
+ )
+ set(generate_split_debug_info TRUE)
+ else()
+ set(generate_split_debug_info FALSE)
+ endif()
+
+ if(generate_split_debug_info)
+ if(MSVC)
+ get_target_property(
+ c_compiler_launcher
+ ${target}
+ C_COMPILER_LAUNCHER
+ )
+ get_target_property(
+ cxx_compiler_launcher
+ ${target}
+ CXX_COMPILER_LAUNCHER
+ )
+
+ if(
+ c_compiler_launcher MATCHES "ccache"
+ OR cxx_compiler_launcher MATCHES "ccache"
+ )
+ message(
+ WARNING
+ "(s)ccache detected for target ${target}. Removing launcher as it's incompatible with split debug info compiled with MSVC."
+ )
+ set_target_properties(
+ ${target}
+ PROPERTIES C_COMPILER_LAUNCHER "" CXX_COMPILER_LAUNCHER ""
+ )
+ endif()
+
+ get_target_property(
+ msvc_debug_information_format
+ ${target}
+ MSVC_DEBUG_INFORMATION_FORMAT
+ )
+ if(
+ NOT msvc_debug_information_format
+ MATCHES
+ "(ProgramDatabase|EditAndContinue)"
+ )
+ message(
+ WARNING
+ "Debug format must be ProgramDatabase or EditAndContinue to generate split debug info with MSVC"
+ )
+ endif()
+
+ set_target_properties(
+ ${target}
+ PROPERTIES
+ # While it would be nice to set this here, we don't know if
+ # the user wants ProgramDatabase or EditAndContinue, so
+ # just check above
+ # MSVC_DEBUG_INFORMATION_FORMAT
+ # "$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>"
+ COMPILE_PDB_NAME "${target}"
+ COMPILE_PDB_OUTPUT_DIRECTORY "${output_dir}"
+ )
+ else()
+ # Common debug flags for GCC/Clang
+ target_compile_options(
+ ${target}
+ PRIVATE
+ $<$<CONFIG:Debug,RelWithDebInfo>:
+ -g
+ -fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.
+ -fdebug-prefix-map=${CMAKE_BINARY_DIR}=.
+ >
+ )
+
+ if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
+ # macOS - use dsymutil with --flat to create separate debug file
+ add_custom_command(
+ TARGET ${target}
+ POST_BUILD
+ 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()
+ add_custom_command(
+ TARGET ${target}
+ POST_BUILD
+ COMMAND
+ ${CMAKE_OBJCOPY} --only-keep-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}>.dwarf
+ $<TARGET_FILE:${target}>
+ WORKING_DIRECTORY ${output_dir}
+ VERBATIM
+ )
+ endif()
+ endif()
+ endif()
+
set_target_properties(
${target}
PROPERTIES EXCLUDE_FROM_ALL ${ARG_EXCLUDE_FROM_ALL}
@@ -429,32 +552,41 @@ function(slang_add_target dir type)
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${ARGN}
)
endmacro()
+
if(ARG_INSTALL_COMPONENT)
i(EXCLUDE_FROM_ALL COMPONENT ${ARG_INSTALL_COMPONENT})
- set(pdb_component "${ARG_INSTALL_COMPONENT}-debug-info")
+ set(debug_component "${ARG_INSTALL_COMPONENT}-debug-info")
elseif(ARG_INSTALL)
i()
- set(pdb_component "debug-info")
+ set(debug_component "debug-info")
endif()
- if(ARG_DEBUG_INFO_INSTALL_COMPONENT)
- set(pdb_component ${ARG_DEBUG_INFO_INSTALL_COMPONENT})
+
+ if(DEFINED ARG_DEBUG_INFO_INSTALL_COMPONENT)
+ set(debug_component "${ARG_DEBUG_INFO_INSTALL_COMPONENT}")
endif()
- if(MSVC AND DEFINED pdb_component)
- if(
- type STREQUAL "EXECUTABLE"
- OR type STREQUAL "SHARED"
- OR type STREQUAL "MODULE"
- )
- install(
- FILES $<TARGET_PDB_FILE:${target}>
- DESTINATION ${runtime_subdir}
- # Optional, because if we're building without debug info (like
- # a release build) then we don't want to fail here.
- OPTIONAL
- COMPONENT ${pdb_component}
- EXCLUDE_FROM_ALL
- )
+
+ # Install debug info only if target is being installed
+ if((ARG_INSTALL OR ARG_INSTALL_COMPONENT) AND generate_split_debug_info)
+ if(type STREQUAL "EXECUTABLE" OR WIN32)
+ set(debug_dest ${runtime_subdir})
+ else()
+ set(debug_dest ${library_subdir})
endif()
+
+ if(MSVC)
+ set(debug_file $<TARGET_PDB_FILE:${target}>)
+ else()
+ 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()