cmake_minimum_required(VERSION 3.5)

project(xrview VERSION 1.0 LANGUAGES CXX)

option(WITH_AUTO_DOWNLOAD "Makes the Application automatically download Saxon-HE and xslt-styleshets if none are configured." ON)

find_package(Qt6 REQUIRED COMPONENTS Widgets WebEngineWidgets Xml LinguistTools)

if(WITH_AUTO_DOWNLOAD)
	find_package(KF6Archive ${KF_VERSION})
	add_definitions(-DWITH_AUTO_DOWNLOAD)
endif()

qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES en de)

# Be sure to show deprecation messages and disable deprecated Qt5 code in Qt-headers
add_definitions(-DQT_DEPRECATED_WARNINGS_SINCE=0x70000 -DQT_DISABLE_DEPRECATED_BEFORE=0x50f02)

set(PROJECT_SOURCES
        src/main.cpp
        src/xrcontrol.cpp
        src/xrechnung.cpp
        src/xrwidget.cpp
        src/xrvsetup.cpp
        src/mainwindow.cpp
        src/mainwindow.ui
)

# For future use, needs to be added to project sources
set(RESOURCES
    resources/xrview.qrc
)

qt_add_executable(xrview
    ${PROJECT_SOURCES}
)

target_link_libraries(xrview PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::WebEngineWidgets
    Qt${QT_VERSION_MAJOR}::Xml
)

if(WITH_AUTO_DOWNLOAD)
	if( ${KF6Archive_FOUND})
	    target_link_libraries(xrview PRIVATE KF6::Archive)
	endif()
endif()

set(XRVIEW_TS_FILES resources/xrview_de.ts resources/xrview_en.ts)
set_source_files_properties(${XRVIEW_TS_FILES} PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/resources)
qt_add_translations(xrview TS_FILES ${XRVIEW_TS_FILES})

install(TARGETS xrview DESTINATION bin
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)


set (XDG_APPS_INSTALL_DIR "share/applications" CACHE STRING "The XDG apps dir")

install(FILES  resources/xrview.appdata.xml DESTINATION share/metainfo RENAME de.volle-kraft-voraus.xrview.appdata.xml)

install(FILES resources/xrview.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} RENAME de.volle-kraft-voraus.xrview.desktop)
# ecm_install_icons( ICONS resources/64-apps-xrview.png DESTINATION share/icons)

