diff --git a/cmake/KF5I18nMacros.cmake.in b/cmake/KF5I18nMacros.cmake.in --- a/cmake/KF5I18nMacros.cmake.in +++ b/cmake/KF5I18nMacros.cmake.in @@ -2,6 +2,8 @@ # # SPDX-License-Identifier: BSD-3-Clause +include(CMakeParseArguments) + find_package(Gettext REQUIRED) # The Python executable used for building ki18n will be used as a fallback @@ -60,7 +62,7 @@ endforeach (_current_FILE) endmacro (KI18N_WRAP_UI) -# KI18N_INSTALL(podir) +# KI18N_INSTALL(podir [DESTINATION ]) # Search for .po files and scripting modules and install them to the standard # location. # @@ -78,6 +80,11 @@ # # .js files are installed using build-tsfiles.cmake # +# ``DESTINATION`` specifies the installation directory where the files are installed to (since 5.70). +# For backward-compatibility, if this argument is not passed, the installation +# directory will be taken from the CMake variables ``LOCALE_INSTALL_DIR`` or, if not set, +# ``KDE_INSTALL_LOCALEDIR``, or, if also not set, will default to "share/locale". +# # For example, given the following directory structure: # # po/ @@ -87,17 +94,36 @@ # kfoo.js # kfoo.po # -# KI18N_INSTALL(po) does the following: +# KI18N_INSTALL(po DESITNATION ${KDE_INSTALL_LOCALEDIR}) does the following: # - Compiles kfoo.po into kfoo.mo and installs it in -# ${LOCALE_INSTALL_DIR}/fr/LC_MESSAGES or share/locale/fr/LC_MESSAGES if -# ${LOCALE_INSTALL_DIR} is not set. -# - Installs kfoo.js in ${LOCALE_INSTALL_DIR}/fr/LC_SCRIPTS/kfoo +# ${KDE_INSTALL_LOCALEDIR}/fr/LC_MESSAGES +# - Installs kfoo.js in ${KDE_INSTALL_LOCALEDIR}/fr/LC_SCRIPTS/kfoo # # KI18N_INSTALL_TS_FILES() is deprecated, use KI18N_INSTALL() # function(KI18N_INSTALL podir) - if (NOT LOCALE_INSTALL_DIR) - set(LOCALE_INSTALL_DIR share/locale) + set(options ) + set(oneValueArgs DESTINATION) + set(multiValueArgs ) + + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(ARGS_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to KI18N_INSTALL(): \"${ARGS_UNPARSED_ARGUMENTS}\"") + endif() + + if(ARGS_DESTINATION) + set(locale_installdir "${ARGS_DESTINATION}") + else() + # backward-compatible fallback to common vars as set when using KDEInstallDirs + # LOCALE_INSTALL_DIR will not be set by KDEInstallDirs if KDE_INSTALL_DIRS_NO_DEPRECATED is set + if (LOCALE_INSTALL_DIR) + set(locale_installdir "${LOCALE_INSTALL_DIR}") + elseif(KDE_INSTALL_LOCALEDIR) + set(locale_installdir "${KDE_INSTALL_LOCALEDIR}") + else() + set(locale_installdir "share/locale") + endif() endif() # First try to find the po directory in the source directory, where the release scripts copy them before making the tarballs @@ -111,12 +137,12 @@ if (NOT (EXISTS "${absolute_podir}" AND IS_DIRECTORY "${absolute_podir}")) # Nothing to do if there's no podir and it would create an empty - # LOCALE_INSTALL_DIR in that case. + # locale_installdir in that case. return() endif() - get_filename_component(dirname ${LOCALE_INSTALL_DIR} NAME) - get_filename_component(destname ${LOCALE_INSTALL_DIR} DIRECTORY) + get_filename_component(dirname ${locale_installdir} NAME) + get_filename_component(destname ${locale_installdir} DIRECTORY) string(MD5 pathmd5 ${absolute_podir}) add_custom_target(pofiles-${pathmd5} ALL @@ -153,6 +179,15 @@ #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) + # backward-compatible fallback to common vars as set when using KDEInstallDirs + if (LOCALE_INSTALL_DIR) + set(locale_installdir "${LOCALE_INSTALL_DIR}") + elseif(KDE_INSTALL_LOCALEDIR) + set(locale_installdir "${KDE_INSTALL_LOCALEDIR}") + else() + set(locale_installdir "share/locale") + endif() + file(GLOB_RECURSE ts_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${scripts_dir}/*) set(pmapc_files) foreach(ts_file ${ts_files}) @@ -163,7 +198,7 @@ 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}) + DESTINATION ${locale_installdir}/${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") @@ -180,7 +215,7 @@ ${pmapc_file} DEPENDS ${pmap_file}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${pmapc_file} - DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_SCRIPTS/${subpath} + DESTINATION ${locale_installdir}/${lang}/LC_SCRIPTS/${subpath} RENAME ${pmapc_basename}) list(APPEND pmapc_files ${pmapc_file}) endif()