Skip to content

Commit

Permalink
Defer searching for libintl to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Oct 13, 2022
1 parent af38bae commit e8ee4cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 52 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ Library specific options:
FREETYPE_LIBRARY - Path to libfreetype.a/libfreetype.so/freetype.lib
FREETYPE_DLL - Only on Windows; path to libfreetype-6.dll
GETTEXT_DLL - Only when building with gettext on Windows; paths to libintl + libiconv DLLs
GETTEXT_INCLUDE_DIR - Only when building with gettext; directory that contains iconv.h
GETTEXT_LIBRARY - Only when building with gettext on Windows; path to libintl.dll.a
GETTEXT_INCLUDE_DIR - Only when building with gettext; directory that contains libintl.h
GETTEXT_LIBRARY - Optional/platform-dependent with gettext; path to libintl.so/libintl.dll.a
GETTEXT_MSGFMT - Only when building with gettext; path to msgfmt/msgfmt.exe
ICONV_LIBRARY - Optional/platform-dependent; path to libiconv.so/libiconv.dylib
IRRLICHT_DLL - Only on Windows; path to IrrlichtMt.dll
IRRLICHT_INCLUDE_DIR - Directory that contains IrrCompileConfig.h (usable for server build only)
LEVELDB_INCLUDE_DIR - Only when building with LevelDB; directory that contains db.h
Expand Down
70 changes: 23 additions & 47 deletions cmake/Modules/FindGettextLib.cmake
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@

set(CUSTOM_GETTEXT_PATH "${PROJECT_SOURCE_DIR}/../../gettext"
CACHE FILEPATH "path to custom gettext")

find_path(GETTEXT_INCLUDE_DIR
NAMES libintl.h
PATHS "${CUSTOM_GETTEXT_PATH}/include"
DOC "GetText include directory")
# This module find everything related to Gettext:
# * development tools (msgfmt)
# * libintl for runtime usage

find_program(GETTEXT_MSGFMT
NAMES msgfmt
PATHS "${CUSTOM_GETTEXT_PATH}/bin"
DOC "Path to msgfmt")

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)
DOC "Path to Gettext msgfmt")

if(GETTEXT_INCLUDE_DIR AND GETTEXT_LIBRARY)
# This is only really used on Windows
find_path(GETTEXT_INCLUDE_DIR NAMES libintl.h)
find_library(GETTEXT_LIBRARY NAMES intl)

set(GETTEXT_REQUIRED_VARS GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
else()
find_package(Intl)
set(GETTEXT_INCLUDE_DIR ${Intl_INCLUDE_DIRS})
set(GETTEXT_LIBRARY ${Intl_LIBRARIES})

# Because intl may be part of the libc it's valid for the two variables to
# be empty, therefore we can't just put them into GETTEXT_REQUIRED_VARS.
if(Intl_FOUND)
set(GETTEXT_REQUIRED_VARS GETTEXT_MSGFMT)
else()
set(GETTEXT_LIB_NAMES
libintl.dll.a intl.dll.a libintl3.dll.a intl3.dll.a)
set(GETTEXT_REQUIRED_VARS _LIBINTL_WAS_NOT_FOUND)
endif()
find_library(GETTEXT_LIBRARY
NAMES ${GETTEXT_LIB_NAMES}
PATHS "${CUSTOM_GETTEXT_PATH}/lib"
DOC "GetText library")
endif(WIN32)

endif()

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 up paths for building
set(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po)
set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale/<locale>/LC_MESSAGES)
set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}/<locale>/LC_MESSAGES)
Expand Down
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,15 @@ else()
endif(HAVE_LIBRT)
endif(APPLE)

# Prefer local iconv if installed
find_library(ICONV_LIBRARY iconv)
mark_as_advanced(ICONV_LIBRARY)
if (ICONV_LIBRARY)
set(PLATFORM_LIBS ${PLATFORM_LIBS} ${ICONV_LIBRARY})
endif()

if (HAIKU)
set(PLATFORM_LIBS ${PLATFORM_LIBS} intl network)
set(PLATFORM_LIBS ${PLATFORM_LIBS} network)
endif()

endif()

check_include_files(endian.h HAVE_ENDIAN_H)
Expand Down

0 comments on commit e8ee4cb

Please sign in to comment.