简体   繁体   中英

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 ?

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()

Use manual call of lrelease and lupdate utilities

set(TS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/translations")

set(TS_FILES
    "${TS_DIR}/${PROJECT_NAME}_ru_RU.ts"
)

find_program(LUPDATE_EXECUTABLE lupdate)
find_program(LRELEASE_EXECUTABLE lrelease)

foreach(_ts_file ${TS_FILES})

    execute_process(
        COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_SOURCE_DIR} -ts ${_ts_file})
    execute_process(
        COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file})

endforeach()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM