Browse Source

Defer searching for libintl to CMake

resolves #12800
sfan5 1 year ago
parent
commit
e8ee4cb40d
3 changed files with 28 additions and 52 deletions
  1. 3 2
      README.md
  2. 23 47
      cmake/Modules/FindGettextLib.cmake
  3. 2 3
      src/CMakeLists.txt

+ 3 - 2
README.md

@@ -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

+ 23 - 47
cmake/Modules/FindGettextLib.cmake

@@ -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)

+ 2 - 3
src/CMakeLists.txt

@@ -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)