LINUX.ORG.RU

CMake, Qt, локализации


0

0

Имеется вот такой CMakeLists.txt:

cmake_minimum_required( VERSION 2.6 )
project (winegame)

#блабла, ищем Qt

#Ищем winestuff
find_package(WineStuff REQUIRED)
#message(STATUS "Searching for WineStuff")
find_package(WineStuff REQUIRED)
#message(STATUS "WineStuff Include Dir: ${WINESTUFF_INCLUDE_DIR}")
#message(STATUS "WineStuff Library: ${WINESTUFF_LIBRARIES}")
set (CMAKE_BUILD_TYPE Debug)
include_directories(${WINESTUFF_INCLUDE_DIR})
#message (STATUS "Files will be compiled in: ${CMAKE_CURRENT_BINARY_DIR}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set (RESDIR ${CMAKE_SOURCE_DIR}/resources)

# Sources, Headers
set (SOURCES about.cpp  diskdialog.cpp  gamedialog.cpp  main.cpp  mainwindow.cpp  prefixdialog.cpp  settingsdialog.cpp  shortcutdialog.cpp  winegameui.cpp  wineversionsdialog.cpp treemodel.cpp package.cpp plugindialog.cpp feedbackdialog.cpp ejectdialog.cpp nextdisc.cpp)
set (QOBJ_HEADERS about.h  diskdialog.h  gamedialog.h  mainwindow.h  prefixdialog.h  settingsdialog.h  shortcutdialog.h  winegameui.h  wineversionsdialog.h treemodel.h plugindialog.h feedbackdialog.h ejectdialog.h nextdisc.h)
set (HEADERS package.h)

#Генерируем формы
set (UIS about.ui  diskdialog.ui  gamedialog.ui  mainwindow.ui  prefixdialog.ui  settingsdialog.ui  shortcutdialog.ui  wineversionsdialog.ui plugindialog.ui feedbackdialog.ui ejectdialog.ui nextdisc.ui)
qt4_wrap_ui (UI_HEADERS ${UIS})

#Генерируем ресурсы
set (RES ${RESDIR}/res.qrc)
qt4_add_resources (QRC_SOURCES ${RES})

#Генерируем файлы MOC
qt4_wrap_cpp (MOC_SOURCES ${QOBJ_HEADERS})


#Translations
set (TSDIR ${CMAKE_CURRENT_SOURCE_DIR}/l10n)
set (LANGUAGES wg_ru)

foreach (LANGUAGE ${LANGUAGES})
set (TS ${TSDIR}/${LANGUAGE}.ts)
set (QM ${TSDIR}/${LANGUAGE}.qm)
set (TRANSLATIONS ${TRANSLATIONS} ${TS})
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (
OUTPUT ${QM}
COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/l10n
MAIN_DEPENDENCY ${TS})
endforeach()
add_custom_target (
translations
COMMAND ${QT_LUPDATE_EXECUTABLE} ${MOC_SOURCES} ${SOURCES} ${UI_SOURCES} -ts ${TRANSLATIONS} -I${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command (
TARGET translations
COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_executable (winegame ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${UI_HEADERS} ${QRC_SOURCES} ${TRANS})

#Линкуем
target_link_libraries( winegame ${QT_LIBRARIES} ${WINESTUFF_LIBRARIES})

#ставим
install (TARGETS winegame DESTINATION bin)
install (FILES ${TRANSLATIONS_BINARY} DESTINATION share/winegame/translations)
install (FILES ${CMAKE_SOURCE_DIR}/desktop/winegame.png DESTINATION share/pixmaps)
install (FILES ${CMAKE_SOURCE_DIR}/desktop/winegame.desktop DESTINATION share/applications)

Почему-то в получающемся в результате 'make translations` qm файле отсутствуют строчки, из файлов ui_*.h (UI)

Что делать?

★★★★

Во-первых, вы перепутали UI_SOURCES с UI_HEADERS. Во-вторых, подставлять в lupdate эти заголовочники и не нужно, достаточно список ${UIS} - он сам разберётся что есть .cpp, а что .ui (по расширению) и сгенерирует переводы прямо из форм. И да, MOC_SOURCES - тоже лишнее.

Dendy ★★★★★
()

Если интересно, вот мои собственные макросы для генерации переводов:

# Macro for creating rules to generate Qt translations.
#
# Usage:
#
#   my_create_translation( TS_FILE QM_FILE TS_TARGETS [source1 source2 ...] )
#
#   - TS_FILE    - in variable, pass .ts file to update and from which .qm file should be generated
#   - QM_FILE    - in variable, here will be generated .qm file
#   - TS_TARGETS - out variable, here will be added target to update .ts file
#
# Two steps here, each can be done separately:
#   1. Update .ts files from sources/forms
#   2. Generate .qm files from .ts files
#
# This macro also workarounds CMake issue, when .ts files treated as compilation
# product and will be physically removed from drive on "make clean" step.
#
# .ts files are not compilation products, they are not generated inside build
# directory. .qm files does - they could be completely removed on "make clean".
#
# Because .ts files should be created separately and should be not included
# into build step - separate target should be created by user for convenience.
#
# Example:
#
#   my_create_translation( qm_file ts_targets myapp.ts mysource.cpp myform.ui ... )
#   add_custom_target( update_my_translations DEPENDS ${ts_targets} )
#
# Updating .ts files can be issued in two ways:
# 1. run "make update_my_translations" (recommended)
# 2. add update_my_translations target as dependency to build process, this will issue .ts
#    updates automatically each time build runs.

macro( my_create_translation TS_FILE QM_FILE TS_TARGETS  )
	qt4_extract_options( _source_files _lupdate_options ${ARGN} )

	get_filename_component( _ts_file_absolute "${TS_FILE}" ABSOLUTE )
	get_filename_component( _ts_filename "${TS_FILE}" NAME )
	get_filename_component( _ts_filename_we "${TS_FILE}" NAME_WE )

	get_filename_component( _qm_dir "${QM_FILE}" PATH )

	set( _pro_file "${_qm_dir}/${_ts_filename_we}.pro" )
	set( _dummy_target_file "${_qm_dir}/_dummy_target_file_for_${_ts_filename_we}" )

	# generate .pro file for lupdate utility
	file( WRITE "${_pro_file}"
		"#\n"
		"# This file is autogenerated by my_create_translation() macro\n"
		"# to update translation file: ${_ts_filename}\n"
		"# All changes will be lost\n"
		"#\n"
	)

	# SOURCES section
	file( APPEND "${_pro_file}"
		"\n"
		"SOURCES =\\\n"
	)
	foreach ( _source_file ${_source_files} )
		get_filename_component( _source_file_ext "${_source_file}" EXT )
		if ( "${_source_file_ext}" STREQUAL ".cpp" OR "${_source_file_ext}" STREQUAL ".c" )
			file( APPEND "${_pro_file}" "  ${_source_file}\\\n" )
		endif()
	endforeach()

	# FORMS section
	file( APPEND "${_pro_file}"
		"\n"
		"FORMS =\\\n"
	)
	foreach ( _source_file ${_source_files} )
		get_filename_component( _source_file_ext "${_source_file}" EXT )
		if ( "_source_file_ext" STREQUAL ".ui" )
			file( APPEND "${_pro_file}" "  ${_source_file}\\\n" )
		endif()
	endforeach()

	# create command with invalid output file so it will be never cleared and always updated manually
	list( APPEND ${TS_TARGETS} "${_dummy_target_file}" )

	# add command that really updates .ts file from sources
	add_custom_command(
		OUTPUT
			"${_dummy_target_file}"
		COMMAND
			"${QT_LUPDATE_EXECUTABLE}" ${_lupdate_options} "${_pro_file}" -ts "${_ts_file_absolute}"
		DEPENDS
			${_source_files}
			${_pro_file}
		)

	# run lupdate once if .ts file not exists
	if ( NOT EXISTS "${_ts_file_absolute}" )
		execute_process( COMMAND "${QT_LUPDATE_EXECUTABLE}" ${_lupdate_options} "${_pro_file}" -ts "${_ts_file_absolute}" )
	endif()

	# generate .qm from .ts
	my_add_translation( "${TS_FILE}" "${QM_FILE}" )

endmacro()



# Second part of macro above.
# Creates rule to generate .qm file from .ts file.
#
# Usage:
#
#   my_add_translation( QM_FILE TS_FILE )
#
#   - TS_FILE - in variable, .ts file from which .qm file will be generated
#   - QM_FILE - in variable, .qm file that will be generated

macro( my_add_translation TS_FILE QM_FILE )
	add_custom_command(
		OUTPUT
			"${QM_FILE}"
		COMMAND
			${QT_LRELEASE_EXECUTABLE} -silent "${TS_FILE}" -qm "${QM_FILE}"
		DEPENDS 
			"${TS_FILE}"
		)
endmacro()
Dendy ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.