Skip to content

Commit

Permalink
fix: provide correct dependencies for CMake client projects...
Browse files Browse the repository at this point in the history
...that use a system provided breakpad (instead of our vendored fork).

The problem [here](#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.
  • Loading branch information
supervacuus committed Dec 19, 2023
1 parent 613f470 commit 0ef3bfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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 0ef3bfc

Please sign in to comment.