Skip to content

Commit

Permalink
fix: specify correct dependencies for CMake client projects... (getse…
Browse files Browse the repository at this point in the history
…ntry#926)

...which use a system-provided breakpad (instead of our vendored fork).

The problem [here](getsentry#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. This should also fix 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.
  • Loading branch information
supervacuus authored Dec 19, 2023
1 parent 613f470 commit 00061be
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:

Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions sentry-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 00061be

Please sign in to comment.