set(BIN_NAME uos-recovery-gui)

find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5PrintSupport REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(DtkCMake REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(PolkitQt5-1 REQUIRED)

pkg_check_modules(DtkWidget REQUIRED dtkwidget)

include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(.)

aux_source_directory(${GUI_DIR} GUI_SRCS)
aux_source_directory(${GUI_DIR}/backup/ GUI_SRCS)
aux_source_directory(${GUI_DIR}/restore/ GUI_SRCS)
aux_source_directory(${GUI_DIR}/advanced/ GUI_SRCS)
aux_source_directory(${GUI_DIR}/common/ GUI_SRCS)
aux_source_directory(${UTILS_DIR} GUI_SRCS)

add_executable(${BIN_NAME}
        ${GUI_SRCS}
        resources.qrc
        )

target_include_directories(${BIN_NAME} PUBLIC
        ${DtkWidget_INCLUDE_DIRS}
        )


target_link_libraries(${BIN_NAME}
        ${Qt5Widgets_LIBRARIES}
        ${Qt5DBus_LIBRARIES}
        ${DtkWidget_LIBRARIES}
        Qt5::PrintSupport
        PolkitQt5-1::Agent
        )

# 生成翻译
## 设置QT语言cmake模块
find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)

## 通过源代码生成ts文件
set(CREATE_TS_DIR
    ${CMAKE_SOURCE_DIR}/src/uos-recovery-gui
)

find_program(LUPDATE_EXECUTABLE lupdate)
execute_process(
    COMMAND ${LUPDATE_EXECUTABLE} -source-language en
    -no-obsolete
    -recursive ${CREATE_TS_DIR}
    -ts ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui.ts)

execute_process(
        COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/translate_gui_unfinised.py ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui.ts
        ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui_en_US.ts)
#execute_process(
#        COMMAND cp -rf ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui.ts
#        ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui_en_US.ts)

## 获取ts源文件
file(GLOB INSTALLER_TRANSLATION_TS
    ${CMAKE_SOURCE_DIR}/translations/gui/uos-recovery-gui*.ts)

# generate qm
execute_process(COMMAND bash "${CMAKE_SOURCE_DIR}/translate_generation.sh"
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

if (CMAKE_BUILD_TYPE MATCHES Debug)
    add_definitions("-DDI_I18N_GUI_DIR_ENV=\"${CMAKE_SOURCE_DIR}/translations/gui\"")
else()
    add_definitions("-DDI_I18N_GUI_DIR_ENV=\"/usr/share/uos-recovery/translations/gui\"")
endif()

#install

# bin
install(TARGETS ${BIN_NAME}
        DESTINATION /usr/bin/)

#translations
# desktop
file(GLOB DESKTOP_QM_FILES "${CMAKE_SOURCE_DIR}/translations/desktop/*.qm")
install(FILES ${DESKTOP_QM_FILES}
        DESTINATION /usr/share/uos-recovery/translations/desktop/)
# gui
file(GLOB QM_FILES "${CMAKE_SOURCE_DIR}/translations/gui/*.qm")
install(FILES ${QM_FILES}
        DESTINATION /usr/share/uos-recovery/translations/gui/)
#icon
install(FILES resources/icons/uos-recovery.svg
        DESTINATION /usr/share/icons/hicolor/scalable/apps)

#desktop
# desktop
install(FILES uos-recovery.desktop DESTINATION /usr/share/applications)

