cmake_minimum_required(VERSION 3.21)
project(Lorenz VERSION 1.2.1 LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.4 REQUIRED COMPONENTS Widgets Network)
# WIN32: a windowed program, so Send to and shortcuts open no console window.
qt_add_executable(lorenz-desktop WIN32 desktop/main.cpp)
if(WIN32)
    target_sources(lorenz-desktop PRIVATE desktop/lorenz.rc)
endif()
target_link_libraries(lorenz-desktop PRIVATE Qt6::Widgets Qt6::Network)
target_compile_definitions(lorenz-desktop PRIVATE LORENZ_VERSION="${PROJECT_VERSION}")
qt_add_resources(lorenz-desktop interface PREFIX "/" BASE assets FILES assets/chevron.png assets/chevron-dark.png)
install(TARGETS lorenz-desktop RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES assets/lorenz.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
if(UNIX AND NOT APPLE)
    set(LORENZ_CLI_BINARY "${PROJECT_SOURCE_DIR}/target/release/lorenz" CACHE FILEPATH
        "Path to the separately built Rust CLI")
    install(PROGRAMS "${LORENZ_CLI_BINARY}" DESTINATION ${CMAKE_INSTALL_BINDIR})
    install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DATADIR}/licenses/lorenz)
    install(FILES desktop/radialwheel.h desktop/i18n.h DESTINATION ${CMAKE_INSTALL_DATADIR}/lorenz/desktop)
    install(FILES integrations/kwin/CMakeLists.txt integrations/kwin/plugin.cpp integrations/kwin/metadata.json
        DESTINATION ${CMAKE_INSTALL_DATADIR}/lorenz/integrations/kwin)
    install(PROGRAMS scripts/build-kwin.sh scripts/install-kwin.sh scripts/uninstall-kwin.sh scripts/kwin-hook.sh
        DESTINATION ${CMAKE_INSTALL_DATADIR}/lorenz/scripts)
    configure_file(packaging/linux/install-integration.cmake.in
        "${CMAKE_CURRENT_BINARY_DIR}/install-integration.cmake" @ONLY)
    install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/install-integration.cmake")
endif()
include(CTest)
if(BUILD_TESTING)
    qt_add_executable(lorenz-wheel-test tests/radialwheel.cpp)
    target_link_libraries(lorenz-wheel-test PRIVATE Qt6::Widgets)
    add_test(NAME radial-wheel COMMAND lorenz-wheel-test)
    set_tests_properties(radial-wheel PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
    qt_add_executable(lorenz-dropwheel-test tests/dropwheel.cpp)
    target_link_libraries(lorenz-dropwheel-test PRIVATE Qt6::Widgets)
    add_test(NAME drop-wheel COMMAND lorenz-dropwheel-test)
    set_tests_properties(drop-wheel PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
    qt_add_executable(lorenz-update-test tests/update.cpp)
    target_link_libraries(lorenz-update-test PRIVATE Qt6::Widgets Qt6::Network)
    add_test(NAME update-check COMMAND lorenz-update-test)
    set_tests_properties(update-check PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
endif()
