build: macos, copy translations post build into the bundle no need to install them
This commit is contained in:
committed by
Chris Rizzitello
parent
82c18e26e5
commit
aa11dc94ba
@ -27,23 +27,34 @@ qt_create_translation(TRS ${CMAKE_SOURCE_DIR}/src ${${CMAKE_PROJECT_NAME}_TRS} O
|
||||
#ensure that the targets are built always
|
||||
add_custom_target(app_translations ALL DEPENDS ${TRS})
|
||||
|
||||
# install our translations
|
||||
install(FILES ${TRS} DESTINATION ${CMAKE_INSTALL_I18N_DIR})
|
||||
if (NOT APPLE)
|
||||
# install our translations
|
||||
install(FILES ${TRS} DESTINATION ${CMAKE_INSTALL_I18N_DIR})
|
||||
elseif(APPLE)
|
||||
#when making the bundle copy our translation into the bundle
|
||||
set(BUNDLE_TR_DIR $<TARGET_BUNDLE_CONTENT_DIR:${CMAKE_PROJECT_PROPER_NAME}>/MacOS/translations)
|
||||
|
||||
if(APPLE)
|
||||
# find the qt translation files not deployed by macdeployqt
|
||||
# find the qt translation files needed to copy into the bundle
|
||||
get_target_property(lupdate_executable Qt6::lupdate IMPORTED_LOCATION)
|
||||
get_filename_component(_qt_bin_dir "${lupdate_executable}" DIRECTORY)
|
||||
file(REAL_PATH "${_qt_bin_dir}/../" QT_ROOT_DIR)
|
||||
find_file(_QT_QM_FILE NAMES qtbase_en.qm PATHS ${QT_ROOT_DIR} PATH_SUFFIXES "translations" "share/qt/translations" REQUIRED)
|
||||
get_filename_component(MAC_QT_LANG_PATH "${_QT_QM_FILE}" DIRECTORY)
|
||||
|
||||
# install each lang file and rename to the same name
|
||||
# rename does not work with a list so foreach is used instead
|
||||
install(FILES ${MAC_QT_LANG_PATH}/qtbase_en.qm DESTINATION ${CMAKE_INSTALL_I18N_DIR} RENAME qt_en.qm)
|
||||
add_custom_command(
|
||||
TARGET app_translations POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${BUNDLE_TR_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/*.qm" ${BUNDLE_TR_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MAC_QT_LANG_PATH}/qtbase_en.qm" "${BUNDLE_TR_DIR}/qt_en.qm"
|
||||
)
|
||||
|
||||
# install the other Qt lang files renamed to qt_lang.qm
|
||||
foreach(LANG ${${CMAKE_PROJECT_NAME}_TRS})
|
||||
string(REPLACE "${CMAKE_PROJECT_NAME}_" "" LANG ${LANG})
|
||||
string(REPLACE ".ts" "" LANG ${LANG})
|
||||
install(FILES ${MAC_QT_LANG_PATH}/qtbase_${LANG}.qm DESTINATION ${CMAKE_INSTALL_I18N_DIR} RENAME qt_${LANG}.qm)
|
||||
add_custom_command(
|
||||
TARGET app_translations POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${MAC_QT_LANG_PATH}/qtbase_${LANG}.qm" "${BUNDLE_TR_DIR}/qt_${LANG}.qm"
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user