summaryrefslogtreecommitdiffstats
path: root/cmake/SlangTarget.cmake
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-12-06 20:24:43 +0800
committerGitHub <noreply@github.com>2024-12-06 13:24:43 +0100
commit27b7ac0e8ae02a41f748cccd76d617bb3b9d9734 (patch)
tree87f1bfc28463e81e89f87dbdee1c1f4b7fa94e2a /cmake/SlangTarget.cmake
parent8ce7c6f6958f9f5ed750ef1a823b9e9ed8c042d8 (diff)
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
Diffstat (limited to 'cmake/SlangTarget.cmake')
-rw-r--r--cmake/SlangTarget.cmake86
1 files changed, 22 insertions, 64 deletions
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
+ "$<$<CONFIG:${debug_configs}>:Embedded>"
+ )
+ if(MSVC)
+ target_link_options(
+ ${target}
+ PRIVATE "$<$<CONFIG:${debug_configs}>:/DEBUG>"
+ )
+ else()
+ target_compile_options(
${target}
- PROPERTIES
- COMPILE_OPTIONS
- "$<$<CONFIG:Debug,RelWithDebInfo>:-fdebug-prefix-map=${CMAKE_CURRENT_BINARY_DIR}=${output_dir}>"
+ PRIVATE "$<$<CONFIG:${debug_configs}>:-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
- # "$<$<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(
@@ -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