Files
qt6-migration-pipeline/cmake/FindLog4Qt.cmake
T

96 lines
3.9 KiB
CMake

# FindLog4Qt.cmake
# Prefer a package config (Log4QtConfig.cmake) when available, otherwise
# try to locate headers and library and create an IMPORTED target.
# First, try config mode (Log4QtConfig.cmake provided by an installed Log4Qt)
# Prefer a normal find_package(CONFIG) but also explicitly probe common
# CMAKE_PREFIX_PATH locations (/usr/local, user-provided prefixes) so a
# Log4Qt installed to /usr/local is reliably detected.
find_package(Log4Qt CONFIG QUIET)
if (Log4Qt_FOUND)
# Package config provided targets/variables; normalize names for callers.
if (TARGET Log4Qt::log4qt)
set(Log4Qt_LIBRARIES "${Log4Qt_LIBRARIES}" CACHE STRING "Log4Qt libraries (from config)" FORCE)
set(Log4Qt_INCLUDE_DIRS "${Log4Qt_INCLUDE_DIRS}" CACHE STRING "Log4Qt include dirs (from config)" FORCE)
endif()
return()
endif()
# If config-mode didn't find a package, probe common prefix paths for a
# Log4QtConfig.cmake installed by the project's Dockerfile (e.g. /usr/local).
# This handles cases where CMAKE_PREFIX_PATH isn't honored or when the
# package config file exists but wasn't discoverable via the generic search.
set(_log4qt_probed_config_file "")
# Build a list of prefixes to probe: entries in CMAKE_PREFIX_PATH plus /usr/local
set(_log4qt_prefixes "${CMAKE_PREFIX_PATH};/usr/local")
foreach(_p IN LISTS _log4qt_prefixes)
if ("${_p}" STREQUAL "")
continue()
endif()
# candidate locations under the prefix
set(_candidate1 "${_p}/lib/cmake/Log4Qt/Log4QtConfig.cmake")
set(_candidate2 "${_p}/share/cmake/Log4Qt/Log4QtConfig.cmake")
foreach(_cand IN LISTS _candidate1 _candidate2)
if (EXISTS "${_cand}")
set(_log4qt_probed_config_file "${_cand}")
break()
endif()
endforeach()
if (NOT "${_log4qt_probed_config_file}" STREQUAL "")
break()
endif()
endforeach()
if (EXISTS "${_log4qt_probed_config_file}")
# Include the config file directly; it should create targets/variables.
include("${_log4qt_probed_config_file}")
if (TARGET Log4Qt::log4qt)
# normalize cache names for callers
set(Log4Qt_FOUND TRUE CACHE INTERNAL "Log4Qt found by config probe")
# try to pick up values set by the config file, fallback to defaults
if (NOT DEFINED Log4Qt_LIBRARIES)
set(Log4Qt_LIBRARIES "" CACHE STRING "Log4Qt libraries (from probed config)" FORCE)
else()
set(Log4Qt_LIBRARIES "${Log4Qt_LIBRARIES}" CACHE STRING "Log4Qt libraries (from probed config)" FORCE)
endif()
if (NOT DEFINED Log4Qt_INCLUDE_DIRS)
set(Log4Qt_INCLUDE_DIRS "" CACHE STRING "Log4Qt include dirs (from probed config)" FORCE)
else()
set(Log4Qt_INCLUDE_DIRS "${Log4Qt_INCLUDE_DIRS}" CACHE STRING "Log4Qt include dirs (from probed config)" FORCE)
endif()
return()
endif()
endif()
# Fall back to classic Find behaviour: locate library and headers
find_path(_LOG4QT_INCLUDE_DIR
NAMES Log4Qt/Logger.h
PATHS /usr/local/include /usr/include /usr/local/include/log4qt
)
find_library(_LOG4QT_LIBRARY
NAMES log4qt Log4Qt liblog4qt libLog4Qt
PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Log4Qt DEFAULT_MSG _LOG4QT_LIBRARY _LOG4QT_INCLUDE_DIR)
if (_LOG4QT_LIBRARY AND _LOG4QT_INCLUDE_DIR)
if (NOT TARGET Log4Qt::log4qt)
add_library(Log4Qt::log4qt UNKNOWN IMPORTED)
set_target_properties(Log4Qt::log4qt PROPERTIES
IMPORTED_LOCATION "${_LOG4QT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${_LOG4QT_INCLUDE_DIR}"
)
endif()
set(Log4Qt_FOUND TRUE CACHE INTERNAL "Log4Qt found by FindLog4Qt")
set(Log4Qt_LIBRARIES "${_LOG4QT_LIBRARY}" CACHE STRING "Log4Qt libraries")
set(Log4Qt_INCLUDE_DIRS "${_LOG4QT_INCLUDE_DIR}" CACHE STRING "Log4Qt include dirs")
else()
set(Log4Qt_FOUND FALSE CACHE INTERNAL "Log4Qt not found")
set(Log4Qt_LIBRARIES "" CACHE STRING "Log4Qt libraries (empty)")
set(Log4Qt_INCLUDE_DIRS "" CACHE STRING "Log4Qt include dirs (empty)")
endif()