cmakeqt-linguist

CMake qt5_add_translation, how to specify the output path?


I use qt5_add_translation to run lrelease and generate the .qm files. By default the .qm files are put at the root level of the build dir, no matter where you put the .ts files in the source dir.

How can I specify a subdir for those files in the build ?


Solution

  • Set a property on the .ts files before calling the Qt macro :

    set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION your_output_path)
    

    Where TS_FILES contains the list of the .ts files and your_output_path is the path where to put the .qm files (relative to the build directory or absolute).

    Because the macro will retrieve the property to make the path of the .qm files (tested with Qt 5.9) :

    get_source_file_property(output_location ${_abs_FILE} OUTPUT_LOCATION)
    if(output_location)
        file(MAKE_DIRECTORY "${output_location}")
        set(qm "${output_location}/${qm}.qm")
    else()
        set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
    endif()