Skip to content

Commit

Permalink
Add a build_shared_lib option (fix #484)
Browse files Browse the repository at this point in the history
Use the major version number as the SOVERSION.
  • Loading branch information
musicinmybrain committed Aug 27, 2022
1 parent afe0104 commit e092ecc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 24 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()

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

0 comments on commit e092ecc

Please sign in to comment.