add_subdirectory(icons)

include_directories(${CMAKE_BINARY_DIR}) # for version.h generated by cmake
include_directories(${CMAKE_SOURCE_DIR}/part) # for part's interface.h
add_executable(ark)

target_sources(ark PRIVATE
    batchextract.cpp
    main.cpp
    mainwindow.cpp
    welcomescreen.cpp
    ark.qrc
   )

ecm_qt_declare_logging_category(ark
                                HEADER ark_debug.h
                                IDENTIFIER ARK
				CATEGORY_NAME ark.main DESCRIPTION "Ark Main" EXPORT ARK)


ki18n_wrap_ui(ark
    welcomescreen.ui)

# For Mac and Windows.
file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/*-apps-ark.png")

include(ECMAddAppIcon)
ecm_add_app_icon(ark_SRCS ICONS ${ICONS_SRCS})


target_link_libraries(ark
    kerfuffle
    KF5::Crash
    KF5::DBusAddons
    KF5::KIOFileWidgets
    KF5::Parts)

# we provide our own Info.plist containing a simple "we open anything" instruction.
if(APPLE)
    # own plist template
    set_target_properties (ark PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/MacOSXBundleInfo.plist.in)

    # the MacOSX bundle display name property (CFBundleDisplayName) is not currently supported by cmake,
    # so has to be set for all targets in this cmake file
    set(MACOSX_BUNDLE_DISPLAY_NAME Ark)
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER "org.kde.Ark")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Ark")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_DISPLAY_NAME "Ark")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_INFO_STRING "Ark - KDE Archiving Tool")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_LONG_VERSION_STRING "Ark ${RELEASE_SERVICE_VERSION}")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_SHORT_VERSION_STRING "${RELEASE_SERVICE_VERSION}")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_BUNDLE_VERSION "${RELEASE_SERVICE_VERSION}")
    set_target_properties(ark PROPERTIES MACOSX_BUNDLE_COPYRIGHT "1997-2017, The Ark Developers")
endif()

# Remove duplicate mimetypes from list of supported formats.
list(REMOVE_DUPLICATES SUPPORTED_ARK_MIMETYPES)

configure_file(
            ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.ark.desktop.cmake
            ${CMAKE_CURRENT_BINARY_DIR}/org.kde.ark.desktop
)

configure_file(
            ${CMAKE_CURRENT_SOURCE_DIR}/ark_dndextract.desktop.cmake
            ${CMAKE_CURRENT_BINARY_DIR}/ark_dndextract.desktop
)

install(TARGETS ark  ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.ark.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.kde.ark.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR})

############ ark_extract_here plugin ###############

set(extracthere_SRCS batchextract.cpp extractHereDndPlugin.cpp ark_debug.cpp)

kcoreaddons_add_plugin(extracthere
    SOURCES ${extracthere_SRCS}
    INSTALL_NAMESPACE kf5/kio_dnd)

kcoreaddons_desktop_to_json(extracthere ${CMAKE_CURRENT_BINARY_DIR}/ark_dndextract.desktop DEFAULT_SERVICE_TYPE)

target_link_libraries(extracthere kerfuffle KF5::KIOWidgets KF5::KIOFileWidgets)

# compressfileitemaction plugin

kcoreaddons_add_plugin(compressfileitemaction
    SOURCES compressfileitemaction.cpp
    JSON compressfileitemaction.json
    INSTALL_NAMESPACE "kf5/kfileitemaction")

target_link_libraries(compressfileitemaction
    kerfuffle
    KF5::I18n
    KF5::KIOWidgets)

# extractfileitemaction plugin

kcoreaddons_add_plugin(extractfileitemaction
    SOURCES extractfileitemaction.cpp batchextract.cpp ${CMAKE_CURRENT_BINARY_DIR}/ark_debug.cpp
    JSON extractfileitemaction.json
    INSTALL_NAMESPACE "kf5/kfileitemaction")

target_link_libraries(extractfileitemaction
    kerfuffle
    KF5::I18n
    KF5::KIOWidgets
    KF5::KIOFileWidgets)
