# KF5 version of the kio_recoll module cmake file.

cmake_minimum_required(VERSION 3.16)
project(kio_recoll)

option(RECOLL_PUBLIC_LIB "Does nothing, kept for compat" 1)

set(KF5_MIN_VERSION "5.0")
set(CMAKE_SKIP_RPATH TRUE)

# Include the Extra-CMake-Modules project
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_MODULE_PATH})

include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(FeatureSummary)

find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS I18n Config KIO Notifications)

## Recoll stuff

set(rcltop ${CMAKE_CURRENT_SOURCE_DIR}/../../../)

include_directories (
  ${CMAKE_SOURCE_DIR}
  ${CMAKE_BINARY_DIR}
  ${rcltop}/common 
  ${rcltop}/internfile 
  ${rcltop}/query 
  ${rcltop}/rcldb 
  ${rcltop}/utils 
)

include_directories (
    ${CMAKE_INSTALL_PREFIX}/include/recoll
)

# Check if running inside a build tree, then use the not yet installed lib. 
foreach(libdir IN ITEMS  ${CMAKE_BINARY_DIR}/../../.libs
                         ${CMAKE_BINARY_DIR}/../../../.libs
                         ${CMAKE_BINARY_DIR}/../../../../.libs
                         ${CMAKE_BINARY_DIR}/../../../../redhat-linux-build
                         $ENV{RECOLL_LIB_DIR}/
                         )
    message(STATUS "TESTING link directory ${libdir}")
    if (EXISTS ${libdir}/librecoll.so)
        message(STATUS "USING link directory ${libdir}")
        link_directories(${CMAKE_INSTALL_PREFIX}/lib ${libdir})
    endif()
endforeach()

add_definitions(
    -DRECOLL_DATADIR="${CMAKE_INSTALL_PREFIX}/share/recoll"
    -DLIBDIR="${CMAKE_INSTALL_PREFIX}/lib"
    -DHAVE_CONFIG_H
)

set(kio_recoll_SRCS kio_recoll.cpp htmlif.cpp dirif.cpp ${rcltop}/qtgui/guiutils.cpp)

add_library(kio_recoll MODULE ${kio_recoll_SRCS})

target_link_libraries(kio_recoll
    recoll
    xapian
    xslt
    xml2
    KF5::KIOCore
    X11
    dl
    z
    pthread
)

install(FILES data/welcome.html	data/help.html
      DESTINATION  ${DATA_INSTALL_DIR}/kio_recoll)

set_target_properties(kio_recoll PROPERTIES OUTPUT_NAME "kio_recoll")
# This is not set on ubuntu focal
set(QT_MAJOR_VERSION 5)
install(TARGETS kio_recoll
      DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf${QT_MAJOR_VERSION}/kio)
