Different qm file ouput location, depending on qt_add_translations being called inside a subdir or not
-
Hi all,
I have the following cmake code to generate plurals, working with different Qt versions:
if(QT6) if (QT_VERSION_MINOR GREATER_EQUAL 7) qt_add_translations(TARGETS muckturnier PLURALS_TS_FILE ${TS_FILE} QM_FILES_OUTPUT_VARIABLE QM_FILE LUPDATE_OPTIONS "-locations none") else() qt_add_translations(muckturnier TS_FILES ${TS_FILE} QM_FILES_OUTPUT_VARIABLE QM_FILE LUPDATE_OPTIONS -pluralonly -locations none) endif() add_dependencies(muckturnier update_translations) else() qt5_create_translation(QM_FILE ${CMAKE_SOURCE_DIR}/src ${TS_FILE} OPTIONS -pluralonly -locations none) add_custom_target(Localization ALL DEPENDS ${QM_FILE}) endif() install(FILES "${QM_FILE}" DESTINATION "${muckturnier_RESOURCES}")
Before calling it, I define the ts source like so:
set(TS_FILE ${CMAKE_SOURCE_DIR}/l10n/muckturnier_de.ts) set_source_files_properties(${TS_FILE} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/${muckturnier_RESOURCES})
This works fine, in all cases, the qm file ends up as
share/muckturnier/muckturnier_de.qm
in my build directory.Now, I want to modularize my CMakeLists.txt, and I created a subdirectory for the ts file with its own CMakeLists.txt, and put the code in there. The problem is that I now get another qm output location:
If I invoke the code from my main CMakeLists.txt like so:
if (linguist_FOUND) add_subdirectory(${CMAKE_SOURCE_DIR}/l10n) endif()
and the ts file definition is inside the sub-CMakeLists.txt, the qm file is created as
l10n/muckturnier_de.qm
inside the build directory. If I put the ts file definition outside, in the main CMakeLists.txt, like so:if (linguist_FOUND) set(TS_FILE ${CMAKE_SOURCE_DIR}/l10n/muckturnier_de.ts) set_source_files_properties(${TS_FILE} PROPERTIES OUTPUT_LOCATION ${CMAKE_BINARY_DIR}/${muckturnier_RESOURCES}) add_subdirectory(${CMAKE_SOURCE_DIR}/l10n) endif()
the output location is correct.
How can that happen? The paths are the same? Thanks for all help!
-
Hi,
I saw that add_subdirectory can have two arguments and the second is the destination. You could pass the binary dir from the current file that way.
-
But does it work if you pass it as second argument ?
-
What's the real problem here? Why cate about the location in the build dir? Simply add it to your resource file and all is fine
-
@SGaist No, the output location stays the same, no matter if I pass the path or not.
The problem is that I provide the qm file in a shared/... folder structure inside the build directory, similar to the one the program would find if it was installed system-wide (for simpler development and to make it possible to use the program as-is after building, without having to install it).
If the output location is somewhere else, I have to copy the file where the program expects it to find – and there's no easy and reliable way to make sure the qm file was actually already built when adding some copy target to be invoked.
It seems that the output location is somehow tied to the CMAKE_BINARY_DIR, and the Qt macros don't use CMAKE_BINARY_DIR but CMAKE_CURRENT_BINARY_DIR, which actually does change when adding a CMakeLists.txt file in a subdirectory …
-
Add the qm files to your resources