diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,6 @@ PURPOSE "Needed for building KI18n unless glibc is the system libc implementation" ) -include(cmake/KF5I18NMacros.cmake) - remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) if(MSVC) remove_definitions(-DQT_STRICT_ITERATORS) @@ -80,6 +78,8 @@ install( FILES cmake/KF5I18NMacros.cmake cmake/kf5i18nuic.cmake + cmake/build-pofiles.cmake + cmake/build-tsfiles.cmake cmake/ts-pmap-compile.py DESTINATION ${CMAKECONFIG_INSTALL_DIR} COMPONENT Devel ) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -4,6 +4,8 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Test Qml Concurrent) +include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_BUILD_DIR}/src) + ecm_add_test(ki18ndeclarativetest.cpp TEST_NAME "ki18n-declarativetest" LINK_LIBRARIES Qt5::Test Qt5::Qml KF5::I18n @@ -16,21 +18,21 @@ # klocalizedstringtest needs the libintl include path target_include_directories(ki18n-klocalizedstringtest PRIVATE ${LibIntl_INCLUDE_DIRS}) -if (TARGET ktranscript) -ecm_add_test(ktranscripttest.cpp testhelpers.cpp - TEST_NAME "ki18n-ktranscripttest" - LINK_LIBRARIES Qt5::Test KF5::I18n -) -# ktranscripttest needs the path to ktranscript in the build dir: it cannot rely -# on the installed version since it must be able to run *before* the plugin is -# installed. -target_compile_definitions(ki18n-ktranscripttest PRIVATE "KTRANSCRIPT_PATH=\"$\"") - -# ktranscriptcleantest needs to directly compile ktranscript.cpp with an addition DEFINE -ecm_add_test(ktranscriptcleantest.cpp ../src/ktranscript.cpp ../src/common_helpers.cpp - TEST_NAME ki18n-ktranscriptcleantest - LINK_LIBRARIES Qt5::Script Qt5::Test Qt5::Concurrent KF5::I18n -) -target_compile_definitions(ki18n-ktranscriptcleantest PRIVATE "KTRANSCRIPT_TESTBUILD") -target_include_directories(ki18n-ktranscriptcleantest PRIVATE ..) -endif() +# if (TARGET ktranscript) +# ecm_add_test(ktranscripttest.cpp testhelpers.cpp +# TEST_NAME "ki18n-ktranscripttest" +# LINK_LIBRARIES Qt5::Test KF5::I18n +# ) +# # ktranscripttest needs the path to ktranscript in the build dir: it cannot rely +# # on the installed version since it must be able to run *before* the plugin is +# # installed. +# target_compile_definitions(ki18n-ktranscripttest PRIVATE "KTRANSCRIPT_PATH=\"$\"") +# +# # ktranscriptcleantest needs to directly compile ktranscript.cpp with an addition DEFINE +# ecm_add_test(ktranscriptcleantest.cpp ../src/ktranscript.cpp ../src/common_helpers.cpp +# TEST_NAME ki18n-ktranscriptcleantest +# LINK_LIBRARIES Qt5::Script Qt5::Test Qt5::Concurrent KF5::I18n +# ) +# target_compile_definitions(ki18n-ktranscriptcleantest PRIVATE "KTRANSCRIPT_TESTBUILD") +# target_include_directories(ki18n-ktranscriptcleantest PRIVATE ..) +# endif() diff --git a/cmake/KF5I18NMacros.cmake b/cmake/KF5I18NMacros.cmake --- a/cmake/KF5I18NMacros.cmake +++ b/cmake/KF5I18NMacros.cmake @@ -57,53 +57,6 @@ endforeach (_current_FILE) endmacro (KI18N_WRAP_UI) -#install the scripts for a given language in the target folder -#usage: KI18N_INSTALL_TS_FILES("ja" ${scripts_dir}) -function(KI18N_INSTALL_TS_FILES lang scripts_dir) - file(GLOB_RECURSE ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${scripts_dir}/*) - set(pmapc_files) - foreach(ts_file ${ts_files}) - string(REGEX MATCH "\\.svn/" in_svn ${ts_file}) - if(NOT in_svn) - # If ts_file is "path/to/foo/bar.js" - # We want subpath to contain "foo" - get_filename_component(subpath ${ts_file} DIRECTORY) - get_filename_component(subpath ${subpath} NAME) - install(FILES ${ts_file} - DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath}) - # If current file is a pmap, also install the compiled version. - get_filename_component(ts_ext ${ts_file} EXT) - if(ts_ext STREQUAL ".pmap") - set(pmap_file ${ts_file}) - get_filename_component(pmap_basename ${ts_file} NAME) - set(pmapc_basename "${pmap_basename}c") - set(pmapc_file "${lang}-${subpath}-${pmapc_basename}") - add_custom_command(OUTPUT ${pmapc_file} - COMMAND ${PYTHON_EXECUTABLE} - ARGS - -B - ${_ki18n_pmap_compile_script} - ${CMAKE_CURRENT_SOURCE_DIR}/${pmap_file} - ${pmapc_file} - DEPENDS ${pmap_file}) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pmapc_file} - DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath} - RENAME ${pmapc_basename}) - list(APPEND pmapc_files ${pmapc_file}) - endif() - endif() - endforeach() - if(pmapc_files) - if(NOT TARGET pmapfiles) - add_custom_target(pmapfiles) - endif() - set(pmapc_target "pmapfiles-${lang}") - string(REPLACE "@" "_" pmapc_target ${pmapc_target}) - add_custom_target(${pmapc_target} ALL DEPENDS ${pmapc_files}) - add_dependencies(pmapfiles ${pmapc_target}) - endif() -endfunction() - # KI18N_INSTALL(podir) # Search for .po files and scripting modules and install them to the standard # location. @@ -142,87 +95,24 @@ if (NOT LOCALE_INSTALL_DIR) set(LOCALE_INSTALL_DIR share/locale) endif() - foreach(lang_dir ${lang_dirs}) - get_filename_component(lang ${lang_dir} NAME) - - file(GLOB po_files "${lang_dir}/*.po") - _ki18n_gettext_process_po_files(${lang} ALL - INSTALL_DESTINATION ${LOCALE_INSTALL_DIR} - PO_FILES ${po_files} - ) - ki18n_install_ts_files(${lang} ${lang_dir}/scripts) - endforeach() -endfunction() - - -############################################################################### -# The following code has been copied from CMake FindGettext.cmake and adjusted -# to support processing multiple .po files with the same name in different -# directories. -# -# CMake bug report: http://public.kitware.com/Bug/view.php?id=14904 -# -# This code comes with the following license notice: -#============================================================================= -# Copyright 2007-2009 Kitware, Inc. -# Copyright 2007 Alexander Neundorf -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -function(_KI18N_GETTEXT_PROCESS_PO_FILES _lang) - set(_options ALL) - set(_oneValueArgs INSTALL_DESTINATION) - set(_multiValueArgs PO_FILES) - set(_gmoFiles) - - CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN}) - - foreach(_current_PO_FILE ${_parsedArguments_PO_FILES}) - get_filename_component(_name ${_current_PO_FILE} NAME) - string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _basename ${_name}) - set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}-${_basename}.gmo) - add_custom_command(OUTPUT ${_gmoFile} - COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_current_PO_FILE} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - DEPENDS ${_current_PO_FILE} - ) - - if(_parsedArguments_INSTALL_DESTINATION) - install(FILES ${_gmoFile} DESTINATION ${_parsedArguments_INSTALL_DESTINATION}/${_lang}/LC_MESSAGES/ RENAME ${_basename}.mo) - endif() - list(APPEND _gmoFiles ${_gmoFile}) - endforeach() - - - if(NOT TARGET pofiles) - add_custom_target(pofiles) - endif() - - _KI18N_GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName) - - if(_parsedArguments_ALL) - add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles}) - else() - add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles}) - endif() - - add_dependencies(pofiles ${uniqueTargetName}) - -endfunction() -function(_KI18N_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name) - set(propertyName "_KI18N_GETTEXT_UNIQUE_COUNTER_${_name}") - get_property(currentCounter GLOBAL PROPERTY "${propertyName}") - if(NOT currentCounter) - set(currentCounter 1) - endif() - set(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE) - math(EXPR currentCounter "${currentCounter} + 1") - set_property(GLOBAL PROPERTY ${propertyName} ${currentCounter} ) + add_custom_target(pofiles ALL + COMMENT "Generating mo..." + COMMAND ${CMAKE_COMMAND} + -DGETTEXT_MSGFMT_EXECUTABLE=${GETTEXT_MSGFMT_EXECUTABLE} + -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/mo + -DPO_DIR=${podir} + -P ${KF5I18n_DIR}/build-pofiles.cmake + ) + add_custom_target(tsfiles ALL + COMMENT "Generating ts..." + COMMAND ${CMAKE_COMMAND} + -Dts_EXECUTABLE=${ts_EXECUTABLE} + -D_ki18n_pmap_compile_script=${_ki18n_pmap_compile_script} + -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/mo + -DPO_DIR=${podir} + -P ${KF5I18n_DIR}/build-tsfiles.cmake + ) + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mo) + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mo DESTINATION ${LOCALE_INSTALL_DIR}) endfunction() -# End of CMake copied code #################################################### diff --git a/cmake/build-pofiles.cmake b/cmake/build-pofiles.cmake new file mode 100644 --- /dev/null +++ b/cmake/build-pofiles.cmake @@ -0,0 +1,42 @@ +# Copyright (c) 2017 Aleix Pol Gonzalez +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +file(GLOB_RECURSE pofiles RELATIVE "${PO_DIR}" "${PO_DIR}/**.po") + +foreach(pofile IN LISTS pofiles) + string(REPLACE ".po" ".mo" _gmoFile ${pofile}) + get_filename_component(langdir ${_gmoFile} DIRECTORY) + file(MAKE_DIRECTORY ${COPY_TO}/${langdir}) + + message(STATUS "building... ${pofile} to ${_gmoFile}" ) + execute_process( + COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${COPY_TO}/${_gmoFile} ${PO_DIR}/${pofile} + RESULT_VARIABLE code + ) + if(code) + message(FATAL_ERROR "failed at generating ${_gmoFile}") + endif() +endforeach() diff --git a/cmake/build-tsfiles.cmake b/cmake/build-tsfiles.cmake new file mode 100644 --- /dev/null +++ b/cmake/build-tsfiles.cmake @@ -0,0 +1,58 @@ +# Copyright (c) 2017 Aleix Pol Gonzalez +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +file(GLOB_RECURSE ts_files RELATIVE ${PO_DIR} ${PO_DIR}/**/scripts/*) +foreach(ts_file ${ts_files}) + if(ts_file MATCHES "\\.svn/") + continue() + endif() + + # If ts_file is "path/to/foo/bar.js" + # We want subpath to contain "foo" + get_filename_component(subpath ${ts_file} DIRECTORY) + get_filename_component(subpath ${subpath} NAME) + file(COPY ${ts_file} DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath}) + message(STATUS "COPY ${ts_file} DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath}") +endforeach() + +file(GLOB_RECURSE pmap_files RELATIVE ${PO_DIR} "${PO_DIR}/**.pmap") +foreach(pmap_file ${pmap_files}) + get_filename_component(pmap_basename ${ts_file} NAME) + set(pmapc_basename "${pmap_basename}c") + set(pmapc_file "${COPY_TO}/${lang}/LC_SCRIPTS/${subpath}/${pmapc_basename}") + message(STATUS "building... ${pmap_file} to ${pmapc_file}" ) + execute_process( + COMMAND ${ts_EXECUTABLE} + -B + ${_ki18n_pmap_compile_script} + ${PO_DIR}/${pmap_file} + ${pmapc_file} + RESULT_VARIABLE code + ) + if(code) + message(FATAL_ERROR "failed at creating ${pmap_file}...") + endif() +endforeach()