Warning, /frameworks/ki18n/cmake/KF5I18nMacros.cmake.in is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2006 Alexander Neundorf <neundorf@kde.org>
0002 #
0003 # SPDX-License-Identifier: BSD-3-Clause
0004 
0005 find_package(Gettext REQUIRED)
0006 
0007 # The Python executable used for building ki18n will be used as a fallback
0008 # solution if it cannot be found in $PATH when building applications.
0009 set(_KI18N_PYTHON_EXECUTABLE "@PYTHON_EXECUTABLE@")
0010 
0011 find_program(KI18N_PYTHON_EXECUTABLE NAMES python3 python2 python)
0012 if(NOT KI18N_PYTHON_EXECUTABLE)
0013     set(KI18N_PYTHON_EXECUTABLE "${_KI18N_PYTHON_EXECUTABLE}")
0014 endif()
0015 
0016 set(_ki18n_pmap_compile_script ${CMAKE_CURRENT_LIST_DIR}/ts-pmap-compile.py)
0017 set(_ki18n_uic_script ${CMAKE_CURRENT_LIST_DIR}/kf5i18nuic.cmake)
0018 set(_ki18n_build_pofiles_script ${CMAKE_CURRENT_LIST_DIR}/build-pofiles.cmake)
0019 set(_ki18n_build_tsfiles_script ${CMAKE_CURRENT_LIST_DIR}/build-tsfiles.cmake)
0020 
0021 # Creates the implementation files from the ui files and adds them to the list of sources,
0022 # either to the variable of the given name or, since KF 5.62, if the given argument is
0023 # a target (must not be an alias), to the list of private sources of that target.
0024 #
0025 #   ki18n_wrap_ui(<sources_var_name(|target (since 5.62))>
0026 #      [<ui_file> [...]]
0027 #   )
0028 #
0029 # Example usages:
0030 #
0031 #   ki18n_wrap_ui(foo_SRCS ${ui_files})
0032 #   ki18n_wrap_ui(foo ${ui_files})
0033 #
0034 macro (KI18N_WRAP_UI _sources )
0035    if(NOT TARGET Qt${QT_MAJOR_VERSION}::uic)
0036       message(FATAL_ERROR "Qt${QT_MAJOR_VERSION}Widgets should be found before calling ki18n_wrap_ui(). Please add find_package(Qt${QT_MAJOR_VERSION}Widgets ...)")
0037    endif()
0038    if (TARGET ${_sources})
0039       get_target_property(aliased_target ${_sources} ALIASED_TARGET)
0040       if(aliased_target)
0041          message(FATAL_ERROR "Target argument passed to ki18n_wrap_ui must not be an alias: ${_sources}")
0042       endif()
0043    endif()
0044 
0045    foreach (_current_FILE ${ARGN})
0046 
0047       get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
0048       if(NOT EXISTS ${_tmp_FILE})
0049          message(SEND_ERROR
0050          " Cannot find ui file:\n \n"
0051          "    ${_current_FILE}\n")
0052       endif()
0053       get_filename_component(_basename ${_tmp_FILE} NAME_WE)
0054       set(_header ${CMAKE_CURRENT_BINARY_DIR}/ui_${_basename}.h)
0055 
0056       get_target_property(QT_UIC_EXECUTABLE Qt${QT_MAJOR_VERSION}::uic LOCATION)
0057       # we need to run uic and replace some things in the generated file
0058       # this is done by executing the cmake script kf5i18nuic.cmake
0059       add_custom_command(OUTPUT ${_header}
0060          COMMAND ${CMAKE_COMMAND}
0061          ARGS
0062          -DKDE_UIC_EXECUTABLE:FILEPATH=${QT_UIC_EXECUTABLE}
0063          -DKDE_UIC_FILE:FILEPATH=${_tmp_FILE}
0064          -DKDE_UIC_H_FILE:FILEPATH=${_header}
0065          -DKDE_UIC_BASENAME:STRING=${_basename}
0066          -P ${_ki18n_uic_script}
0067          MAIN_DEPENDENCY ${_tmp_FILE}
0068       )
0069       set_source_files_properties(${_tmp_FILE} PROPERTIES SKIP_AUTOUIC ON)
0070       set_source_files_properties(${_header} PROPERTIES SKIP_AUTOMOC ON)
0071       set_source_files_properties(${_header} PROPERTIES SKIP_AUTOUIC ON)
0072       if(TARGET ${_sources})
0073          target_sources(${_sources} PRIVATE ${_header})
0074       else()
0075          list(APPEND ${_sources} ${_header})
0076       endif()
0077    endforeach (_current_FILE)
0078 endmacro (KI18N_WRAP_UI)
0079 
0080 # KI18N_INSTALL(podir)
0081 # Search for .po files and scripting modules and install them to the standard
0082 # location.
0083 #
0084 # This is a convenience function which relies on the following directory
0085 # structure:
0086 #
0087 #  <podir>/
0088 #    <lang>/
0089 #      scripts/
0090 #        <domain>/
0091 #          *.js
0092 #      *.po
0093 #
0094 # .po files are passed to build-pofiles.cmake
0095 #
0096 # .js files are installed using build-tsfiles.cmake
0097 #
0098 # For example, given the following directory structure:
0099 #
0100 #  po/
0101 #    fr/
0102 #      scripts/
0103 #        kfoo/
0104 #          kfoo.js
0105 #      kfoo.po
0106 #
0107 # KI18N_INSTALL(po) does the following:
0108 # - Compiles kfoo.po into kfoo.mo and installs it in
0109 #   ${LOCALE_INSTALL_DIR}/fr/LC_MESSAGES or share/locale/fr/LC_MESSAGES if
0110 #   ${LOCALE_INSTALL_DIR} is not set.
0111 # - Installs kfoo.js in ${LOCALE_INSTALL_DIR}/fr/LC_SCRIPTS/kfoo
0112 #
0113 # KI18N_INSTALL_TS_FILES() is deprecated, use KI18N_INSTALL()
0114 #
0115 function(KI18N_INSTALL podir)
0116     if (NOT LOCALE_INSTALL_DIR)
0117         set(LOCALE_INSTALL_DIR share/locale)
0118     endif()
0119 
0120     # First try to find the po directory in the source directory, where the release scripts copy them before making the tarballs
0121     get_filename_component(absolute_podir ${podir} ABSOLUTE)
0122 
0123     # we try to find the po directory in the binary directory, in case it was downloaded
0124     # using ECM
0125     if (NOT (EXISTS "${absolute_podir}" AND IS_DIRECTORY "${absolute_podir}"))
0126             get_filename_component(absolute_podir ${CMAKE_CURRENT_BINARY_DIR}/${podir} ABSOLUTE)
0127     endif()
0128 
0129     if (NOT (EXISTS "${absolute_podir}" AND IS_DIRECTORY "${absolute_podir}"))
0130         # Nothing to do if there's no podir and it would create an empty
0131         # LOCALE_INSTALL_DIR in that case.
0132         return()
0133     endif()
0134 
0135     get_filename_component(dirname ${LOCALE_INSTALL_DIR} NAME)
0136     get_filename_component(destname ${LOCALE_INSTALL_DIR} DIRECTORY)
0137     string(MD5 pathmd5 ${absolute_podir})
0138 
0139     add_custom_target(pofiles-${pathmd5} ALL
0140         COMMENT "Generating mo..."
0141         COMMAND ${CMAKE_COMMAND}
0142                 -DGETTEXT_MSGFMT_EXECUTABLE=${GETTEXT_MSGFMT_EXECUTABLE}
0143                 -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/${dirname}
0144                 -DPO_DIR=${absolute_podir}
0145                 -P ${_ki18n_build_pofiles_script}
0146     )
0147     add_custom_target(tsfiles-${pathmd5} ALL
0148         COMMENT "Generating ts..."
0149         COMMAND ${CMAKE_COMMAND}
0150                 -DPYTHON_EXECUTABLE=${KI18N_PYTHON_EXECUTABLE}
0151                 -D_ki18n_pmap_compile_script=${_ki18n_pmap_compile_script}
0152                 -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/${dirname}
0153                 -DPO_DIR=${absolute_podir}
0154                 -P ${_ki18n_build_tsfiles_script}
0155     )
0156 
0157     if (NOT TARGET pofiles)
0158         add_custom_target(pofiles)
0159     endif()
0160     if (NOT TARGET tsfiles)
0161         add_custom_target(tsfiles)
0162     endif()
0163     add_dependencies(pofiles pofiles-${pathmd5})
0164     add_dependencies(tsfiles tsfiles-${pathmd5})
0165 
0166     file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dirname})
0167     install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dirname} DESTINATION ${destname})
0168 endfunction()
0169 
0170 #install the scripts for a given language in the target folder
0171 #usage: KI18N_INSTALL_TS_FILES("ja" ${scripts_dir})
0172 function(KI18N_INSTALL_TS_FILES lang scripts_dir)
0173    file(GLOB_RECURSE ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${scripts_dir}/*)
0174    set(pmapc_files)
0175    foreach(ts_file ${ts_files})
0176       string(REGEX MATCH "\\.svn/" in_svn ${ts_file})
0177       if(NOT in_svn)
0178          # If ts_file is "path/to/foo/bar.js"
0179          # We want subpath to contain "foo"
0180          get_filename_component(subpath ${ts_file} DIRECTORY)
0181          get_filename_component(subpath ${subpath} NAME)
0182          install(FILES ${ts_file}
0183                  DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath})
0184          # If current file is a pmap, also install the compiled version.
0185          get_filename_component(ts_ext ${ts_file} EXT)
0186          if(ts_ext STREQUAL ".pmap")
0187             set(pmap_file ${ts_file})
0188             get_filename_component(pmap_basename ${ts_file} NAME)
0189             set(pmapc_basename "${pmap_basename}c")
0190             set(pmapc_file "${lang}-${subpath}-${pmapc_basename}")
0191             add_custom_command(OUTPUT ${pmapc_file}
0192                COMMAND ${KI18N_PYTHON_EXECUTABLE}
0193                ARGS
0194                -B
0195                ${_ki18n_pmap_compile_script}
0196                ${CMAKE_CURRENT_SOURCE_DIR}/${pmap_file}
0197                ${pmapc_file}
0198                DEPENDS ${pmap_file})
0199             install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pmapc_file}
0200                     DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath}
0201                     RENAME ${pmapc_basename})
0202             list(APPEND pmapc_files ${pmapc_file})
0203          endif()
0204       endif()
0205    endforeach()
0206    if(pmapc_files)
0207       if(NOT TARGET pmapfiles)
0208          add_custom_target(pmapfiles)
0209       endif()
0210       set(pmapc_target "pmapfiles-${lang}")
0211       string(REPLACE "@" "_" pmapc_target ${pmapc_target})
0212       add_custom_target(${pmapc_target} ALL DEPENDS ${pmapc_files})
0213       add_dependencies(pmapfiles ${pmapc_target})
0214    endif()
0215 endfunction()