CMake set_source_files_properties error
-
When I'm adding translation files to the CMakeLists this error appears:
C:\Qt\6.7.1\msvc2019_64\lib\cmake\Qt6LinguistTools\Qt6LinguistToolsMacros.cmake:689:EVAL:1: error: set_source_files_properties given non-existent target for TARGET_DIRECTORY
How to fix it?
The CMakeLists:
cmake_minimum_required(VERSION 3.5) project(Movar_cpp VERSION 1.0.2 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools WebEngineWidgets TextToSpeech) qt_standard_project_setup() qt_add_resources(images PREFIX "/icons" FILES movar.png ) qt_add_translations(Movar_cpp TS_FILES i18n/Movar_cpp_uk_UA.ts i18n/Movar_cpp_en_US.ts i18n/Movar_cpp_ja_JP.ts ) qt_add_executable(Movar_cpp mainwindow.ui mainwindow.h mainwindow.cpp main.cpp dictionarysettings.h dictionarysettings.cpp dictionarysettings.ui fileloader.h fileloader.cpp app_resources.qrc adaptedcompleter.h adaptedcompleter.cpp adaptedstringlistmodel.h adaptedstringlistmodel.cpp ) target_link_libraries(Movar_cpp PRIVATE Qt6::Widgets Qt6::WebEngineWidgets Qt6::TextToSpeech) set_target_properties(Movar_cpp PROPERTIES WIN32_EXECUTABLE ON ) install(TARGETS Movar_cpp BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
-
@ekkescorner I found in yours article solution for fixing en_US and en simultaneous ts files creation:
qt_standard_project_setup( I18N_SOURCE_LANGUAGE en_US I18N_TRANSLATED_LANGUAGES uk_UA ja_JP )
Finally I created CMakeLists that works for me:
cmake_minimum_required(VERSION 3.5) project(Movar_cpp VERSION 1.0.2 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools WebEngineWidgets TextToSpeech) qt_standard_project_setup() qt_add_lupdate( TS_FILES translations/Movar_cpp_en_US.ts translations/Movar_cpp_ja_JP.ts translations/Movar_cpp_uk_UA.ts SOURCES mainwindow.cpp dictionarysettings.cpp fileloader.cpp mainwindow.ui dictionarysettings.ui ) qt_add_lrelease( TS_FILES translations/Movar_cpp_en_US.ts translations/Movar_cpp_ja_JP.ts translations/Movar_cpp_uk_UA.ts ) qt_add_executable(Movar_cpp mainwindow.ui mainwindow.h mainwindow.cpp main.cpp dictionarysettings.h dictionarysettings.cpp dictionarysettings.ui fileloader.h fileloader.cpp app_resources.qrc adaptedcompleter.h adaptedcompleter.cpp adaptedstringlistmodel.h adaptedstringlistmodel.cpp ) add_dependencies(${CMAKE_PROJECT_NAME} update_translations) target_link_libraries(Movar_cpp PRIVATE Qt6::Widgets Qt6::WebEngineWidgets Qt6::TextToSpeech) set_target_properties(Movar_cpp PROPERTIES WIN32_EXECUTABLE ON ) install(TARGETS Movar_cpp BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
I used qt_add_lupdate and qt_add_lrelease.
And there must be added function add_dependencies().
As I understand, it's old bug with lacking "update_translations" in beforementioned functions.
Without it ts files will be empty. -
Hi,
Based on the arrowpad example, it looks like you are not setting everything properly.
-
@Teg-Miles take a look at my posts about translations https://t1p.de/ekkeCMakeTranslation
you're missing set_source_files_properties... -
what is your Qt version ?
-
@ekkescorner 6.7.0
-
for me it works perfect without in Qt 6.7
but I set the languages in qt_standard_project_setup, which is recommended with 6.7+
see also https://www.qt.io/blog/revisited-i18n-with-cmake -
@ekkescorner It doesn't work either for me. And then I wrote en_US, uk_UA, ja_JP in I18N_TRANSLATED_LANGUAGES arguments it creates _en.ts files anyway. Is there some inbuilt settings for English language?
-
I know the default SOURCE language is en
do you mean you get en_US AND en ?
this would be OK if your development-language (SOURCE) is en
then as default qt_add_translations will use en for development, also creates a special en for plurals only plus all TRANSLATED languagesin my apps where en is my SOURCE language I want to have all translated also in en, so I set NO_GENERATE_PLURALS_TS_FILE
-
@ekkescorner I found in yours article solution for fixing en_US and en simultaneous ts files creation:
qt_standard_project_setup( I18N_SOURCE_LANGUAGE en_US I18N_TRANSLATED_LANGUAGES uk_UA ja_JP )
Finally I created CMakeLists that works for me:
cmake_minimum_required(VERSION 3.5) project(Movar_cpp VERSION 1.0.2 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Widgets LinguistTools WebEngineWidgets TextToSpeech) qt_standard_project_setup() qt_add_lupdate( TS_FILES translations/Movar_cpp_en_US.ts translations/Movar_cpp_ja_JP.ts translations/Movar_cpp_uk_UA.ts SOURCES mainwindow.cpp dictionarysettings.cpp fileloader.cpp mainwindow.ui dictionarysettings.ui ) qt_add_lrelease( TS_FILES translations/Movar_cpp_en_US.ts translations/Movar_cpp_ja_JP.ts translations/Movar_cpp_uk_UA.ts ) qt_add_executable(Movar_cpp mainwindow.ui mainwindow.h mainwindow.cpp main.cpp dictionarysettings.h dictionarysettings.cpp dictionarysettings.ui fileloader.h fileloader.cpp app_resources.qrc adaptedcompleter.h adaptedcompleter.cpp adaptedstringlistmodel.h adaptedstringlistmodel.cpp ) add_dependencies(${CMAKE_PROJECT_NAME} update_translations) target_link_libraries(Movar_cpp PRIVATE Qt6::Widgets Qt6::WebEngineWidgets Qt6::TextToSpeech) set_target_properties(Movar_cpp PROPERTIES WIN32_EXECUTABLE ON ) install(TARGETS Movar_cpp BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
I used qt_add_lupdate and qt_add_lrelease.
And there must be added function add_dependencies().
As I understand, it's old bug with lacking "update_translations" in beforementioned functions.
Without it ts files will be empty. -
-
curios. but good to hear that you found a working solution.