add_subdirectory(grantlee_plugin)

configure_file(config-kcalutils.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kcalutils.h)

set(kcalutils_SRCS
  htmlexport.cpp
  icaldrag.cpp
  incidenceformatter.cpp
  recurrenceactions.cpp
  stringify.cpp
  vcaldrag.cpp
  dndfactory.cpp
  grantleeki18nlocalizer.cpp
  grantleetemplatemanager.cpp
  qtresourcetemplateloader.cpp
)
ecm_qt_declare_logging_category(kcalutils_SRCS HEADER kcalutils_debug.h IDENTIFIER KCALUTILS_LOG CATEGORY_NAME org.kde.pim.kcalutils
        OLD_CATEGORY_NAMES log_kcalutils
        DESCRIPTION "kcalutils (pim lib)" EXPORT KCALUTILS)


kconfig_add_kcfg_files(kcalutils_SRCS htmlexportsettings.kcfgc)

ki18n_wrap_ui(kcalutils_SRCS recurrenceactionsscopewidget.ui)

qt5_add_resources(kcalutils_SRCS templates.qrc)

add_library(KF5CalendarUtils ${kcalutils_SRCS})

generate_export_header(KF5CalendarUtils BASE_NAME kcalutils)

add_library(KF5::CalendarUtils ALIAS KF5CalendarUtils)

target_include_directories(KF5CalendarUtils INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/KCalUtils;${KF5_INCLUDE_INSTALL_DIR}/KCalUtils/kcalutils>")
target_include_directories(KF5CalendarUtils PUBLIC "$<BUILD_INTERFACE:${KCalUtils_SOURCE_DIR}/src;${KCalUtils_BINARY_DIR}/src>")

target_link_libraries(KF5CalendarUtils
PUBLIC
  Qt5::Widgets
  KF5::CalendarCore
  KF5::CoreAddons
  KF5::ConfigGui
PRIVATE
  KF5::WidgetsAddons
  KF5::IconThemes
  KF5::I18n
  KF5::IdentityManagement
  KF5::Codecs
  Grantlee5::Templates
)

set_target_properties(KF5CalendarUtils PROPERTIES
    VERSION ${KCALUTILS_VERSION_STRING}
    SOVERSION ${KCALUTILS_SOVERSION}
    EXPORT_NAME CalendarUtils
)

install(TARGETS KF5CalendarUtils EXPORT KF5CalendarUtilsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS})

########### Generate Headers ###############
ecm_generate_headers(KCalUtils_CamelCase_HEADERS
  HEADER_NAMES
  DndFactory
  HtmlExport
  ICalDrag
  IncidenceFormatter
  RecurrenceActions
  Stringify
  VCalDrag
  PREFIX KCalUtils
  REQUIRED_HEADERS KCalUtils_HEADERS
)

########### install files ###############

install(FILES
  ${CMAKE_CURRENT_SOURCE_DIR}/includes/HTMLExportSettings
  ${CMAKE_CURRENT_BINARY_DIR}/kcalutils_export.h
  ${CMAKE_CURRENT_BINARY_DIR}/htmlexportsettings.h
  ${KCalUtils_HEADERS}
  DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalUtils/kcalutils
  COMPONENT Devel
)

install(FILES
  ${KCalUtils_CamelCase_HEADERS}
  DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalUtils/KCalUtils/
  COMPONENT Devel
)

ecm_qt_install_logging_categories(EXPORT KCALUTILS FILE kcalutils.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})

ecm_generate_pri_file(BASE_NAME KCalUtils LIB_NAME KF5CalendarUtils DEPS "ConfigGui CalendarCore CoreAddons" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KCalUtils)
install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
