From a08a72493176110e6848462a3c90d5f6921c6274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski=20=F0=9F=A4=8D=F0=9F=92=99?= =?UTF-8?q?=F0=9F=A4=8D?= Date: Mon, 10 Oct 2022 11:27:14 +0700 Subject: [PATCH] Update FindGettextLib.cmake (from the same file in minetest/minetest repo) seems to work fine --- cmake/Modules/FindGettextLib.cmake | 81 ++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/cmake/Modules/FindGettextLib.cmake b/cmake/Modules/FindGettextLib.cmake index 6a85351..8aea256 100644 --- a/cmake/Modules/FindGettextLib.cmake +++ b/cmake/Modules/FindGettextLib.cmake @@ -1,28 +1,69 @@ # Package finder for gettext libs and include files -SET(CUSTOM_GETTEXT_PATH "${PROJECT_SOURCE_DIR}/../../gettext" +set(CUSTOM_GETTEXT_PATH "${PROJECT_SOURCE_DIR}/../../gettext" CACHE FILEPATH "path to custom gettext") -# by default -SET(GETTEXT_FOUND FALSE) +find_path(GETTEXT_INCLUDE_DIR + NAMES libintl.h + PATHS "${CUSTOM_GETTEXT_PATH}/include" + DOC "GetText include directory") -FIND_PROGRAM(GETTEXT_MSGFMT +find_program(GETTEXT_MSGFMT NAMES msgfmt PATHS "${CUSTOM_GETTEXT_PATH}/bin" - DOC "path to msgfmt") + DOC "Path to msgfmt") -IF(GETTEXT_MSGFMT) - SET(GETTEXT_FOUND TRUE) - SET(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po) - SET(GETTEXT_MO_BUILD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../data/locale/) - SET(GETTEXT_MO_DEST_PATH ${SHAREDIR}/locale/) - FILE(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*") - LIST(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES voxelands.pot) - MACRO(SET_MO_PATHS _buildvar _destvar _locale) - STRING(REPLACE "" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH}) - STRING(REPLACE "" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH}) - ENDMACRO(SET_MO_PATHS) -ELSE() - SET(GETTEXT_INCLUDE_DIR "") - SET(GETTEXT_LIBRARY "") -ENDIF() +set(GETTEXT_REQUIRED_VARS GETTEXT_INCLUDE_DIR GETTEXT_MSGFMT) + +if(APPLE) + find_library(GETTEXT_LIBRARY + NAMES libintl.a + PATHS "${CUSTOM_GETTEXT_PATH}/lib" + DOC "GetText library") + + find_library(ICONV_LIBRARY + NAMES libiconv.dylib + PATHS "/usr/lib" + DOC "IConv library") + set(GETTEXT_REQUIRED_VARS ${GETTEXT_REQUIRED_VARS} GETTEXT_LIBRARY ICONV_LIBRARY) +endif(APPLE) + +# Modern Linux, as well as OSX, does not require special linking because +# GetText is part of glibc. +# TODO: check the requirements on other BSDs and older Linux +if(WIN32) + if(MSVC) + set(GETTEXT_LIB_NAMES + libintl.lib intl.lib libintl3.lib intl3.lib) + else() + set(GETTEXT_LIB_NAMES + libintl.dll.a intl.dll.a libintl3.dll.a intl3.dll.a) + endif() + find_library(GETTEXT_LIBRARY + NAMES ${GETTEXT_LIB_NAMES} + PATHS "${CUSTOM_GETTEXT_PATH}/lib" + DOC "GetText library") +endif(WIN32) + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GettextLib DEFAULT_MSG ${GETTEXT_REQUIRED_VARS}) + + +if(GETTEXTLIB_FOUND) + # BSD variants require special linkage as they don't use glibc + if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly") + set(GETTEXT_LIBRARY "intl") + endif() + + set(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po) + set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale//LC_MESSAGES) + set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}//LC_MESSAGES) + file(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*") + list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES minetest.pot) + list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES timestamp) + macro(SET_MO_PATHS _buildvar _destvar _locale) + string(REPLACE "" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH}) + string(REPLACE "" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH}) + endmacro() +endif()