summaryrefslogtreecommitdiffstats
path: root/examples/CMakeLists.txt
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2025-01-08 08:30:18 +0200
committerGitHub <noreply@github.com>2025-01-07 22:30:18 -0800
commit5b9931456f595b0a2163fabb65dceac99e0e220f (patch)
tree1329b9bdb3fd77349e6a03dc4d2d1c34251f219b /examples/CMakeLists.txt
parentc43f6fa55aca23365c86c6ec1737d42be74d9d3e (diff)
Add backtraces to examples (#5973)
* examples: Log stack trace on exceptions For now, this is only implemented on Windows. This helps to address #5520. * examples: Print log file if there is any * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'examples/CMakeLists.txt')
-rw-r--r--examples/CMakeLists.txt23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index e46f41e7a..759d99994 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,4 +1,6 @@
function(example dir)
+ cmake_parse_arguments(ARG "WIN32_EXECUTABLE" "" "" ${ARGN})
+
set(debug_dir ${CMAKE_CURRENT_BINARY_DIR}/${dir})
file(
@@ -30,6 +32,22 @@ function(example dir)
)
endif()
+ # Libraries providing a main function that prints stack traces on exceptions
+ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
+ # On Windows we have two different versions: main for "console applications" and
+ # WinMain for normal Windows applications.
+ if(${ARG_WIN32_EXECUTABLE})
+ set(main_wrapper_libraries example-winmain)
+ else()
+ set(main_wrapper_libraries example-main)
+ endif()
+ # Add stack printing support
+ set(main_wrapper_libraries ${main_wrapper_libraries} stacktrace-windows)
+ set(main_wrapper_libraries ${main_wrapper_libraries} dbghelp.lib)
+ else()
+ set(main_wrapper_libraries example-main)
+ endif()
+
slang_add_target(
${dir}
EXECUTABLE
@@ -42,7 +60,9 @@ function(example dir)
gfx-util
platform
$<$<BOOL:${SLANG_ENABLE_CUDA}>:CUDA::cuda_driver>
+ ${main_wrapper_libraries}
EXTRA_COMPILE_DEFINITIONS_PRIVATE
+ SLANG_EXAMPLE_NAME=${dir}
$<$<BOOL:${SLANG_ENABLE_XLIB}>:SLANG_ENABLE_XLIB>
REQUIRED_BY all-examples
OPTIONAL_REQUIRES ${copy_assets_target} copy-prebuilt-binaries
@@ -68,6 +88,9 @@ if(SLANG_ENABLE_EXAMPLES)
$<$<BOOL:${SLANG_ENABLE_CUDA}>:CUDA::cuda_driver>
FOLDER examples
)
+ slang_add_target(example-main STATIC FOLDER examples)
+ slang_add_target(example-winmain STATIC FOLDER examples EXCLUDE_FROM_ALL)
+ slang_add_target(stacktrace-windows STATIC FOLDER examples EXCLUDE_FROM_ALL)
add_custom_target(
all-examples