mirror of https://git.tukaani.org/xz.git
CMake: Make XZ_NLS handling more robust
If a user set XZ_NLS=ON but find_package(Intl) failed or CMake version wasn't at least 3.20, the configuration would fail in a cryptic way. If XZ_NLS is enabled, require that CMake is new enough and that either gettext tools or pre-generated .gmo files are available. Otherwise fail the configuration. Previously missing gettext tools and .gmo files would only result in a warning. Missing man page translations are still only a warning. Thanks to Peter Seiderer for the bug report. Fixes: https://github.com/tukaani-project/xz/issues/129 Closes: https://github.com/tukaani-project/xz/pull/130
This commit is contained in:
parent
ec6157570e
commit
fb99f8e8c5
|
@ -310,47 +310,57 @@ if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_LIBRT)
|
||||||
tuklib_add_definition_if(ALL HAVE_CLOCK_MONOTONIC)
|
tuklib_add_definition_if(ALL HAVE_CLOCK_MONOTONIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Translation support requires CMake 3.20 because it added the Intl::Intl
|
# Translation support requires CMake 3.20 because it added the Intl::Intl
|
||||||
# target so we don't need to play with the individual variables.
|
# target so we don't need to play with the individual variables.
|
||||||
#
|
#
|
||||||
# The definition ENABLE_NLS is added only to those targets that use it, thus
|
# The definition ENABLE_NLS is added only to those targets that use it, thus
|
||||||
# it's not done here. (xz has translations, xzdec doesn't.)
|
# it's not done here. (xz has translations, xzdec doesn't.)
|
||||||
|
set(XZ_NLS_DEFAULT OFF)
|
||||||
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
|
||||||
find_package(Intl)
|
find_package(Intl)
|
||||||
find_package(Gettext)
|
find_package(Gettext)
|
||||||
|
|
||||||
if(Intl_FOUND)
|
if(Intl_FOUND)
|
||||||
option(XZ_NLS
|
set(XZ_NLS_DEFAULT ON)
|
||||||
"Native Language Support (translated messages and man pages)"
|
endif()
|
||||||
ON)
|
endif()
|
||||||
|
|
||||||
|
option(XZ_NLS "Native Language Support (translated messages and man pages)"
|
||||||
|
"${XZ_NLS_DEFAULT}")
|
||||||
|
|
||||||
|
if(XZ_NLS)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS "3.20")
|
||||||
|
message(FATAL_ERROR "XZ_NLS=ON requires CMake >= 3.20. "
|
||||||
|
"Upgrade to a newer CMake or set XZ_NLS=OFF.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT Intl_FOUND)
|
||||||
|
message(FATAL_ERROR "XZ_NLS=ON but find_package(Intl) failed. "
|
||||||
|
"Install libintl or set XZ_NLS=OFF.")
|
||||||
|
endif()
|
||||||
|
|
||||||
# If translation support is enabled but neither gettext tools or
|
# If translation support is enabled but neither gettext tools or
|
||||||
# pre-generated .gmo files exist, translation support cannot be
|
# pre-generated .gmo files exist, translation support cannot be enabled.
|
||||||
# enabled.
|
|
||||||
#
|
#
|
||||||
# The detection of pre-generated .gmo files is done by only
|
# The detection of pre-generated .gmo files is done by only
|
||||||
# checking for the existence of a single .gmo file; Ukrainian
|
# checking for the existence of a single .gmo file; Ukrainian
|
||||||
# is one of many translations that gets regular updates.
|
# is one of many translations that gets regular updates.
|
||||||
if(XZ_NLS AND NOT GETTEXT_FOUND AND
|
if(NOT GETTEXT_FOUND AND
|
||||||
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/uk.gmo")
|
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po/uk.gmo")
|
||||||
# This only sets the variable, not the cache variable!
|
# By default this message is shown only when new enough CMake is used
|
||||||
set(XZ_NLS OFF)
|
# and library support for translations was found. The assumptions is
|
||||||
|
|
||||||
# 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
|
# that in this situation the user might have interest in the
|
||||||
# translations. This also keeps this code simpler.
|
# translations. This also keeps this code simpler.
|
||||||
message(WARNING "Native language support (NLS) has been disabled. "
|
message(FATAL_ERROR "Native language support (NLS) requires either "
|
||||||
"NLS support requires either gettext tools or "
|
"gettext tools or pre-generated .gmo files. "
|
||||||
"pre-generated .gmo files. The latter are only "
|
"The latter are only available in distribution "
|
||||||
"available in distribution tarballs. "
|
"tarballs. "
|
||||||
"To avoid this warning, NLS can be explicitly "
|
"Install gettext tools or set XZ_NLS=OFF.")
|
||||||
"disabled by passing -DXZ_NLS=OFF to cmake.")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Warn if NLS is enabled but translated man pages are missing.
|
# Warn if translated man pages are missing.
|
||||||
if(UNIX AND XZ_NLS AND
|
if(UNIX AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po4a/man")
|
||||||
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/po4a/man")
|
|
||||||
message(WARNING "Native language support (NLS) has been enabled "
|
message(WARNING "Native language support (NLS) has been enabled "
|
||||||
"but pre-generated translated man pages "
|
"but pre-generated translated man pages "
|
||||||
"were not found and thus they won't be installed. "
|
"were not found and thus they won't be installed. "
|
||||||
|
@ -359,9 +369,9 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20")
|
||||||
|
|
||||||
# The *installed* name of the translation files is "xz.mo".
|
# The *installed* name of the translation files is "xz.mo".
|
||||||
set(TRANSLATION_DOMAIN "xz")
|
set(TRANSLATION_DOMAIN "xz")
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Add warning options for GCC or Clang. Keep this in sync with configure.ac.
|
# Add warning options for GCC or Clang. Keep this in sync with configure.ac.
|
||||||
#
|
#
|
||||||
# NOTE: add_compile_options() doesn't affect the feature checks;
|
# NOTE: add_compile_options() doesn't affect the feature checks;
|
||||||
|
|
Loading…
Reference in New Issue