From 27b7ac0e8ae02a41f748cccd76d617bb3b9d9734 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Fri, 6 Dec 2024 20:24:43 +0800 Subject: Emit debug info for Release builds (#5783) * Remove unnecessary warnings on windows * Correctly set debug flags on gcc * Emit debug info for Release builds * Perform LTO for relwithdebinfo builds * Release from release builds not relwithdebinfo --- cmake/SlangTarget.cmake | 86 +++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 64 deletions(-) (limited to 'cmake') diff --git a/cmake/SlangTarget.cmake b/cmake/SlangTarget.cmake index 59d12ab7a..45e7cf1e1 100644 --- a/cmake/SlangTarget.cmake +++ b/cmake/SlangTarget.cmake @@ -168,7 +168,9 @@ function(slang_add_target dir type) # See: https://cmake.org/cmake/help/latest/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.html set_target_properties( ${target} - PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE + PROPERTIES + INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE + INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE ) # @@ -200,12 +202,26 @@ function(slang_add_target dir type) PDB_OUTPUT_DIRECTORY "${output_dir}/${runtime_subdir}" ) - if(NOT MSVC) - set_target_properties( + set(debug_configs "Debug,RelWithDebInfo") + if(SLANG_ENABLE_RELEASE_DEBUG_INFO) + set(debug_configs "Debug,RelWithDebInfo,Release") + endif() + + set_target_properties( + ${target} + PROPERTIES + MSVC_DEBUG_INFORMATION_FORMAT + "$<$:Embedded>" + ) + if(MSVC) + target_link_options( + ${target} + PRIVATE "$<$:/DEBUG>" + ) + else() + target_compile_options( ${target} - PROPERTIES - COMPILE_OPTIONS - "$<$:-fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=${output_dir}>" + PRIVATE "$<$:-g>" ) endif() @@ -234,70 +250,13 @@ function(slang_add_target dir type) 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 - # "$<$:ProgramDatabase>" COMPILE_PDB_NAME "${target}" COMPILE_PDB_OUTPUT_DIRECTORY "${output_dir}" ) else() - # Common debug flags for GCC/Clang - target_compile_options( - ${target} - PRIVATE - $<$: - -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( @@ -582,7 +541,6 @@ function(slang_add_target dir type) install( FILES ${debug_file} DESTINATION ${debug_dest} - CONFIGURATIONS Debug RelWithDebInfo COMPONENT ${debug_component} EXCLUDE_FROM_ALL OPTIONAL -- cgit v1.2.3