FindGettextLib.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # This module find everything related to Gettext:
  2. # * development tools (msgfmt)
  3. # * libintl for runtime usage
  4. find_program(GETTEXT_MSGFMT
  5. NAMES msgfmt
  6. DOC "Path to Gettext msgfmt")
  7. if(GETTEXT_INCLUDE_DIR AND GETTEXT_LIBRARY)
  8. # This is only really used on Windows
  9. find_path(GETTEXT_INCLUDE_DIR NAMES libintl.h)
  10. find_library(GETTEXT_LIBRARY NAMES intl)
  11. set(GETTEXT_REQUIRED_VARS GETTEXT_INCLUDE_DIR GETTEXT_LIBRARY GETTEXT_MSGFMT)
  12. else()
  13. find_package(Intl)
  14. set(GETTEXT_INCLUDE_DIR ${Intl_INCLUDE_DIRS})
  15. set(GETTEXT_LIBRARY ${Intl_LIBRARIES})
  16. # Because intl may be part of the libc it's valid for the two variables to
  17. # be empty, therefore we can't just put them into GETTEXT_REQUIRED_VARS.
  18. if(Intl_FOUND)
  19. set(GETTEXT_REQUIRED_VARS GETTEXT_MSGFMT)
  20. else()
  21. set(GETTEXT_REQUIRED_VARS _LIBINTL_WAS_NOT_FOUND)
  22. endif()
  23. endif()
  24. include(FindPackageHandleStandardArgs)
  25. find_package_handle_standard_args(GettextLib DEFAULT_MSG ${GETTEXT_REQUIRED_VARS})
  26. if(GETTEXTLIB_FOUND)
  27. # Set up paths for building
  28. set(GETTEXT_PO_PATH ${CMAKE_SOURCE_DIR}/po)
  29. set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale/<locale>/LC_MESSAGES)
  30. set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}/<locale>/LC_MESSAGES)
  31. file(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*")
  32. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES minetest.pot)
  33. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES timestamp)
  34. macro(SET_MO_PATHS _buildvar _destvar _locale)
  35. string(REPLACE "<locale>" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH})
  36. string(REPLACE "<locale>" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH})
  37. endmacro()
  38. endif()