cmake_minimum_required(VERSION 3.16)
project(kio_recoll)

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

set(KF6_MIN_VERSION "6.0")
set(CMAKE_SKIP_RPATH TRUE)

# Include the Extra-CMake-Modules project
find_package(ECM ${KF6_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(KF6 ${KF6_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 
  ${rcltop}/redhat-linux-build
)

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
                         $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"
)

set(kio_recoll_SRCS kio_recoll.cpp htmlif.cpp dirif.cpp)

add_library(kio_recoll MODULE ${kio_recoll_SRCS})

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

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

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