Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shared library support and fix library install path on Linux #815

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [Unreleased]
### Features
* Add a build_shared_library CMake option
### Bug Fixes
* Fix library installation path on Linux distributions that use lib64

## [9.97.0] - 25-12-2020
### Features
* Support for QNX OS
Expand Down
35 changes: 28 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ 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")
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)

Expand All @@ -52,18 +55,36 @@ 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
ARCHIVE DESTINATION lib)
easyloggingpp_shared
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

export(PACKAGE ${PROJECT_NAME})
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down