Warning, /frameworks/ki18n/cmake/KF6I18nMacros.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 "@Python3_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}/kf6i18nuic.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 Qt6::uic)
0036 message(FATAL_ERROR "Qt6Widgets should be found before calling ki18n_wrap_ui(). Please add find_package(Qt6Widgets ...)")
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 Qt6::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 kf6i18nuic.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 option(KF_SKIP_PO_PROCESSING "Skip processing of po files" OFF)
0081
0082 # KI18N_INSTALL(podir)
0083 # Search for .po files and scripting modules and install them to the standard
0084 # location. The instalation can be skipped using the KF_SKIP_PO_PROCESSING option.
0085 #
0086 # This is a convenience function which relies on the following directory
0087 # structure:
0088 #
0089 # <podir>/
0090 # <lang>/
0091 # scripts/
0092 # <domain>/
0093 # *.js
0094 # *.po
0095 #
0096 # .po files are passed to build-pofiles.cmake
0097 #
0098 # .js files are installed using build-tsfiles.cmake
0099 #
0100 # For example, given the following directory structure:
0101 #
0102 # po/
0103 # fr/
0104 # scripts/
0105 # kfoo/
0106 # kfoo.js
0107 # kfoo.po
0108 #
0109 # KI18N_INSTALL(po) does the following:
0110 # - Compiles kfoo.po into kfoo.mo and installs it in
0111 # ${KDE_INSTALL_LOCALEDIR}/fr/LC_MESSAGES or share/locale/fr/LC_MESSAGES if
0112 # ${KDE_INSTALL_LOCALEDIR} is not set.
0113 # - Installs kfoo.js in ${KDE_INSTALL_LOCALEDIR}/fr/LC_SCRIPTS/kfoo
0114 #
0115 function(KI18N_INSTALL podir)
0116 if (KF_SKIP_PO_PROCESSING)
0117 return()
0118 endif()
0119 if (NOT KDE_INSTALL_LOCALEDIR)
0120 set(KDE_INSTALL_LOCALEDIR share/locale)
0121 endif()
0122
0123 # First try to find the po directory in the source directory, where the release scripts copy them before making the tarballs
0124 get_filename_component(absolute_podir ${podir} ABSOLUTE)
0125
0126 # we try to find the po directory in the binary directory, in case it was downloaded
0127 # using ECM
0128 if (NOT (EXISTS "${absolute_podir}" AND IS_DIRECTORY "${absolute_podir}"))
0129 get_filename_component(absolute_podir ${CMAKE_CURRENT_BINARY_DIR}/${podir} ABSOLUTE)
0130 endif()
0131
0132 if (NOT (EXISTS "${absolute_podir}" AND IS_DIRECTORY "${absolute_podir}"))
0133 # Nothing to do if there's no podir and it would create an empty
0134 # KDE_INSTALL_LOCALEDIR in that case.
0135 return()
0136 endif()
0137
0138 get_filename_component(dirname ${KDE_INSTALL_LOCALEDIR} NAME)
0139 get_filename_component(destname ${KDE_INSTALL_LOCALEDIR} DIRECTORY)
0140 string(MD5 pathmd5 ${absolute_podir})
0141
0142 add_custom_target(pofiles-${pathmd5} ALL
0143 COMMENT "Generating mo..."
0144 COMMAND ${CMAKE_COMMAND}
0145 -DGETTEXT_MSGFMT_EXECUTABLE=${GETTEXT_MSGFMT_EXECUTABLE}
0146 -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/${dirname}
0147 -DPO_DIR=${absolute_podir}
0148 -P ${_ki18n_build_pofiles_script}
0149 )
0150 add_custom_target(tsfiles-${pathmd5} ALL
0151 COMMENT "Generating ts..."
0152 COMMAND ${CMAKE_COMMAND}
0153 -DPython3_EXECUTABLE=${KI18N_PYTHON_EXECUTABLE}
0154 -D_ki18n_pmap_compile_script=${_ki18n_pmap_compile_script}
0155 -DCOPY_TO=${CMAKE_CURRENT_BINARY_DIR}/${dirname}
0156 -DPO_DIR=${absolute_podir}
0157 -P ${_ki18n_build_tsfiles_script}
0158 )
0159
0160 if (NOT TARGET pofiles)
0161 add_custom_target(pofiles)
0162 endif()
0163 if (NOT TARGET tsfiles)
0164 add_custom_target(tsfiles)
0165 endif()
0166 add_dependencies(pofiles pofiles-${pathmd5})
0167 add_dependencies(tsfiles tsfiles-${pathmd5})
0168
0169 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dirname})
0170 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${dirname} DESTINATION ${destname})
0171 endfunction()