FindLibIntl.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # - Try to find libintl
  2. # Once done, this will define
  3. #
  4. # LibIntl_FOUND - system has libintl
  5. # LibIntl_INCLUDE_DIRS - the libintl include directories
  6. # LibIntl_LIBRARIES - link these to use libintl
  7. include(CheckCSourceCompiles)
  8. include(CheckVariableExists)
  9. include(LibFindMacros)
  10. # Append custom gettext path to CMAKE_PREFIX_PATH
  11. # if installed via Mac Hombrew
  12. if (CMAKE_HOST_APPLE)
  13. find_program(HOMEBREW_PROG brew)
  14. if (EXISTS ${HOMEBREW_PROG})
  15. execute_process(COMMAND ${HOMEBREW_PROG} --prefix gettext
  16. OUTPUT_STRIP_TRAILING_WHITESPACE
  17. OUTPUT_VARIABLE HOMEBREW_GETTEXT_PREFIX)
  18. list(APPEND CMAKE_PREFIX_PATH "${HOMEBREW_GETTEXT_PREFIX}")
  19. endif()
  20. endif()
  21. find_path(LibIntl_INCLUDE_DIR
  22. NAMES libintl.h
  23. PATH_SUFFIXES gettext
  24. )
  25. find_library(LibIntl_LIBRARY
  26. NAMES intl libintl
  27. )
  28. if (LibIntl_INCLUDE_DIR)
  29. set(CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}")
  30. endif()
  31. # On some systems (linux+glibc) libintl is passively available.
  32. # So only specify the library if one was found.
  33. if (LibIntl_LIBRARY)
  34. set(CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
  35. endif()
  36. check_c_source_compiles("
  37. #include <libintl.h>
  38. int main(int argc, char** argv) {
  39. gettext(\"foo\");
  40. ngettext(\"foo\", \"bar\", 1);
  41. bindtextdomain(\"foo\", \"bar\");
  42. bind_textdomain_codeset(\"foo\", \"bar\");
  43. textdomain(\"foo\");
  44. }" HAVE_WORKING_LIBINTL)
  45. if (HAVE_WORKING_LIBINTL)
  46. # On some systems (linux+glibc) libintl is passively available.
  47. # If HAVE_WORKING_LIBINTL then we consider the requirement satisfied.
  48. # Unset REQUIRED so that libfind_process(LibIntl) can proceed.
  49. if(LibIntl_FIND_REQUIRED)
  50. unset(LibIntl_FIND_REQUIRED)
  51. endif()
  52. check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR)
  53. endif()
  54. set(LibIntl_PROCESS_INCLUDES LibIntl_INCLUDE_DIR)
  55. set(LibIntl_PROCESS_LIBS LibIntl_LIBRARY)
  56. libfind_process(LibIntl)