Handling existing VS2022 solution's translation files when converting to CMake
-
The Qt projects in my VS2022 solution have a sub-directory called i18n.
This contains e.g.:
C:\Users\amonra\Documents\GitHub\DSS\DeepSkyStacker\i18n>dir /b *.ts DSS_ca.ts DSS_cs.ts DSS_de.ts DSS_en.ts DSS_es.ts DSS_fr.ts DSS_it.ts DSS_ja_JP.tsDSS_nl.ts DSS_pt_BR.ts DSS_ro.ts DSS_ru.ts DSS_tr.ts DSS_zh_CN.ts DSS_zh_TW.ts translations.qrc
The VS Tools properties for the DSS_en.ts file are set so lupdate does "plurals only". The translations.qrc file picks up the qm files from this same directory where they are placed when lrelease is run.
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS_ca.qm</file> <file>DSS_cs.qm</file> <file>DSS_de.qm</file> <file>DSS_en.qm</file> <file>DSS_es.qm</file> <file>DSS_fr.qm</file> <file>DSS_it.qm</file> <file>DSS_nl.qm</file> <file>DSS_pt_BR.qm</file> <file>DSS_ro.qm</file> <file>DSS_ru.qm</file> <file>DSS_tr.qm</file> <file>DSS_zh_CN.qm</file> <file>DSS_zh_TW.qm</file> </qresource> </RCC>
That works well.
Now I am converting to use CMake. When I started this process I naively added the .ts files and the qrc file to the list of files I passed to qt_add_executable in the expectation that lrelease would automatically be run against those files in the source dir. NOPE that was wrong, though I'm not sure why it can't just pick them up and use them...
My CMake builds were working because the .qm files were already there in that directory, but after a clean they went away (of course), and the CMake build stopped working as the .qm files were no longer in that dir.
So how should I handle this in CMake so that if a) it runs lupdate the DSS_en.ts file is handled correctly, and b) the qm files that are generated in the build directory by CMake are built in the executable as a resource. I'm trying to work out what I need to put in my CMakeLists.txt file to "do the right thing".
I have already got this in the CMakeLists.txt.
set(i18n_Files "i18n/DSS_ca.ts" "i18n/DSS_cs.ts" "i18n/DSS_de.ts" "i18n/DSS_en.ts" "i18n/DSS_es.ts" "i18n/DSS_fr.ts" "i18n/DSS_it.ts" "i18n/DSS_ja_JP.ts" "i18n/DSS_nl.ts" "i18n/DSS_pt_BR.ts" "i18n/DSS_ro.ts" "i18n/DSS_ru.ts" "i18n/DSS_tr.ts" "i18n/DSS_zh_CN.ts" "i18n/DSS_zh_TW.ts" "i18n/translations.qrc" )
I suspect that if I remove the translations.qrc file from that list, that this can be used with the translation CMake functions but I'm a little unclear how to put it all together :(
I changed that list (removing the qrc file), and added the qrc file to the list of all files for qt_add_executable and then did:
set_source_files_properties(${i18n_Files} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/i18n") qt_add_lrelease(TS_FILES ${i18n_Files})
which seemed to work but is that the right way to approach this?
Thanks
David