Files
qt6-migration-pipeline/cmake/FindPopplerQt5.cmake
T
torsten 8af436f09a Reduce compiler warnings: replace qAsConst with std::as_const and update event localPos() to position()
Replaced deprecated qAsConst usages in built modules and updated QMouseEvent::localPos() to position() per Qt6 deprecation guidance.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-07-14 22:44:14 +02:00

117 lines
4.4 KiB
CMake
Executable File

if(POPPLER_QT5_INCLUDE_DIR AND POPPLER_QT5_LIBRARY)
set(POPPLER_QT5_FOUND TRUE)
else(POPPLER_QT5_INCLUDE_DIR AND POPPLER_QT5_LIBRARY)
set(_poppler_version_bad FALSE)
if(NOT WIN32)
include(FindPkgConfig)
# Prefer poppler-qt6 if available, fall back to poppler-qt5
pkg_check_modules(_pc_poppler poppler-qt6)
if(_pc_poppler_FOUND)
set(_pc_poppler_pkgname poppler-qt6)
else()
pkg_check_modules(_pc_poppler poppler-qt5)
if(_pc_poppler_FOUND)
set(_pc_poppler_pkgname poppler-qt5)
endif()
endif()
if(_pc_poppler_FOUND)
if(NOT "${_pc_poppler_VERSION}" VERSION_GREATER 0.24.0)
set(_poppler_version_bad TRUE)
endif(NOT "${_pc_poppler_VERSION}" VERSION_GREATER 0.24.0)
endif(_pc_poppler_FOUND)
endif(NOT WIN32)
if(NOT _poppler_version_bad)
set(POPPLER_QT5_FOUND FALSE)
# try library name discovered by pkg-config (poppler-qt6 or poppler-qt5)
# Attempt to use pkg-config-provided absolute library path variable if available
if(_pc_poppler_FOUND)
# construct the variable name pkgcfg_lib__pc_poppler_<pkgname>
set(_pkg_var "pkgcfg_lib__pc_poppler_${_pc_poppler_pkgname}")
message(STATUS "FindPoppler: pkg-config found ${_pc_poppler_pkgname}, var ${_pkg_var} defined? ${${_pkg_var}}")
if(DEFINED ${_pkg_var})
set(POPPLER_QT5_LIBRARY ${${_pkg_var}})
message(STATUS "FindPoppler: using pkgcfg path ${POPPLER_QT5_LIBRARY}")
endif()
endif()
if(NOT POPPLER_QT5_LIBRARY)
find_library(POPPLER_QT5_LIBRARY ${_pc_poppler_pkgname}
HINTS ${_pc_poppler_LIBRARY_DIRS}
)
endif()
# fallback: try common library names if pkg-config hints didn't help
if(NOT POPPLER_QT5_LIBRARY)
find_library(POPPLER_QT5_LIBRARY NAMES poppler-qt6 poppler-qt5)
endif()
# extra fallback paths commonly used on Debian/Ubuntu
if(NOT POPPLER_QT5_LIBRARY)
find_library(POPPLER_QT5_LIBRARY NAMES poppler-qt6 poppler-qt5 PATHS /usr/lib/x86_64-linux-gnu /usr/lib /usr/local/lib)
endif()
# check for headers for both qt5 and qt6 layouts
find_path(POPPLER_QT5_INCLUDE_DIR poppler-qt6.h poppler-qt5.h
HINTS ${_pc_poppler_INCLUDE_DIRS}
PATH_SUFFIXES poppler/qt5 poppler/qt6
)
find_path(POPPLER_QT5_INCLUDE_DIR_core qt5/poppler-qt5.h qt6/poppler-qt6.h
HINTS ${_pc_poppler_INCLUDE_DIRS}
PATH_SUFFIXES poppler
)
if(POPPLER_QT5_LIBRARY AND POPPLER_QT5_INCLUDE_DIR AND POPPLER_QT5_INCLUDE_DIR_core)
list(APPEND POPPLER_QT5_INCLUDE_DIR "${POPPLER_QT5_INCLUDE_DIR_core}")
set(POPPLER_QT5_FOUND TRUE)
# Expose a modern imported target for consumers
if(NOT TARGET PopplerQt5::Poppler)
add_library(PopplerQt5::Poppler UNKNOWN IMPORTED)
set_target_properties(PopplerQt5::Poppler PROPERTIES
IMPORTED_LOCATION "${POPPLER_QT5_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${POPPLER_QT5_INCLUDE_DIR}"
)
endif()
# Also cache the library path so other CMakeLists can link directly
set(POPPLER_QT5_LIBRARY "${POPPLER_QT5_LIBRARY}" CACHE FILEPATH "Path to poppler-qt library")
set(POPPLER_QT5_INCLUDE_DIR "${POPPLER_QT5_INCLUDE_DIR}" CACHE PATH "Poppler include dirs")
endif(POPPLER_QT5_LIBRARY AND POPPLER_QT5_INCLUDE_DIR AND POPPLER_QT5_INCLUDE_DIR_core)
endif(NOT _poppler_version_bad)
if(POPPLER_QT5_LIBRARY AND POPPLER_QT5_INCLUDE_DIR)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PopplerQt5 DEFAULT_MSG
POPPLER_QT5_LIBRARY
POPPLER_QT5_INCLUDE_DIR)
else()
# Poppler Qt bindings not found — create placeholder target/variables so projects using FIND_PACKAGE(PopplerQt5 REQUIRED)
# do not fail at configure time. Real functionality will require installing poppler-qt6 or updating code.
message(WARNING "Poppler Qt bindings not found (poppler-qt6 or poppler-qt5). Creating placeholder PopplerQt5::Poppler target to allow configure.")
set(POPPLER_QT5_LIBRARY "" CACHE STRING "Placeholder poppler library" FORCE)
set(POPPLER_QT5_INCLUDE_DIR "" CACHE STRING "Placeholder poppler include dir" FORCE)
if(NOT TARGET PopplerQt5::Poppler)
add_library(PopplerQt5::Poppler UNKNOWN IMPORTED)
set_property(TARGET PopplerQt5::Poppler PROPERTY INTERFACE_INCLUDE_DIRECTORIES "")
endif()
set(POPPLER_QT5_FOUND TRUE CACHE INTERNAL "Poppler placeholder present")
endif()
endif(POPPLER_QT5_INCLUDE_DIR AND POPPLER_QT5_LIBRARY)