FindIntl.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindIntl
  5. --------
  6. .. versionadded:: 3.2
  7. Find the Gettext libintl headers and libraries.
  8. This module reports information about the Gettext libintl
  9. installation in several variables.
  10. .. variable:: Intl_FOUND
  11. True if libintl is found.
  12. .. variable:: Intl_INCLUDE_DIRS
  13. The directory containing the libintl headers.
  14. .. variable:: Intl_LIBRARIES
  15. The intl libraries to be linked.
  16. .. versionadded:: 3.20
  17. This module defines :prop_tgt:`IMPORTED` target ``Intl::Intl``.
  18. The following cache variables may also be set:
  19. .. variable:: Intl_INCLUDE_DIR
  20. The directory containing the libintl headers
  21. .. variable:: Intl_LIBRARY
  22. The libintl library (if any)
  23. .. variable:: Intl_HAVE_GETTEXT_BUILTIN
  24. .. versionadded:: 3.20
  25. True if gettext is in the C library
  26. .. variable:: Intl_HAVE_DCGETTEXT_BUILTIN
  27. .. versionadded:: 3.20
  28. True if dcgettext is in the C library
  29. .. variable:: Intl_IS_BUILTIN
  30. .. versionadded:: 3.20
  31. whether intl is a part of the C library determined from the result of
  32. Intl_HAVE_GETTEXT_BUILTIN and Intl_HAVE_DCGETTEXT_BUILTIN
  33. .. note::
  34. On some platforms, such as Linux with GNU libc, the gettext
  35. functions are present in the C standard library and libintl
  36. is not required. ``Intl_LIBRARIES`` will be empty in this
  37. case.
  38. .. note::
  39. If you wish to use the Gettext tools (``msgmerge``,
  40. ``msgfmt``, etc.), use :module:`FindGettext`.
  41. #]=======================================================================]
  42. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  43. include(${CMAKE_CURRENT_LIST_DIR}/CheckSymbolExists.cmake)
  44. # Check if we have libintl is a part of libc
  45. cmake_push_check_state(RESET)
  46. set(CMAKE_REQUIRED_QUIET TRUE)
  47. check_symbol_exists(gettext libintl.h Intl_HAVE_GETTEXT_BUILTIN)
  48. check_symbol_exists(dcgettext libintl.h Intl_HAVE_DCGETTEXT_BUILTIN) # redundant check
  49. cmake_pop_check_state()
  50. if(Intl_HAVE_GETTEXT_BUILTIN AND Intl_HAVE_DCGETTEXT_BUILTIN)
  51. set(Intl_IS_BUILTIN TRUE)
  52. else()
  53. set(Intl_IS_BUILTIN FALSE)
  54. endif()
  55. # Find include directory
  56. find_path(Intl_INCLUDE_DIR
  57. NAMES "libintl.h"
  58. DOC "libintl include directory")
  59. mark_as_advanced(Intl_INCLUDE_DIR)
  60. # Find all Intl libraries
  61. set(Intl_REQUIRED_VARS)
  62. if(NOT Intl_IS_BUILTIN)
  63. find_library(Intl_LIBRARY "intl" "libintl" NAMES_PER_DIR
  64. DOC "libintl libraries (if not in the C library)")
  65. mark_as_advanced(Intl_LIBRARY)
  66. list(APPEND Intl_REQUIRED_VARS Intl_LIBRARY)
  67. endif()
  68. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  69. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Intl
  70. FOUND_VAR Intl_FOUND
  71. REQUIRED_VARS Intl_INCLUDE_DIR ${Intl_REQUIRED_VARS}
  72. FAIL_MESSAGE "Failed to find Gettext libintl")
  73. unset(Intl_REQUIRED_VARS)
  74. if(Intl_FOUND)
  75. set(Intl_INCLUDE_DIRS "${Intl_INCLUDE_DIR}")
  76. set(Intl_LIBRARIES "${Intl_LIBRARY}")
  77. if(NOT TARGET Intl::Intl)
  78. add_library(Intl::Intl INTERFACE IMPORTED)
  79. set_target_properties(Intl::Intl PROPERTIES
  80. INTERFACE_INCLUDE_DIRECTORIES "${Intl_INCLUDE_DIRS}"
  81. INTERFACE_LINK_LIBRARIES "${Intl_LIBRARIES}")
  82. endif()
  83. endif()