-
-
Save Anticom/09097c32544cb73a70d1ef6aa4646cf4 to your computer and use it in GitHub Desktop.
Working FindLog4cplus.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#.rst: | |
# FindLog4cplus | |
# ------- | |
# | |
# Finds the log4cplus library | |
# | |
# This will define the following variables:: | |
# | |
# LOG4CPLUS_FOUND - True if the system has the log4cplus library | |
# LOG4CPLUS_LIBRARIES - Path to log4cplus libraries | |
# LOG4CPLUS_INCLUDE_DIR - Path to log4cplus include directory | |
# LOG4CPLUS_DEFINITIONS - Additional definitions needed in order to compile log4cplus | |
# LOG4CPLUS_VERSION - The version of the log4cplus library which was found | |
# LOG4CPLUS_VERSION_STRING - The version in legacy format | |
# Try to use pkg-config | |
find_package(PkgConfig QUIET) | |
pkg_check_modules(PC_LOG4CPLUS QUIET log4cplus) | |
# Locate include directory | |
find_path(LOG4CPLUS_INCLUDE_DIR | |
NAMES | |
log4cplus/logger.h | |
PATHS | |
${PC_LOG4CPLUS_INCLUDE_DIRS} | |
) | |
# Locate library | |
# TODO how to configure choosability between shared / static | |
find_library(LOG4CPLUS_LIBRARY | |
NAMES | |
log4cplus | |
PATHS | |
${PC_LOG4CPLUS_LIBRARY_DIRS} | |
) | |
# Set version | |
set(LOG4CPLUS_VERSION ${PC_LOG4CPLUS_VERSION}) | |
# Handle std args | |
include(FindPackageHandleStandardArgs) | |
find_package_handle_standard_args(LOG4CPLUS | |
FOUND_VAR | |
LOG4CPLUS_FOUND | |
REQUIRED_VARS | |
LOG4CPLUS_LIBRARY | |
LOG4CPLUS_INCLUDE_DIR | |
VERSION_VAR | |
LOG4CPLUS_VERSION | |
) | |
# If pkg-config failed to find version, parse it from version header | |
if("${LOG4CPLUS_VERSION}" STREQUAL "") | |
set(LOG4CPLUS_VERSION_HEADER_FILE "${LOG4CPLUS_INCLUDE_DIR}/log4cplus/version.h") | |
if(EXISTS "${LOG4CPLUS_VERSION_HEADER_FILE}") | |
file(STRINGS | |
"${LOG4CPLUS_VERSION_HEADER_FILE}" | |
LOG4CPLUS_VERSION_HEADER_CONTENTS | |
REGEX "[0-9]+, [0-9]+, [0-9]+") | |
if(NOT "${LOG4CPLUS_VERSION_HEADER_CONTENTS}" STREQUAL "") | |
list(GET LOG4CPLUS_VERSION_HEADER_CONTENTS 0 LOG4CPLUS_VERSION_HEADER_CONTENTS) | |
string(REGEX MATCH "([0-9]+), ([0-9]+), ([0-9]+)" | |
LOG4CPLUS_VERSION_HEADER_VERSION "${LOG4CPLUS_VERSION_HEADER_CONTENTS}") | |
set(LOG4CPLUS_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") | |
endif() | |
endif() | |
endif() | |
# Set exposed variables | |
if(LOG4CPLUS_FOUND) | |
set(LOG4CPLUS_LIBRARIES ${LOG4CPLUS_LIBRARY}) | |
set(LOG4CPLUS_INCLUDE_DIRS ${LOG4CPLUS_INCLUDE_DIR}) | |
set(LOG4CPLUS_DEFINITIONS ${PC_LOG4CPLUS_CFLAGS_OTHER}) | |
endif() | |
# Mark certain entries as advanced in the cache | |
mark_as_advanced( | |
LOG4CPLUS_INCLUDE_DIR | |
LOG4CPLUS_LIBRARY | |
) | |
# compatibility variables | |
set(LOG4CPLUS_VERSION_STRING ${LOG4CPLUS_VERSION}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment