From e874089831f23a35d3735f5a2ee8cce2f79ba90a Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 3 Dec 2025 12:13:28 +0800 Subject: [PATCH] feature add flag for control sentry to use --- CMakeLists.txt | 52 +++++++++++++++++++++++++++++++-------------- deps/CMakeLists.txt | 2 +- src/CMakeLists.txt | 6 +++++- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d90d2521..13642a8cb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,14 @@ option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1) option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1) option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0) option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0) + +# Sentry crash reporting - enabled only on Windows by default +if (WIN32) + set(SLIC3R_SENTRY_DEFAULT ON) +else() + set(SLIC3R_SENTRY_DEFAULT OFF) +endif() +option(SLIC3R_SENTRY "Enable Sentry crash reporting SDK" ${SLIC3R_SENTRY_DEFAULT}) # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable. CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0) @@ -534,7 +542,9 @@ find_package(TBB REQUIRED) find_package(OpenSSL REQUIRED) find_package(CURL REQUIRED) -find_package(Sentry REQUIRED) +if (SLIC3R_SENTRY) + find_package(Sentry REQUIRED) +endif() find_package(Freetype REQUIRED) @@ -544,19 +554,21 @@ target_link_libraries(libcurl INTERFACE CURL::libcurl) find_package(ZLIB REQUIRED) target_link_libraries(libcurl INTERFACE ZLIB::ZLIB) -add_library(sentry INTERFACE) -target_link_libraries(sentry INTERFACE sentry::sentry) +if (SLIC3R_SENTRY) + add_library(sentry INTERFACE) + target_link_libraries(sentry INTERFACE sentry::sentry) -# Add sentry library directory and link sentry.lib explicitly for Windows -if (WIN32 AND CMAKE_PREFIX_PATH) - # Try to find sentry.lib in the install prefix - file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/sentry.lib") - if (_sentry_lib) - target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") - target_link_libraries(sentry INTERFACE "sentry.lib") - message(STATUS "Found sentry.lib at: ${CMAKE_PREFIX_PATH}/lib") - else() - message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + # Add sentry library directory and link sentry.lib explicitly for Windows + if (WIN32 AND CMAKE_PREFIX_PATH) + # Try to find sentry.lib in the install prefix + file(GLOB _sentry_lib "${CMAKE_PREFIX_PATH}/lib/sentry.lib") + if (_sentry_lib) + target_link_directories(sentry INTERFACE "${CMAKE_PREFIX_PATH}/lib") + target_link_libraries(sentry INTERFACE "sentry.lib") + message(STATUS "Found sentry.lib at: ${CMAKE_PREFIX_PATH}/lib") + else() + message(WARNING "sentry.lib not found in ${CMAKE_PREFIX_PATH}/lib. Sentry SDK may not have been built yet.") + endif() endif() endif() @@ -745,7 +757,7 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) DESTINATION ${_out_dir}) # Copy Sentry and Crashpad artifacts if they were built by deps - if (EXISTS "${CMAKE_PREFIX_PATH}/bin/sentry.dll") + if (SLIC3R_SENTRY AND EXISTS "${CMAKE_PREFIX_PATH}/bin/sentry.dll") file(COPY "${CMAKE_PREFIX_PATH}/bin/sentry.dll" "${CMAKE_PREFIX_PATH}/bin/crashpad_handler.exe" DESTINATION ${_out_dir} @@ -814,12 +826,20 @@ function(Snapmaker_Orca_copy_dlls target config postfix output_dlls) ${_out_dir}/TKXSBase.dll ${_out_dir}/freetype.dll - ${_out_dir}/sentry.dll - ${_out_dir}/crashpad_handler.exe PARENT_SCOPE ) + # Add Sentry DLLs to the output list if Sentry is enabled + if (SLIC3R_SENTRY) + set(${output_dlls} + ${${output_dlls}} + ${_out_dir}/sentry.dll + ${_out_dir}/crashpad_handler.exe + PARENT_SCOPE + ) + endif() + endfunction() diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 89e22ee5e4..126da82e8c 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -315,7 +315,7 @@ if (NOT OPENSSL_FOUND OR NOT CURL_FOUND) endif () set(SENTRY_PKG "") -if (NOT SENTRY_FOUND) +if (SLIC3R_SENTRY AND NOT SENTRY_FOUND) include(Sentry/Sentry.cmake) set(SENTRY_PKG dep_Sentry) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7525f6cf45..a4463c9749 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -183,7 +183,11 @@ if (WIN32) target_compile_definitions(Snapmaker_Orca_app_gui PRIVATE -DSLIC3R_WRAPPER_NOCONSOLE) add_dependencies(Snapmaker_Orca_app_gui Snapmaker_Orca) set_target_properties(Snapmaker_Orca_app_gui PROPERTIES OUTPUT_NAME "snapmaker-orca") - target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) + if (SLIC3R_SENTRY) + target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly sentry::sentry) + else() + target_link_libraries(Snapmaker_Orca_app_gui PRIVATE boost_headeronly) + endif() endif () # Link the resources dir to where Slic3r GUI expects it