Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Different qm file ouput location, depending on qt_add_translations being called inside a subdir or not
Forum Updated to NodeBB v4.3 + New Features

Different qm file ouput location, depending on qt_add_translations being called inside a subdir or not

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 297 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by
        #3

        Checking ${CMAKE_BINARY_DIR} was actually the first thing I did, I thought it may change in a subdir. But actually, it doesn't … it still points to the same directory like in the main CMakeLists.txt. So this does not seem to cause it …

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          But does it work if you pass it as second argument ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • l3u_L Offline
              l3u_L Offline
              l3u_
              wrote on last edited by l3u_
              #6

              @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 …

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Add the qm files to your resources

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • l3u_L Offline
                  l3u_L Offline
                  l3u_
                  wrote on last edited by
                  #8

                  Well, this would be a possible workaround, but it neither explains nor solves the underlying problem …

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved