From 0ef3bfc18e2435ac40e9ab77bef8fbe73992d75c Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Tue, 19 Dec 2023 16:40:29 +0100 Subject: [PATCH 1/3] fix: provide correct dependencies for CMake client projects... ...that use a system provided breakpad (instead of our vendored fork). The problem [here](https://github.com/getsentry/sentry-native/issues/877) was that people who introduce sentry-native via CMake `find_package()` will get insufficient dependencies which leads to configuration errors in the client CMake project. There are two aspects to this problem: * if the user builds sentry as a shared library it shouldn't be necessary to specify the dependencies. This can be fixed by defining `breakpad` as a `PRIVATE` dependency in that case. This should also be the fix for the Gentoo issue because it uses sentry as a shared library afaict. * if the user builds sentry as a static library, then we must stay with the `PUBLIC` dependency, but we also need to correctly search for breakpad, libcurl and pthread in the context of the client project. --- CMakeLists.txt | 6 +++++- sentry-config.cmake.in | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ec677899..8c7a8ba55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,7 +496,11 @@ elseif(SENTRY_BACKEND_BREAKPAD) # system breakpad is using pkg-config, see `external/breakpad/breakpad-client.pc.in` find_package(PkgConfig REQUIRED) pkg_check_modules(BREAKPAD REQUIRED IMPORTED_TARGET breakpad-client) - target_link_libraries(sentry PUBLIC PkgConfig::BREAKPAD) + if(SENTRY_BUILD_SHARED_LIBS) + target_link_libraries(sentry PRIVATE PkgConfig::BREAKPAD) + else() + target_link_libraries(sentry PUBLIC PkgConfig::BREAKPAD) + endif() else() add_subdirectory(external) target_include_directories(sentry PRIVATE diff --git a/sentry-config.cmake.in b/sentry-config.cmake.in index 89ea34511..d4fb8b89f 100644 --- a/sentry-config.cmake.in +++ b/sentry-config.cmake.in @@ -2,19 +2,34 @@ set(SENTRY_BACKEND @SENTRY_BACKEND@) set(SENTRY_TRANSPORT @SENTRY_TRANSPORT@) +set(SENTRY_BUILD_SHARED_LIBS @SENTRY_BUILD_SHARED_LIBS@) +set(SENTRY_LINK_PTHREAD @SENTRY_LINK_PTHREAD@) if(SENTRY_BACKEND STREQUAL "crashpad") - if(@SENTRY_CRASHPAD_SYSTEM@) + set(SENTRY_CRASHPAD_SYSTEM @SENTRY_CRASHPAD_SYSTEM@) + if(SENTRY_CRASHPAD_SYSTEM) find_package(crashpad REQUIRED) else() include("${CMAKE_CURRENT_LIST_DIR}/sentry_crashpad-targets.cmake") endif() endif() +if(SENTRY_BACKEND STREQUAL "breakpad" AND NOT SENTRY_BUILD_SHARED_LIBS) + set(SENTRY_BREAKPAD_SYSTEM @SENTRY_BREAKPAD_SYSTEM@) + if(SENTRY_BREAKPAD_SYSTEM) + find_package(PkgConfig REQUIRED) + pkg_check_modules(BREAKPAD REQUIRED IMPORTED_TARGET breakpad-client) + endif() +endif() + include("${CMAKE_CURRENT_LIST_DIR}/sentry-targets.cmake") -if(SENTRY_TRANSPORT STREQUAL "curl" AND NOT @BUILD_SHARED_LIBS@) +if(SENTRY_TRANSPORT STREQUAL "curl" AND (NOT @BUILD_SHARED_LIBS@ OR NOT SENTRY_BUILD_SHARED_LIBS)) find_package(CURL REQUIRED) set_property(TARGET sentry::sentry APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CURL_LIBRARIES}) endif() + +if(SENTRY_LINK_PTHREAD AND NOT SENTRY_BUILD_SHARED_LIBS) + find_package(Threads REQUIRED) +endif() From f6714a8fe475f45b9a38b95a9f02da46a849484a Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Tue, 19 Dec 2023 16:45:53 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88daef74d..eaade5f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Fixes**: - Maintain crashpad client instance during Native SDK lifecycle. ([#910](https://github.com/getsentry/sentry-native/pull/910)) +- Specify correct dependencies for CMake client projects using a system-provided breakpad. ([#926](https://github.com/getsentry/sentry-native/pull/926)) **Internal**: @@ -17,6 +18,7 @@ Features, fixes and improvements in this release have been contributed by: - [@compnerd](https://github.com/compnerd) +- [@stima](https://github.com/stima) ## 0.6.7 From 49046a1662abd3f7a132bb7c85e4c45311caf562 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Tue, 19 Dec 2023 17:16:12 +0100 Subject: [PATCH 3/3] normalize whitespace --- sentry-config.cmake.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sentry-config.cmake.in b/sentry-config.cmake.in index d4fb8b89f..483d92c0a 100644 --- a/sentry-config.cmake.in +++ b/sentry-config.cmake.in @@ -6,7 +6,7 @@ set(SENTRY_BUILD_SHARED_LIBS @SENTRY_BUILD_SHARED_LIBS@) set(SENTRY_LINK_PTHREAD @SENTRY_LINK_PTHREAD@) if(SENTRY_BACKEND STREQUAL "crashpad") - set(SENTRY_CRASHPAD_SYSTEM @SENTRY_CRASHPAD_SYSTEM@) + set(SENTRY_CRASHPAD_SYSTEM @SENTRY_CRASHPAD_SYSTEM@) if(SENTRY_CRASHPAD_SYSTEM) find_package(crashpad REQUIRED) else() @@ -15,7 +15,7 @@ if(SENTRY_BACKEND STREQUAL "crashpad") endif() if(SENTRY_BACKEND STREQUAL "breakpad" AND NOT SENTRY_BUILD_SHARED_LIBS) - set(SENTRY_BREAKPAD_SYSTEM @SENTRY_BREAKPAD_SYSTEM@) + set(SENTRY_BREAKPAD_SYSTEM @SENTRY_BREAKPAD_SYSTEM@) if(SENTRY_BREAKPAD_SYSTEM) find_package(PkgConfig REQUIRED) pkg_check_modules(BREAKPAD REQUIRED IMPORTED_TARGET breakpad-client) @@ -31,5 +31,5 @@ if(SENTRY_TRANSPORT STREQUAL "curl" AND (NOT @BUILD_SHARED_LIBS@ OR NOT SENTRY_B endif() if(SENTRY_LINK_PTHREAD AND NOT SENTRY_BUILD_SHARED_LIBS) - find_package(Threads REQUIRED) + find_package(Threads REQUIRED) endif()