FindIntl.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_IS_BUILT_IN
  24. .. versionadded:: 3.20
  25. whether ``intl`` is a part of the C library.
  26. .. note::
  27. On some platforms, such as Linux with GNU libc, the gettext
  28. functions are present in the C standard library and libintl
  29. is not required. ``Intl_LIBRARIES`` will be empty in this
  30. case.
  31. .. note::
  32. If you wish to use the Gettext tools (``msgmerge``,
  33. ``msgfmt``, etc.), use :module:`FindGettext`.
  34. #]=======================================================================]
  35. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  36. if(CMAKE_C_COMPILER_LOADED)
  37. include(${CMAKE_CURRENT_LIST_DIR}/CheckCSourceCompiles.cmake)
  38. elseif(CMAKE_CXX_COMPILER_LOADED)
  39. include(${CMAKE_CURRENT_LIST_DIR}/CheckCXXSourceCompiles.cmake)
  40. else()
  41. # If neither C nor CXX are loaded, implicit intl makes no sense.
  42. set(Intl_IS_BUILT_IN FALSE)
  43. endif()
  44. # Check if Intl is built in to the C library.
  45. if(NOT DEFINED Intl_IS_BUILT_IN)
  46. if(NOT DEFINED Intl_INCLUDE_DIR AND NOT DEFINED Intl_LIBRARY)
  47. cmake_push_check_state(RESET)
  48. set(CMAKE_REQUIRED_QUIET TRUE)
  49. set(Intl_IMPLICIT_TEST_CODE [[
  50. #include <libintl.h>
  51. int main(void) {
  52. gettext("");
  53. dgettext("", "");
  54. dcgettext("", "", 0);
  55. return 0;
  56. }
  57. ]])
  58. if(CMAKE_C_COMPILER_LOADED)
  59. check_c_source_compiles("${Intl_IMPLICIT_TEST_CODE}" Intl_IS_BUILT_IN)
  60. else()
  61. check_cxx_source_compiles("${Intl_IMPLICIT_TEST_CODE}" Intl_IS_BUILT_IN)
  62. endif()
  63. cmake_pop_check_state()
  64. else()
  65. set(Intl_IS_BUILT_IN FALSE)
  66. endif()
  67. endif()
  68. set(_Intl_REQUIRED_VARS)
  69. if(Intl_IS_BUILT_IN)
  70. set(_Intl_REQUIRED_VARS _Intl_IS_BUILT_IN_MSG)
  71. set(_Intl_IS_BUILT_IN_MSG "built in to C library")
  72. else()
  73. set(_Intl_REQUIRED_VARS Intl_LIBRARY Intl_INCLUDE_DIR)
  74. find_path(Intl_INCLUDE_DIR
  75. NAMES "libintl.h"
  76. DOC "libintl include directory")
  77. mark_as_advanced(Intl_INCLUDE_DIR)
  78. find_library(Intl_LIBRARY "intl" "libintl" NAMES_PER_DIR
  79. DOC "libintl libraries (if not in the C library)")
  80. mark_as_advanced(Intl_LIBRARY)
  81. endif()
  82. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  83. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Intl
  84. FOUND_VAR Intl_FOUND
  85. REQUIRED_VARS ${_Intl_REQUIRED_VARS}
  86. FAIL_MESSAGE "Failed to find Gettext libintl")
  87. unset(_Intl_REQUIRED_VARS)
  88. unset(_Intl_IS_BUILT_IN_MSG)
  89. if(Intl_FOUND)
  90. if(Intl_IS_BUILT_IN)
  91. set(Intl_INCLUDE_DIRS "")
  92. set(Intl_LIBRARIES "")
  93. else()
  94. set(Intl_INCLUDE_DIRS "${Intl_INCLUDE_DIR}")
  95. set(Intl_LIBRARIES "${Intl_LIBRARY}")
  96. endif()
  97. if(NOT TARGET Intl::Intl)
  98. add_library(Intl::Intl INTERFACE IMPORTED)
  99. set_target_properties(Intl::Intl PROPERTIES
  100. INTERFACE_INCLUDE_DIRECTORIES "${Intl_INCLUDE_DIRS}"
  101. INTERFACE_LINK_LIBRARIES "${Intl_LIBRARIES}")
  102. endif()
  103. endif()