set(BIN_NAME uos-recovery-tool)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt6 REQUIRED Widgets Core DBus PrintSupport)

#find_package(Qt5Core REQUIRED)
#find_package(Qt5PrintSupport REQUIRED)
find_package(Dtk6CMake REQUIRED)
#find_package(Qt5DBus REQUIRED)

include_directories(${CMAKE_SOURCE_DIR}/src)
aux_source_directory(${RECOVERYTOOL_DIR} SRC_FILES)

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

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

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

execute_process(
        COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/translate_tool_unfinised.py ${CMAKE_SOURCE_DIR}/translations/tool/uos-recovery-tool.ts
        ${CMAKE_SOURCE_DIR}/translations/tool/uos-recovery-tool_en_US.ts)
#execute_process(
#        COMMAND cp -rf ${CMAKE_SOURCE_DIR}/translations/tool/uos-recovery-tool.ts
#        ${CMAKE_SOURCE_DIR}/translations/tool/uos-recovery-tool_en_US.ts)

## 获取ts源文件
file(GLOB INSTALLER_TRANSLATION_TS
        ${CMAKE_SOURCE_DIR}/translations/tool/uos-recovery-tool*.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_TOOL_DIR_ENV=\"${CMAKE_SOURCE_DIR}/translations/tool\"")
else()
    add_definitions("-DDI_I18N_TOOL_DIR_ENV=\"/usr/share/uos-recovery/translations/tool\"")
endif()

# tool
file(GLOB QM_FILES "${CMAKE_SOURCE_DIR}/translations/tool/*.qm")
install(FILES ${QM_FILES}
        DESTINATION /usr/share/uos-recovery/translations/tool/)

## 源文件
add_executable(${BIN_NAME}
        ${SRC_FILES}
        main.cpp)

target_link_libraries(${BIN_NAME}
        ${Qt6Core_LIBRARIES}
        ${Qt6DBus_LIBRARIES}
        Qt6::PrintSupport
        )

## 安装目标文件
install(TARGETS ${BIN_NAME}
        DESTINATION /usr/bin/)
