From afe010435d0511363d0255b3ad3afbd423251e44 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Sat, 27 Aug 2022 08:55:09 -0400 Subject: [PATCH 1/2] Use GNUInstallDirs module This fixes installation paths on Linux. For example, the static library is installed to /usr/lib64/ when appropriate. --- CHANGELOG.md | 4 ++++ CMakeLists.txt | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 247463183..59265222a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [Unreleased] +### Bug Fixes + * Fix library installation path on Linux distributions that use lib64 + ## [9.97.0] - 25-12-2020 ### Features * Support for QNX OS diff --git a/CMakeLists.txt b/CMakeLists.txt index 538cc8a0b..314c9152f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,10 @@ set(ELPP_MINOR_VERSION "96") set(ELPP_PATCH_VERSION "7") set(ELPP_VERSION_STRING "${ELPP_MAJOR_VERSION}.${ELPP_MINOR_VERSION}.${ELPP_PATCH_VERSION}") -set(ELPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in") -set(ELPP_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") +include(GNUInstallDirs) + +set(ELPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE PATH "The directory the headers are installed in") +set(ELPP_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) @@ -63,7 +65,7 @@ if (build_static_lib) install(TARGETS easyloggingpp - ARCHIVE DESTINATION lib) + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() export(PACKAGE ${PROJECT_NAME}) From 2a1d339baa48a24d61a91c94b63bd7aaf3ef3a5d Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Sat, 27 Aug 2022 09:16:31 -0400 Subject: [PATCH 2/2] Add a build_shared_lib option (fix #484) Use the major version number as the SOVERSION. --- CHANGELOG.md | 2 ++ CMakeLists.txt | 27 +++++++++++++++++++++++---- README.md | 1 + 3 files changed, 26 insertions(+), 4 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..3bb8c018d 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") @@ -54,17 +55,35 @@ if (HAVE_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.