Skip to content

Commit

Permalink
feat: Cleanup platform libraries linkage (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill authored Feb 12, 2021
1 parent 1843a91 commit f75ae73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 28 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ option(SENTRY_PIC "Build sentry (and dependent) libraries as position independen
option(SENTRY_BUILD_TESTS "Build sentry-native tests" "${SENTRY_MAIN_PROJECT}")
option(SENTRY_BUILD_EXAMPLES "Build sentry-native example(s)" "${SENTRY_MAIN_PROJECT}")

option(SENTRY_LINK_PTHREAD "Link platform threads library" ON)
if(SENTRY_LINK_PTHREAD)
find_package(Threads REQUIRED)
endif()

if(MSVC)
option(SENTRY_BUILD_RUNTIMESTATIC "Build sentry-native with static runtime" OFF)
endif()
Expand Down Expand Up @@ -340,19 +345,29 @@ if(WIN32)
endif()
endif()

if(LINUX)
option(SENTRY_LINK_PTHREAD "Link Sentry with pthread" ON)
if(SENTRY_LINK_PTHREAD)
target_link_libraries(sentry PRIVATE pthread)
endif()
target_link_libraries(sentry PRIVATE dl)
target_link_libraries(sentry PRIVATE rt)
elseif(ANDROID)
target_link_libraries(sentry PRIVATE dl log)
elseif(MSVC)
target_link_libraries(sentry PRIVATE dbghelp version)
elseif(MINGW)
target_link_libraries(sentry PRIVATE dbghelp version)
# handle platform libraries
if(ANDROID)
set(_SENTRY_PLATFORM_LIBS "dl" "log")
elseif(LINUX)
set(_SENTRY_PLATFORM_LIBS "dl" "rt")
elseif(WIN32)
set(_SENTRY_PLATFORM_LIBS "dbghelp" "version")
endif()

# handle platform threads library
if(SENTRY_LINK_PTHREAD)
list(APPEND _SENTRY_PLATFORM_LIBS "Threads::Threads")
endif()

# apply platform libraries to sentry library
if(SENTRY_LIBRARY_TYPE STREQUAL "static")
target_link_libraries(sentry PUBLIC ${_SENTRY_PLATFORM_LIBS})
else()
target_link_libraries(sentry PRIVATE ${_SENTRY_PLATFORM_LIBS})
endif()

# suppress some errors and warnings for MinGW target
if(MINGW)
target_compile_options(sentry PRIVATE
-Wno-unused-variable
-Wno-unused-parameter
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ using `cmake -D BUILD_SHARED_LIBS=OFF ..`.
Enables linking with the static MSVC runtime. Has no effect if the compiler is not MSVC.

- `SENTRY_LINK_PTHREAD` (Default: ON):
Links to the `pthread` library on unix targets.
Links platform threads library like `pthread` on unix targets.

- `SENTRY_BUILD_FORCE32` (Default: OFF):
Forces cross-compilation from 64-bit host to 32-bit target. Only has an effect on Linux.
Expand Down

0 comments on commit f75ae73

Please sign in to comment.