From 4cd1042ee752d61370c685d0d8b20c1e935672f7 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Thu, 29 Feb 2024 16:35:52 +0200 Subject: CMake: Warn if gettext tools and pre-created .gmo files are missing. It's only done with CMake >= 3.20 and if library support for translation was already found. Sort of fixes: https://github.com/tukaani-project/xz/issues/82 --- CMakeLists.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index d2b1af7a..035cbec5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,9 +278,34 @@ endif() if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") find_package(Intl) find_package(Gettext) + if(Intl_FOUND) option(ENABLE_NLS "Native Language Support (translated messages)" ON) + # If translation support is enabled but neither gettext tools or + # pre-generated .gmo files exist, translation support cannot be + # enabled. + # + # The detection of pre-generated .gmo files is done by only + # checking for the existence of a single .gmo file; Ukrainian + # is one of many translations that gets regular updates. + if(ENABLE_NLS AND NOT GETTEXT_FOUND AND + NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/uk.gmo") + # This only sets the variable, not the cache variable! + set(ENABLE_NLS OFF) + + # This message is shown only when new enough CMake is used and + # library support for translations was found. The assumptions is + # that in this situation the user might have interest in the + # translations. This also keeps this code simpler. + message(WARNING "Native language support (NLS) has been disabled. " + "NLS support requires either gettext tools or " + "pre-generated .gmo files. The latter are only " + "available in distribution tarballs. " + "To avoid this warning, NLS can be explicitly " + "disabled by passing -DENABLE_NLS=OFF to cmake.") + endif() + # The *installed* name of the translation files is "xz.mo". set(TRANSLATION_DOMAIN "xz") endif() -- cgit v1.2.3