From 50a7228e3157bd1831e2397bb1073b1f0e22a774 Mon Sep 17 00:00:00 2001 From: Sergei Ilinykh Date: Wed, 1 May 2024 22:00:52 +0300 Subject: [PATCH] Handle translations Qt 6.7 way --- CMakeLists.txt | 29 +++++++++++++++++--- langs/CMakeLists.txt | 63 ++++++++++++++++++++++++++------------------ src/CMakeLists.txt | 4 --- 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c17a6..14d1e43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ # ------------------------------------------------- cmake_minimum_required(VERSION 3.10.0) +set(CMAKE_CXX_STANDARD 17) + set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") include(QtNoteMacro) message(STATUS "Version: QtNote-${QTNOTE_VERSION}") @@ -28,13 +30,34 @@ if (Qt${QT_DEFAULT_MAJOR_VERSION}Widgets_VERSION VERSION_LESS 5.10.0) message(FATAL_ERROR "Minimum supported Qt5 version is 5.10!") endif() -set(CMAKE_CXX_STANDARD 17) - if(UNIX AND NOT (APPLE OR HAIKU)) set(UNIXLIKE ON) endif() -include(GNUInstallDirs) +set(I18N_TRANSLATED_LANGUAGES) +file(GLOB qtnote_TRS "${CMAKE_CURRENT_SOURCE_DIR}/qtnote_*.ts") +foreach(_LANG ${qtnote_TRS}) + get_filename_component(_SHORT_LANG ${_LANG} NAME_WE) + string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG}) + list(APPEND I18N_TRANSLATED_LANGUAGES ${_SHORT_LANG}) +endforeach() +if(Qt${QT_DEFAULT_MAJOR_VERSION}Core_VERSION VERSION_LESS 6.3.0) + include(GNUInstallDirs) + set(CMAKE_AUTOMOC ON) + set(CMAKE_AUTORCC ON) + set(CMAKE_AUTOUIC ON) + if(WIN32 AND CMAKE_RUNTIME_OUTPUT_DIRECTORY STREQUAL "") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() + set(USE_FOLDERS ON) +elseif(Qt${QT_DEFAULT_MAJOR_VERSION}Core_VERSION VERSION_LESS 6.7.0) + qt_standard_project_setup() +else() + qt_standard_project_setup( + I18N_TRANSLATED_LANGUAGES ${I18N_TRANSLATED_LANGUAGES} + I18N_SOURCE_LANGUAGE en + ) +endif() set(APP_NAME qtnote) set(TRANSLATIONSDIR ${CMAKE_INSTALL_FULL_DATADIR}/${APP_NAME}) set(PLUGINSDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${APP_NAME}) diff --git a/langs/CMakeLists.txt b/langs/CMakeLists.txt index 8e34588..4933c69 100644 --- a/langs/CMakeLists.txt +++ b/langs/CMakeLists.txt @@ -3,32 +3,45 @@ file(GLOB qtnote_TRS "${CMAKE_CURRENT_SOURCE_DIR}/qtnote_*.ts") find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS LinguistTools REQUIRED) -set(PROJECT_DIRS -${CMAKE_SOURCE_DIR} -${qtnotexe_SOURCE_DIR} -${libqtnote_SOURCE_DIR} -${plugins_SOURCE_DIR} -) - -#update translations with: make lupdate -add_custom_target(lupdate) -foreach(_LANG ${qtnote_TRS}) - get_filename_component(_SHORT_LANG ${_LANG} NAME_WE) - string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG}) - add_custom_command(TARGET lupdate - PRE_BUILD - COMMAND ${Qt${QT_DEFAULT_MAJOR_VERSION}_LUPDATE_EXECUTABLE} - ARGS -no-obsolete -recursive ${PROJECT_DIRS} -ts ${_LANG} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - VERBATIM +if(Qt${QT_DEFAULT_MAJOR_VERSION}LinguistTools_VERSION VERSION_LESS 6.7.0) + set(PROJECT_DIRS + ${CMAKE_SOURCE_DIR} + ${qtnotexe_SOURCE_DIR} + ${libqtnote_SOURCE_DIR} + ${plugins_SOURCE_DIR} ) -endforeach() -if(WIN32) - set_source_files_properties(${qtnote_TRS} PROPERTIES OUTPUT_LOCATION "${EXECUTABLE_OUTPUT_PATH}/langs") -endif() -qt_add_translation(qtnote_QM ${qtnote_TRS}) + #update translations with: make lupdate + add_custom_target(lupdate) + foreach(_LANG ${qtnote_TRS}) + get_filename_component(_SHORT_LANG ${_LANG} NAME_WE) + string(REPLACE "@" "_" _SHORT_LANG ${_SHORT_LANG}) + add_custom_command(TARGET lupdate + PRE_BUILD + COMMAND ${Qt${QT_DEFAULT_MAJOR_VERSION}_LUPDATE_EXECUTABLE} + ARGS -no-obsolete -recursive ${PROJECT_DIRS} -ts ${_LANG} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + VERBATIM + ) + endforeach() -add_custom_target(build_translations ALL DEPENDS ${qtnote_QM}) + if(WIN32) + set_source_files_properties(${qtnote_TRS} PROPERTIES OUTPUT_LOCATION "${EXECUTABLE_OUTPUT_PATH}/langs") + endif() + qt_add_translation(qtnote_QM ${qtnote_TRS}) -install(FILES ${qtnote_QM} DESTINATION ${TRANSLATIONSDIR} COMPONENT Executable) + add_custom_target(build_translations ALL DEPENDS ${qtnote_QM}) +else() + set(LANGS_SOURCE_TARGETS) + foreach(trg baseintegration gnome kdeintegration spellchecker tomboy macosx) + if(TARGET ${trg}) + list(APPEND LANGS_SOURCE_TARGETS ${trg}) + endif() + endforeach() + qt_add_translations(TARGETS qtnoteexe + SOURCE_TARGETS qtnoteexe qtnote ${LANGS_SOURCE_TARGETS} + TS_FILE_BASE qtnote + TS_FILES ${qtnote_TRS} + QM_FILES_OUTPUT_VARIABLE qtnote_QM) +endif() +add_custom_target(build_translations ALL DEPENDS ${qtnote_QM}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2441352..bd3f753 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,6 @@ cmake_minimum_required(VERSION 3.10.0) include(QtNoteMacro) project(qtnoteexe VERSION ${QTNOTE_VERSION} LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - if(WIN32) set(WINRESFILE "win/qtnote.rc") endif()