From 1aebc3c0cb5f8d9f1e56c8337bec7d404f773ee2 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Fri, 2 May 2025 14:31:58 +0100 Subject: [PATCH] Simplify logic around gettext/libintl use (#7582) * Simplify logic around gettext/libintl use Use CMake-provided FindIntl module to look for the library and includes. Don't check for functions existence, both `gettext()` and `ngettext()` are available for ages now. Remove Windows- and Mac-specific logic, always use the functions if found and ENABLE_NLS is set to ON; for rare cases where their use is unwanted, one could set CMAKE_DISABLE_FIND_PACKAGE_Intl to ON. * Don't install/use gettext from Homebrew for universal Mac builds Homebrew doesn't support universal libraries/binaries, hence only an unsuitable pure-arm64 library is being installed, leading to build failure as a result. Since it seems that gettext is still being installed as a dependency for some other package(s), pass CMAKE_DISABLE_FIND_PACKAGE_Intl to guarantee it's not being used. --- .github/workflows/actions.yml | 3 ++- libtransmission/CMakeLists.txt | 25 ++++++------------------- libtransmission/utils.h | 23 ++--------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index dd4f2838f..d1914489d 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -627,7 +627,7 @@ jobs: echo '${{ toJSON(runner) }}' sw_vers - name: Get Dependencies - run: brew install --formulae cmake gettext ninja node pkgconf + run: brew install --formulae cmake ninja node pkgconf - name: Get Source uses: actions/download-artifact@v4 with: @@ -643,6 +643,7 @@ jobs: -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_INSTALL_PREFIX=pfx \ -DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \ + -DCMAKE_DISABLE_FIND_PACKAGE_Intl=ON \ -DENABLE_CLI=${{ (needs.what-to-make.outputs.make-cli == 'true') && 'ON' || 'OFF' }} \ -DENABLE_DAEMON=${{ (needs.what-to-make.outputs.make-daemon == 'true') && 'ON' || 'OFF' }} \ -DENABLE_GTK=OFF \ diff --git a/libtransmission/CMakeLists.txt b/libtransmission/CMakeLists.txt index e4b529d47..573e94400 100644 --- a/libtransmission/CMakeLists.txt +++ b/libtransmission/CMakeLists.txt @@ -3,10 +3,7 @@ include(CheckLibraryExists) include(CheckSymbolExists) if(ENABLE_NLS) - check_library_exists(intl libintl_gettext "" HAVE_LIBINTL) - if(HAVE_LIBINTL) - set(LIBINTL_LIBRARY intl) - endif() + find_package(Intl) endif() check_symbol_exists(SO_REUSEPORT "sys/types.h;sys/socket.h" HAVE_SO_REUSEPORT) @@ -230,7 +227,7 @@ target_compile_definitions(${TR_NAME} $<$:WITH_MBEDTLS> $<$:WITH_OPENSSL> $<$:WITH_WOLFSSL> - $<$>:DISABLE_GETTEXT>) + $<$:ENABLE_GETTEXT>) tr_target_compile_definitions_for_headers(${TR_NAME} PRIVATE @@ -238,12 +235,6 @@ tr_target_compile_definitions_for_headers(${TR_NAME} xfs/xfs.h xlocale.h) -if(ENABLE_NLS) - tr_target_compile_definitions_for_headers(${TR_NAME} - PRIVATE - libintl.h) -endif() - tr_target_compile_definitions_for_functions(${TR_NAME} PRIVATE copyfile @@ -259,17 +250,13 @@ tr_target_compile_definitions_for_functions(${TR_NAME} pread pwrite sendfile64 - statvfs - PUBLIC - gettext - ngettext - REQUIRED_LIBS - $<$:${LIBINTL_LIBRARY}>) # gettext, ngettext + statvfs) target_include_directories(${TR_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_BINARY_DIR}/..) + ${CMAKE_CURRENT_BINARY_DIR}/.. + ${Intl_INCLUDE_DIRS}) if(ANDROID) find_library(log-lib log) @@ -287,7 +274,7 @@ target_link_libraries(${TR_NAME} dht::dht libutp::libutp libb64::libb64 - ${LIBINTL_LIBRARY} + ${Intl_LIBRARIES} ${LIBM_LIBRARY} ${LIBQUOTA_LIBRARY} ${TR_NETWORK_LIBRARIES} diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 6d35c8bd3..4c6e5cbe1 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -25,30 +25,11 @@ struct tr_error; * @{ */ -#if !defined(_) -#if defined(HAVE_GETTEXT) && !defined(__APPLE__) +#ifdef ENABLE_GETTEXT #include -#define _(a) gettext(a) -#else -#define _(a) (a) -#endif -#endif - -#if defined(HAVE_NGETTEXT) +#define _ gettext #define tr_ngettext ngettext #else -#define tr_ngettext(singular, plural, count) ((count) == 1 ? (singular) : (plural)) -#endif - -/* #define DISABLE_GETTEXT */ -#ifndef DISABLE_GETTEXT -#if defined(_WIN32) -#define DISABLE_GETTEXT -#endif -#endif -#ifdef DISABLE_GETTEXT -#undef _ -#undef tr_ngettext #define _(a) (a) #define tr_ngettext(singular, plural, count) ((count) == 1 ? (singular) : (plural)) #endif