]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Warn if gettext tools and pre-created .gmo files are missing.
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 29 Feb 2024 14:35:52 +0000 (16:35 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 29 Feb 2024 14:37:19 +0000 (16:37 +0200)
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

index d2b1af7ab0ab759b6805ced3dff2555e2a4b3f8e..035cbec53c586c0c812fa6dac885ac911f911425 100644 (file)
@@ -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()