Commit 635dd93e authored by Linus Jahn's avatar Linus Jahn Committed by GitHub

CMake: Improve i18n build system, Make Kaidan installable (#66)

All translations are now bundled into the kaidan binary (@licensing@
only possible because translations and code are GPL), so we don't have
any problems locating the qm-files anymore. :)

The generation of the qm-files is more manual now, but so there are no
unncessary outputs on the command line anymore.

And best news: You can install kaidan now via. `make install`.
parent 705b37fd
......@@ -49,10 +49,11 @@ set(EXECUTABLE_OUTPUT_PATH "bin")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# Find packages
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Sql LinguistTools)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Core Qml Quick Sql)
find_package(KF5Kirigami REQUIRED)
find_package(Swiften REQUIRED)
find_package(Boost REQUIRED)
include(GNUInstallDirs)
#
# Translation
......@@ -68,6 +69,7 @@ endif()
add_executable(${PROJECT_NAME}
kaidan.qrc
${I18N_QRC_CPP} # set in i18n/CMakeLists.txt, if enabled
src/main.cpp
src/Kaidan.cpp
src/RosterController.cpp
......@@ -105,3 +107,10 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
BOOST_SIGNALS_NO_DEPRECATION_WARNING=True
)
#
# Install Kaidan binary
#
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
# Translations
# if(APPLE AND UNIX) ## OSX
# install(FILES ${TRANSLATION_QM} DESTINATION MultiMC.app/Contents/Resources/translations)
# else()
# install(FILES ${TRANSLATION_QM} DESTINATION share/${PROJECT_NAME}/i18n)
# endif()
# Do not clean up (delete) files in this directory, when using make clean
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
find_package(Qt5LinguistTools)
include(GNUInstallDirs)
file(GLOB FILES_TO_TRANSLATE
${CMAKE_SOURCE_DIR}/src/*.cpp
${CMAKE_SOURCE_DIR}/src/qml/*.qml
)
file(GLOB TRANSLATION_FILES ${CMAKE_CURRENT_LIST_DIR}/*.ts)
file(GLOB TS_FILES
${CMAKE_CURRENT_LIST_DIR}/*.ts
)
#
# Update TS-files
#
set(LUPDATE_ARGS -silent)
add_custom_target(ts_update ALL DEPENDS)
foreach(TS_FILE ${TS_FILES})
add_custom_command(
TARGET ts_update
COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${LUPDATE_ARGS} ${FILES_TO_TRANSLATE} -ts ${TS_FILE}
COMMENT "Updating ${TS_FILE}"
MAIN_DEPENDENCY ${FILES_TO_TRANSLATE}
VERBATIM
)
endforeach()
#
# Generate QM-files
#
set(LRELEASE_ARGS -compress -nounfinished -removeidentical -silent)
add_custom_target(translations ALL DEPENDS ts_update)
# Update ts-files
qt5_create_translation(TRANSLATION_MESSAGES ${FILES_TO_TRANSLATE} ${TRANSLATION_FILES} OPTIONS -silent)
# Generate qm-files from ts-files
qt5_add_translation(TRANSLATION_QM ${TRANSLATION_FILES})
foreach(TS_FILE ${TS_FILES})
get_filename_component(FILENAME ${TS_FILE} NAME_WE) # only name without extension
set(QM_FILE "${PROJECT_NAME}_${FILENAME}.qm") # name for the generated qm file
set(QM_FILES ${QM_FILES} "${CMAKE_CURRENT_BINARY_DIR}/${QM_FILE}")
add_custom_target(translations ALL DEPENDS ${TRANSLATION_MESSAGES})
add_custom_command(
TARGET translations
COMMAND ${Qt5_LRELEASE_EXECUTABLE} ${LRELEASE_ARGS} ${TS_FILE} -qm ${CMAKE_CURRENT_BINARY_DIR}/${QM_FILE}
COMMENT "Generating binary translation file ${QM_FILE}"
MAIN_DEPENDENCY ${TS_FILE}
VERBATIM
)
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${QM_FILE} DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/i18n)
endforeach()
#
# Add all translations to the binary via. rcc / qrc file
#
set(I18N_QRC_NAME kaidan_i18n)
set(I18N_QRC_INPUT ${CMAKE_CURRENT_SOURCE_DIR}/${I18N_QRC_NAME}.qrc)
set(I18N_QRC_COPY ${CMAKE_CURRENT_BINARY_DIR}/${I18N_QRC_NAME}.qrc)
set(I18N_QRC_CPP ${CMAKE_CURRENT_BINARY_DIR}/qrc_${I18N_QRC_NAME}.cpp)
# Copy the QRC file to the output directory, because the files listed in the
# qrc file are relative to that directory.
add_custom_command(
OUTPUT ${I18N_QRC_COPY}
COMMAND ${CMAKE_COMMAND} -E copy ${I18N_QRC_INPUT} ${I18N_QRC_COPY}
COMMENT "Copying i18n resource file to current build directory"
MAIN_DEPENDENCY ${I18N_QRC_INPUT}
)
# Run the resource compiler (rcc_options should already be set). We can't
# use QT5_ADD_RESOURCES because the qrc file may not exist yet.
add_custom_command(
OUTPUT ${I18N_QRC_CPP}
COMMAND ${Qt5Core_RCC_EXECUTABLE} ${RCC_OPTIONS} -name ${I18N_QRC_NAME} -o ${I18N_QRC_CPP} ${I18N_QRC_COPY}
COMMENT "Generating qrc source qrc_${I18N_QRC_NAME}.cpp"
MAIN_DEPENDENCY ${I18N_QRC_COPY}
DEPENDS ${QM_FILES}
)
if(APPLE AND UNIX) ## OSX
install(FILES ${TRANSLATION_QM} DESTINATION MultiMC.app/Contents/Resources/translations)
else()
install(FILES ${TRANSLATION_QM} DESTINATION translations)
endif()
# The copy of the qrc file will be added to the binary via. AUTORCC in the main CMake file.
<RCC>
<qresource prefix="/i18n">
<file>kaidan_de.qm</file>
<file>kaidan_fr.qm</file>
<file>kaidan_ja.qm</file>
<file>kaidan_ru.qm</file>
</qresource>
</RCC>
......@@ -120,7 +120,9 @@ int main(int argc, char *argv[])
// Kaidan-Translator
QTranslator kaidanTranslator;
kaidanTranslator.load(QLocale::system().name()); // loads the systems locale or none
// load the systems locale or none
kaidanTranslator.load(QString(APPLICATION_NAME) + "_" + QLocale::system().name(),
":/i18n"); // load the qm files via. rcc (bundled in binary)
app.installTranslator(&kaidanTranslator);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment