CopyBaseTranslations.cmake (1986B)
1 function(copy_base_translations target) 2 get_target_property(MOC_EXECUTABLE_LOCATION Qt6::moc IMPORTED_LOCATION) 3 get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY) 4 find_program(LCONVERT_EXE lconvert HINTS "${QT_BINARY_DIRECTORY}") 5 set(BASE_TRANSLATIONS_DIR "${QT_BINARY_DIRECTORY}/../translations") 6 7 if(NOT APPLE) 8 add_custom_command(TARGET ${target} POST_BUILD 9 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:${target}>/translations") 10 endif() 11 12 file(GLOB qmFiles "${BASE_TRANSLATIONS_DIR}/qt_*.qm") 13 foreach(path IN LISTS qmFiles) 14 get_filename_component(file ${path} NAME) 15 16 # qt_help_<lang> just has to ruin everything. 17 if(file MATCHES "qt_help_" OR NOT file MATCHES "qt_([^.]+).qm") 18 continue() 19 endif() 20 21 # If qtbase_<lang>.qm exists, merge all qms for that language into a single qm. 22 set(lang "${CMAKE_MATCH_1}") 23 set(baseQmPath "${BASE_TRANSLATIONS_DIR}/qtbase_${lang}.qm") 24 if(EXISTS "${baseQmPath}") 25 set(outPath "${CMAKE_CURRENT_BINARY_DIR}/qt_${lang}.qm") 26 set(srcQmFiles) 27 file(GLOB langQmFiles "${BASE_TRANSLATIONS_DIR}/qt*${lang}.qm") 28 foreach(qmFile IN LISTS langQmFiles) 29 get_filename_component(file ${qmFile} NAME) 30 if(file STREQUAL "qt_${lang}.qm") 31 continue() 32 endif() 33 LIST(APPEND srcQmFiles "${qmFile}") 34 endforeach() 35 add_custom_command(OUTPUT ${outPath} 36 COMMAND "${LCONVERT_EXE}" -verbose -of qm -o "${outPath}" ${srcQmFiles} 37 DEPENDS ${srcQmFiles} 38 ) 39 set(path "${outPath}") 40 endif() 41 42 target_sources(${target} PRIVATE ${path}) 43 if(APPLE) 44 set_source_files_properties(${path} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/translations) 45 else() 46 add_custom_command(TARGET ${target} POST_BUILD 47 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${path}" "$<TARGET_FILE_DIR:${target}>/translations") 48 endif() 49 endforeach() 50 endfunction()