From e092eccd268f3e372c56db793345086271d78109 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Sat, 27 Aug 2022 09:16:31 -0400 Subject: [PATCH] Add a build_shared_lib option (fix #484) Use the major version number as the SOVERSION. --- CHANGELOG.md | 2 ++ CMakeLists.txt | 29 ++++++++++++++++++++++++----- README.md | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59265222a..dd64ba320 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +### Features + * Add a build_shared_library CMake option ### Bug Fixes * Fix library installation path on Linux distributions that use lib64 diff --git a/CMakeLists.txt b/CMakeLists.txt index 314c9152f..507e84b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ endmacro() option(test "Build all tests" OFF) option(build_static_lib "Build easyloggingpp as a static library" OFF) +option(build_shared_lib "Build easyloggingpp as a shared library" OFF) option(lib_utc_datetime "Build library with UTC date/time logging" OFF) set(ELPP_MAJOR_VERSION "9") @@ -51,20 +52,38 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/easyloggingpp.pc DESTINATION "${ELPP_P include(CheckIncludeFileCXX) check_include_file_cxx("execinfo.h" HAVE_EXECINFO) if (HAVE_EXECINFO) - add_definitions(-DHAVE_EXECINFO) + add_definitions(-DHAVE_EXECINFO) endif() -if (build_static_lib) +if (build_shared_lib OR build_shared_lib) if (lib_utc_datetime) add_definitions(-DELPP_UTC_DATETIME) endif() require_cpp11() - add_library(easyloggingpp STATIC src/easylogging++.cc) - set_property(TARGET easyloggingpp PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() + +if (build_static_lib) + add_library(easyloggingpp_static STATIC src/easylogging++.cc) + set_target_properties(easyloggingpp_static PROPERTIES + OUTPUT_NAME easyloggingpp + POSITION_INDEPENDENT_CODE ON) + set_property(TARGET easyloggingpp_static PROPERTY POSITION_INDEPENDENT_CODE ON) + + install(TARGETS + easyloggingpp_static + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() +if (build_shared_lib) + add_library(easyloggingpp_shared SHARED src/easylogging++.cc) + set_target_properties(easyloggingpp_shared PROPERTIES + OUTPUT_NAME easyloggingpp + POSITION_INDEPENDENT_CODE ON + SOVERSION "${ELPP_MAJOR_VERSION}" + VERSION "${ELPP_MAJOR_VERSION}.${ELPP_MINOR_VERSION}.${ELPP_PATCH_VERSION}") install(TARGETS - easyloggingpp + easyloggingpp_shared ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() diff --git a/README.md b/README.md index ee3e8f3ca..8ca44b24d 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ Following options are supported by Easylogging++ cmake and you can turn these op * `lib_utc_datetime` - Defines `ELPP_UTC_DATETIME` * `build_static_lib` - Builds static library for Easylogging++ + * `build_shared_lib` - Builds shared library for Easylogging++ With that said, you will still need `easylogging++.cc` file in order to compile. For header only, please check [v9.89](https://github.com/amrayn/easyloggingpp/releases/tag/9.89) and lower.