FindGettextLib.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # If the executable is expected to be ran from <source dir>/bin/, also
  30. # generate the locale in <source dir>/locale/.
  31. if(RUN_IN_PLACE AND NOT CMAKE_CROSSCOMPILING)
  32. set(GETTEXT_MO_BUILD_PATH ${CMAKE_SOURCE_DIR}/locale/<locale>/LC_MESSAGES)
  33. else()
  34. set(GETTEXT_MO_BUILD_PATH ${CMAKE_BINARY_DIR}/locale/<locale>/LC_MESSAGES)
  35. endif()
  36. set(GETTEXT_MO_DEST_PATH ${LOCALEDIR}/<locale>/LC_MESSAGES)
  37. file(GLOB GETTEXT_AVAILABLE_LOCALES RELATIVE ${GETTEXT_PO_PATH} "${GETTEXT_PO_PATH}/*")
  38. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES ${PROJECT_NAME}.pot)
  39. list(REMOVE_ITEM GETTEXT_AVAILABLE_LOCALES timestamp)
  40. macro(SET_MO_PATHS _buildvar _destvar _locale)
  41. string(REPLACE "<locale>" ${_locale} ${_buildvar} ${GETTEXT_MO_BUILD_PATH})
  42. string(REPLACE "<locale>" ${_locale} ${_destvar} ${GETTEXT_MO_DEST_PATH})
  43. endmacro()
  44. endif()