Skip to content

Commit

Permalink
feat: Expose sentry-native version to CMake project and package (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill authored Jan 18, 2021
1 parent 8617d85 commit 8a02abf
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ else()
cmake_minimum_required (VERSION 3.10)
endif()

project(Sentry-Native LANGUAGES C CXX ASM)
#read sentry-native version
file(READ "include/sentry.h" _SENTRY_HEADER_CONTENT)
string(REGEX MATCH "#define SENTRY_SDK_VERSION \"([0-9\.]+)\"" _SENTRY_VERSION_MATCH "${_SENTRY_HEADER_CONTENT}")
set(SENTRY_VERSION "${CMAKE_MATCH_1}")
unset(_SENTRY_HEADER_CONTENT)
unset(_SENTRY_VERSION_MATCH)

project(Sentry-Native
LANGUAGES C CXX ASM
VERSION ${SENTRY_VERSION}
)

set(SENTRY_MAIN_PROJECT OFF)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
Expand Down Expand Up @@ -444,6 +454,18 @@ include(CMakePackageConfigHelpers)
configure_package_config_file(sentry-config.cmake.in sentry-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")

# generate package version file
# use semver behavior: SameMinorVersion for 0.x.x, SameMajorVersion for 1.x.x or greater
if(${PROJECT_VERSION_MAJOR} EQUAL 0)
set(_SENTRY_VERSION_COMPATIBILITY SameMinorVersion)
else()
message(AUTHOR_WARNING "sentry-native reaches 1.0.0, simplify this code")
set(_SENTRY_VERSION_COMPATIBILITY SameMajorVersion)
endif()
write_basic_package_version_file(sentry-config-version.cmake
VERSION ${SENTRY_VERSION}
COMPATIBILITY ${_SENTRY_VERSION_COMPATIBILITY})

sentry_install(TARGETS sentry EXPORT sentry
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
Expand All @@ -452,7 +474,10 @@ sentry_install(TARGETS sentry EXPORT sentry
)
sentry_install(EXPORT sentry NAMESPACE sentry:: FILE sentry-targets.cmake
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")
sentry_install(FILES "${PROJECT_BINARY_DIR}/sentry-config.cmake"
sentry_install(
FILES
"${PROJECT_BINARY_DIR}/sentry-config.cmake"
"${PROJECT_BINARY_DIR}/sentry-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}")
if(WIN32 AND MSVC AND SENTRY_BUILD_SHARED_LIBS)
sentry_install(FILES $<TARGET_PDB_FILE:sentry>
Expand Down

0 comments on commit 8a02abf

Please sign in to comment.