From 3184bb92e61b0199a3663d8b43799407434fa091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 15 Oct 2023 14:58:26 +0200 Subject: [PATCH] core: make libintl.h required if CMake option ENABLE_NLS is enabled (issue #2031) --- CMakeLists.txt | 6 ++---- ChangeLog.adoc | 2 +- cmake/FindGettext.cmake | 42 +++++++++++++++++++++-------------------- config.h.cmake | 1 - src/core/wee-doc.c | 2 ++ src/core/weechat.h | 6 +----- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8512cbd7..59ae20502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,10 +246,8 @@ add_subdirectory(icons) if(ENABLE_NLS) find_package(Gettext REQUIRED) add_definitions(-DENABLE_NLS) - find_package(Intl) - if(Intl_FOUND) - list(APPEND EXTRA_LIBS "${Intl_LIBRARIES}") - endif() + find_package(Intl REQUIRED) + list(APPEND EXTRA_LIBS "${Intl_LIBRARIES}") add_subdirectory(po) else() add_custom_target(translations COMMAND true) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 12fb682a7..b6addc274 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -21,7 +21,7 @@ Bug fixes:: Build:: - * core: fix build error if CMake option ENABLE_NLS is turned to off or if required dependencies are not found (issue #2026) + * core: fix build error if CMake option ENABLE_NLS is turned to off or if required dependencies are not found (issue #2026, issue #2031) [[v4.0.5]] == Version 4.0.5 (2023-09-24) diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake index 358734688..2460e190b 100644 --- a/cmake/FindGettext.cmake +++ b/cmake/FindGettext.cmake @@ -45,26 +45,28 @@ set(CMAKE_REQUIRED_INCLUDES ${LIBINTL_INCLUDE}) check_include_files(libintl.h HAVE_LIBINTL_H) -if(HAVE_LIBINTL_H) - check_function_exists(dgettext LIBC_HAS_DGETTEXT) - if(LIBC_HAS_DGETTEXT) - set(GETTEXT_FOUND TRUE) - else() - find_library(LIBINTL_LIBRARY NAMES intl - PATHS - /usr/local/lib - /usr/lib - ) - if(LIBINTL_LIBRARY) - if(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - set(CMAKE_REQUIRED_LIBRARIES "iconv") - check_library_exists(${LIBINTL_LIBRARY} "libintl_dgettext" "" LIBINTL_HAS_DGETTEXT) - else() - check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT) - endif() - if(LIBINTL_HAS_DGETTEXT) - set(GETTEXT_FOUND TRUE) - endif() +if(NOT HAVE_LIBINTL_H) + message(SEND_ERROR "Header libintl.h not found, required if ENABLE_NLS is enabled") +endif() + +check_function_exists(dgettext LIBC_HAS_DGETTEXT) +if(LIBC_HAS_DGETTEXT) + set(GETTEXT_FOUND TRUE) +else() + find_library(LIBINTL_LIBRARY NAMES intl + PATHS + /usr/local/lib + /usr/lib + ) + if(LIBINTL_LIBRARY) + if(${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") + set(CMAKE_REQUIRED_LIBRARIES "iconv") + check_library_exists(${LIBINTL_LIBRARY} "libintl_dgettext" "" LIBINTL_HAS_DGETTEXT) + else() + check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT) + endif() + if(LIBINTL_HAS_DGETTEXT) + set(GETTEXT_FOUND TRUE) endif() endif() endif() diff --git a/config.h.cmake b/config.h.cmake index 462dcf36c..a9010448d 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,4 +1,3 @@ -#cmakedefine HAVE_LIBINTL_H #cmakedefine HAVE_SYS_RESOURCE_H #cmakedefine HAVE_FLOCK #cmakedefine HAVE_LANGINFO_CODESET diff --git a/src/core/wee-doc.c b/src/core/wee-doc.c index d06e878ab..704c17f50 100644 --- a/src/core/wee-doc.c +++ b/src/core/wee-doc.c @@ -1662,9 +1662,11 @@ doc_generate (const char *path) * (this is used to generate documentation without installing WeeChat, * that means no need to run `make install`) */ +#ifdef ENABLE_NLS localedir = getenv ("WEECHAT_DOCGEN_LOCALEDIR"); if (localedir && localedir[0]) bindtextdomain (PACKAGE, localedir); +#endif /* ENABLE_NLS */ for (i = 0; locales[i]; i++) { diff --git a/src/core/weechat.h b/src/core/weechat.h index 47d395c89..af2ee8994 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -33,11 +33,7 @@ #include #if defined(ENABLE_NLS) && !defined(_) - #ifdef HAVE_LIBINTL_H - #include - #else - #include "../../intl/libintl.h" - #endif /* HAVE_LIBINTL_H */ + #include #define _(string) gettext(string) #define NG_(single,plural,number) ngettext(single,plural,number) #ifdef gettext_noop