FindGettextLib.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. set(CUSTOM_GETTEXT_PATH "${PROJECT_SOURCE_DIR}/../../gettext"
  2. CACHE FILEPATH "path to custom gettext")
  3. find_path(GETTEXT_INCLUDE_DIR
  4. NAMES libintl.h
  5. PATHS "${CUSTOM_GETTEXT_PATH}/include"
  6. DOC "GetText include directory")
  7. find_program(GETTEXT_MSGFMT
  8. NAMES msgfmt
  9. PATHS "${CUSTOM_GETTEXT_PATH}/bin"
  10. DOC "Path to msgfmt")
  11. set(GETTEXT_REQUIRED_VARS GETTEXT_INCLUDE_DIR GETTEXT_MSGFMT)
  12. if(APPLE)
  13. find_library(GETTEXT_LIBRARY
  14. NAMES libintl.a
  15. PATHS "${CUSTOM_GETTEXT_PATH}/lib"
  16. DOC "GetText library")
  17. find_library(ICONV_LIBRARY
  18. NAMES libiconv.dylib
  19. PATHS "/usr/lib"
  20. DOC "IConv library")
  21. set(GETTEXT_REQUIRED_VARS ${GETTEXT_REQUIRED_VARS} GETTEXT_LIBRARY ICONV_LIBRARY)
  22. endif(APPLE)
  23. # Modern Linux, as well as OSX, does not require special linking because
  24. # GetText is part of glibc.
  25. # TODO: check the requirements on other BSDs and older Linux
  26. if(WIN32)
  27. if(MSVC)
  28. set(GETTEXT_LIB_NAMES
  29. libintl.lib intl.lib libintl3.lib intl3.lib)
  30. else()
  31. set(GETTEXT_LIB_NAMES
  32. libintl.dll.a intl.dll.a libintl3.dll.a intl3.dll.a)
  33. endif()
  34. find_library(GETTEXT_LIBRARY
  35. NAMES ${GETTEXT_LIB_NAMES}
  36. PATHS "${CUSTOM_GETTEXT_PATH}/lib"
  37. DOC "GetText library")
  38. find_file(GETTEXT_DLL
  39. NAMES libintl.dll intl.dll libintl3.dll intl3.dll
  40. PATHS "${CUSTOM_GETTEXT_PATH}/bin" "${CUSTOM_GETTEXT_PATH}/lib"
  41. DOC "gettext *intl*.dll")
  42. find_file(GETTEXT_ICONV_DLL
  43. NAMES libiconv2.dll
  44. PATHS "${CUSTOM_GETTEXT_PATH}/bin" "${CUSTOM_GETTEXT_PATH}/lib"
  45. DOC "gettext *iconv*.lib")
  46. set(GETTEXT_REQUIRED_VARS ${GETTEXT_REQUIRED_VARS} GETTEXT_DLL GETTEXT_ICONV_DLL)
  47. endif(WIN32)
  48. include(FindPackageHandleStandardArgs)
  49. find_package_handle_standard_args(GettextLib DEFAULT_MSG ${GETTEXT_REQUIRED_VARS})
  50. if(GETTEXTLIB_FOUND)
  51. # BSD variants require special linkage as they don't use glibc
  52. if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly")
  53. set(GETTEXT_LIBRARY "intl")
  54. endif()
  55. set(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po)
  56. set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale/<locale>/LC_MESSAGES)
  57. set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}/<locale>/LC_MESSAGES)
  58. file(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*")
  59. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES minetest.pot)
  60. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES timestamp)
  61. macro(SET_MO_PATHS _buildvar _destvar _locale)
  62. string(REPLACE "<locale>" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH})
  63. string(REPLACE "<locale>" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH})
  64. endmacro()
  65. endif()