From 3aef34664094a6d5b217070d6f7074427f92e28e Mon Sep 17 00:00:00 2001 From: R-Goc Date: Sat, 23 Aug 2025 22:35:56 +0200 Subject: [PATCH] Add support for delayed load of dbghelp Dbghelp is a large library and is known to increase startup times when loaded as a dll. When using /DELAYLOAD windows will automatically load the library on the first call to one of its functions. --- CMakeLists.txt | 5 +++++ cmake/OptionVariables.cmake | 1 + 2 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78e0af04..93d8b641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,6 +276,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") SET(CMAKE_CXX_ARCHIVE_FINISH " -no_warning_for_no_symbols -c ") endif() +if(CPPTRACE_DELAYLOAD_DBGHELP AND BUILD_SHARED_LIBS AND MSVC AND (CPPTRACE_UNWIND_WITH_DBGHELP OR CPPTRACE_GET_SYMBOLS_WITH_DBGHELP)) + target_link_libraries(${target_name} PRIVATE delayimp.lib) + target_link_options(${target_name} PRIVATE /DELAYLOAD:dbghelp.dll) +endif() + # =================================================== Back-end setup =================================================== if(HAS_CXX_EXCEPTION_TYPE) diff --git a/cmake/OptionVariables.cmake b/cmake/OptionVariables.cmake index 417982bd..e726db11 100644 --- a/cmake/OptionVariables.cmake +++ b/cmake/OptionVariables.cmake @@ -187,6 +187,7 @@ set(CPPTRACE_LIBDWARF_SHALLOW "1" CACHE STRING "") option(CPPTRACE_PROVIDE_EXPORT_SET "" ON) option(CPPTRACE_PROVIDE_EXPORT_SET_FOR_LIBDWARF "" OFF) option(CPPTRACE_DISABLE_CXX_20_MODULES "" OFF) +option(CPPTRACE_DELAYLOAD_DBGHELP "" OFF) mark_as_advanced( CPPTRACE_BACKTRACE_PATH