mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-21 21:35:38 +00:00
CMake: Generate/copy base translations for Mac/Linux
This commit is contained in:
parent
a2f19143da
commit
b8a372bb6e
50
CMakeModules/CopyBaseTranslations.cmake
Normal file
50
CMakeModules/CopyBaseTranslations.cmake
Normal file
|
@ -0,0 +1,50 @@
|
|||
function(copy_base_translations target)
|
||||
get_target_property(MOC_EXECUTABLE_LOCATION Qt6::moc IMPORTED_LOCATION)
|
||||
get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY)
|
||||
find_program(LCONVERT_EXE lconvert HINTS "${QT_BINARY_DIRECTORY}")
|
||||
set(BASE_TRANSLATIONS_DIR "${QT_BINARY_DIRECTORY}/../translations")
|
||||
|
||||
if(NOT APPLE)
|
||||
add_custom_command(TARGET ${target} POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:${target}>/translations")
|
||||
endif()
|
||||
|
||||
file(GLOB qmFiles "${BASE_TRANSLATIONS_DIR}/qt_*.qm")
|
||||
foreach(path IN LISTS qmFiles)
|
||||
get_filename_component(file ${path} NAME)
|
||||
|
||||
# qt_help_<lang> just has to ruin everything.
|
||||
if(file MATCHES "qt_help_" OR NOT file MATCHES "qt_([^.]+).qm")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
# If qtbase_<lang>.qm exists, merge all qms for that language into a single qm.
|
||||
set(lang "${CMAKE_MATCH_1}")
|
||||
set(baseQmPath "${BASE_TRANSLATIONS_DIR}/qtbase_${lang}.qm")
|
||||
if(EXISTS "${baseQmPath}")
|
||||
set(outPath "${CMAKE_CURRENT_BINARY_DIR}/qt_${lang}.qm")
|
||||
set(srcQmFiles)
|
||||
file(GLOB langQmFiles "${BASE_TRANSLATIONS_DIR}/qt*${lang}.qm")
|
||||
foreach(qmFile IN LISTS langQmFiles)
|
||||
get_filename_component(file ${qmFile} NAME)
|
||||
if(file STREQUAL "qt_${lang}.qm")
|
||||
continue()
|
||||
endif()
|
||||
LIST(APPEND srcQmFiles "${qmFile}")
|
||||
endforeach()
|
||||
add_custom_command(OUTPUT ${outPath}
|
||||
COMMAND "${LCONVERT_EXE}" -verbose -of qm -o "${outPath}" ${srcQmFiles}
|
||||
DEPENDS ${srcQmFiles}
|
||||
)
|
||||
set(path "${outPath}")
|
||||
endif()
|
||||
|
||||
target_sources(${target} PRIVATE ${path})
|
||||
if(APPLE)
|
||||
set_source_files_properties(${path} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
|
||||
else()
|
||||
add_custom_command(TARGET ${target} POST_BUILD
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${path}" "$<TARGET_FILE_DIR:${target}>/translations")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
|
@ -1,3 +1,5 @@
|
|||
include(CopyBaseTranslations)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
|
@ -225,18 +227,18 @@ elseif(APPLE)
|
|||
|
||||
# Translation setup
|
||||
qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
|
||||
foreach (QM_FILE IN LISTS QM_FILES)
|
||||
target_sources(duckstation-qt PRIVATE ${QM_FILE})
|
||||
set_source_files_properties(${QM_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
|
||||
endforeach()
|
||||
foreach (QM_FILE IN LISTS QM_FILES)
|
||||
target_sources(duckstation-qt PRIVATE ${QM_FILE})
|
||||
set_source_files_properties(${QM_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations)
|
||||
endforeach()
|
||||
copy_base_translations(duckstation-qt)
|
||||
else()
|
||||
# TODO: Copy base translations.
|
||||
qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
|
||||
set(QM_OUTPUT_DIR "$<TARGET_FILE_DIR:duckstation-qt>/translations")
|
||||
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${QM_OUTPUT_DIR}")
|
||||
foreach (QM_FILE IN LISTS QM_FILES)
|
||||
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
|
||||
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${QM_FILE}" "${QM_OUTPUT_DIR}/${QM_FILE_NAME}")
|
||||
endforeach()
|
||||
qt_add_lrelease(duckstation-qt TS_FILES ${TS_FILES} QM_FILES_OUTPUT_VARIABLE QM_FILES)
|
||||
set(QM_OUTPUT_DIR "$<TARGET_FILE_DIR:duckstation-qt>/translations")
|
||||
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E make_directory "${QM_OUTPUT_DIR}")
|
||||
foreach (QM_FILE IN LISTS QM_FILES)
|
||||
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
|
||||
add_custom_command(TARGET duckstation-qt POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${QM_FILE}" "${QM_OUTPUT_DIR}/${QM_FILE_NAME}")
|
||||
endforeach()
|
||||
copy_base_translations(duckstation-qt)
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in a new issue