FindLibidn2.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. # Find the libidn2 library
  25. #
  26. # Input variables:
  27. #
  28. # - `LIBIDN2_INCLUDE_DIR`: Absolute path to libidn2 include directory.
  29. # - `LIBIDN2_LIBRARY`: Absolute path to `libidn2` library.
  30. #
  31. # Result variables:
  32. #
  33. # - `LIBIDN2_FOUND`: System has libidn2.
  34. # - `LIBIDN2_INCLUDE_DIRS`: The libidn2 include directories.
  35. # - `LIBIDN2_LIBRARIES`: The libidn2 library names.
  36. # - `LIBIDN2_LIBRARY_DIRS`: The libidn2 library directories.
  37. # - `LIBIDN2_PC_REQUIRES`: The libidn2 pkg-config packages.
  38. # - `LIBIDN2_CFLAGS`: Required compiler flags.
  39. # - `LIBIDN2_VERSION`: Version of libidn2.
  40. set(LIBIDN2_PC_REQUIRES "libidn2")
  41. if(CURL_USE_PKGCONFIG AND
  42. NOT DEFINED LIBIDN2_INCLUDE_DIR AND
  43. NOT DEFINED LIBIDN2_LIBRARY)
  44. find_package(PkgConfig QUIET)
  45. pkg_check_modules(LIBIDN2 ${LIBIDN2_PC_REQUIRES})
  46. endif()
  47. if(LIBIDN2_FOUND)
  48. set(Libidn2_FOUND TRUE)
  49. string(REPLACE ";" " " LIBIDN2_CFLAGS "${LIBIDN2_CFLAGS}")
  50. message(STATUS "Found Libidn2 (via pkg-config): ${LIBIDN2_INCLUDE_DIRS} (found version \"${LIBIDN2_VERSION}\")")
  51. else()
  52. find_path(LIBIDN2_INCLUDE_DIR NAMES "idn2.h")
  53. find_library(LIBIDN2_LIBRARY NAMES "idn2" "libidn2")
  54. unset(LIBIDN2_VERSION CACHE)
  55. if(LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/idn2.h")
  56. set(_version_regex "#[\t ]*define[\t ]+IDN2_VERSION[\t ]+\"([^\"]*)\"")
  57. file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" _version_str REGEX "${_version_regex}")
  58. string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
  59. set(LIBIDN2_VERSION "${_version_str}")
  60. unset(_version_regex)
  61. unset(_version_str)
  62. endif()
  63. include(FindPackageHandleStandardArgs)
  64. find_package_handle_standard_args(Libidn2
  65. REQUIRED_VARS
  66. LIBIDN2_INCLUDE_DIR
  67. LIBIDN2_LIBRARY
  68. VERSION_VAR
  69. LIBIDN2_VERSION
  70. )
  71. if(LIBIDN2_FOUND)
  72. set(LIBIDN2_INCLUDE_DIRS ${LIBIDN2_INCLUDE_DIR})
  73. set(LIBIDN2_LIBRARIES ${LIBIDN2_LIBRARY})
  74. endif()
  75. mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARY)
  76. endif()