From 8aba39c95566cf5eeda8ce6f00cd40d8aa443975 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 26 Jul 2024 09:23:21 -0500 Subject: [PATCH] optional stack trace support --- .cspell/words.txt | 3 +++ project.cmake | 47 ++++++++++++++++++------------------ repertory/repertory/main.cpp | 7 ++++-- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.cspell/words.txt b/.cspell/words.txt index 3fb0ce47..c9fae75a 100644 --- a/.cspell/words.txt +++ b/.cspell/words.txt @@ -31,6 +31,8 @@ dcmake_cxx_flags dcpphttplib_openssl_support dcpphttplib_tcp_nodelay dcpptrace_static_define +dcpptrace_unwind_with_execinfo +dcpptrace_unwind_with_libunwind dcurl_ca_bundle dcurl_ca_fallback dcurl_disable_ldap @@ -67,6 +69,7 @@ drocksdb_install_on_windows dshared dspdlog_fmt_external dthreads_prefer_pthread_flag +dunw_local_only duse_libidn2 duuid_build_tests dwith_benchmark diff --git a/project.cmake b/project.cmake index 102b8cd6..ecf3cb38 100644 --- a/project.cmake +++ b/project.cmake @@ -1,28 +1,29 @@ -add_definitions(-DCPPTRACE_STATIC_DEFINE) +if (NOT PROJECT_STATIC_LINK) + if(PROJECT_IS_MINGW) + add_definitions(-DCPPTRACE_UNWIND_WITH_DBGHELP) + else() + add_definitions(-DCPPTRACE_UNWIND_WITH_UNWIND) + endif() -if(PROJECT_IS_MINGW) - add_definitions(-DCPPTRACE_UNWIND_WITH_DBGHELP) -else() - add_definitions(-DCPPTRACE_UNWIND_WITH_LIBUNWIND) -endif() - -include(FetchContent) -FetchContent_Declare( - cpptrace - GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git - GIT_TAG v0.6.3 -) -FetchContent_MakeAvailable(cpptrace) -link_libraries(cpptrace::cpptrace) - -if(WIN32) - add_custom_command( - TARGET ${PROJECT_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - $ - $ + include(FetchContent) + FetchContent_Declare( + cpptrace + GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git + GIT_TAG v0.6.3 ) + FetchContent_MakeAvailable(cpptrace) + + if(WIN32) + add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) + endif() + + link_libraries(cpptrace::cpptrace) endif() set(CMAKE_CXX_FLAGS "-include common.hpp ${CMAKE_CXX_FLAGS}") diff --git a/repertory/repertory/main.cpp b/repertory/repertory/main.cpp index 6e689f73..a8cd1b1c 100644 --- a/repertory/repertory/main.cpp +++ b/repertory/repertory/main.cpp @@ -19,7 +19,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#if !defined(PROJECT_STATIC_LINK) #include "cpptrace/cpptrace.hpp" +#endif #include "cli/actions.hpp" #include "initialize.hpp" @@ -30,7 +32,10 @@ using namespace repertory; auto main(int argc, char **argv) -> int { +#if !defined(PROJECT_STATIC_LINK) cpptrace::register_terminate_handler(); +#endif + if (not repertory::project_initialize()) { return -1; } @@ -114,8 +119,6 @@ auto main(int argc, char **argv) -> int { } } - throw std::runtime_error("test"); - int mount_result{}; if (res == exit_code::success) { if (utils::cli::has_option(args, utils::cli::options::help_option)) {