FindLibIntl.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. list(APPEND 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. list(APPEND CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
  35. endif()
  36. if (MSVC)
  37. list(APPEND CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
  38. endif()
  39. check_c_source_compiles("
  40. #include <libintl.h>
  41. int main(int argc, char** argv) {
  42. gettext(\"foo\");
  43. ngettext(\"foo\", \"bar\", 1);
  44. bindtextdomain(\"foo\", \"bar\");
  45. bind_textdomain_codeset(\"foo\", \"bar\");
  46. textdomain(\"foo\");
  47. }" HAVE_WORKING_LIBINTL)
  48. if (MSVC)
  49. list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
  50. endif()
  51. if (LibIntl_INCLUDE_DIR)
  52. list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${LibIntl_INCLUDE_DIR}")
  53. endif()
  54. if (LibIntl_LIBRARY)
  55. list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}")
  56. endif()
  57. if (HAVE_WORKING_LIBINTL)
  58. # On some systems (linux+glibc) libintl is passively available.
  59. # If HAVE_WORKING_LIBINTL then we consider the requirement satisfied.
  60. # Unset REQUIRED so that libfind_process(LibIntl) can proceed.
  61. if(LibIntl_FIND_REQUIRED)
  62. unset(LibIntl_FIND_REQUIRED)
  63. endif()
  64. set(LibIntl_FIND_QUIETLY ON)
  65. check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR)
  66. endif()
  67. set(LibIntl_PROCESS_INCLUDES LibIntl_INCLUDE_DIR)
  68. set(LibIntl_PROCESS_LIBS LibIntl_LIBRARY)
  69. libfind_process(LibIntl)