FindLibuv.cmake 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 libuv library
  25. #
  26. # Input variables:
  27. #
  28. # LIBUV_INCLUDE_DIR The libuv include directory
  29. # LIBUV_LIBRARY Path to libuv library
  30. #
  31. # Result variables:
  32. #
  33. # LIBUV_FOUND System has libuv
  34. # LIBUV_INCLUDE_DIRS The libuv include directories
  35. # LIBUV_LIBRARIES The libuv library names
  36. # LIBUV_LIBRARY_DIRS The libuv library directories
  37. # LIBUV_CFLAGS Required compiler flags
  38. # LIBUV_VERSION Version of libuv
  39. if(CURL_USE_PKGCONFIG AND
  40. NOT DEFINED LIBUV_INCLUDE_DIR AND
  41. NOT DEFINED LIBUV_LIBRARY)
  42. find_package(PkgConfig QUIET)
  43. pkg_check_modules(LIBUV "libuv")
  44. endif()
  45. if(LIBUV_FOUND)
  46. string(REPLACE ";" " " LIBUV_CFLAGS "${LIBUV_CFLAGS}")
  47. message(STATUS "Found Libuv (via pkg-config): ${LIBUV_INCLUDE_DIRS} (found version \"${LIBUV_VERSION}\")")
  48. else()
  49. find_path(LIBUV_INCLUDE_DIR NAMES "uv.h")
  50. find_library(LIBUV_LIBRARY NAMES "uv" "libuv")
  51. if(LIBUV_INCLUDE_DIR AND EXISTS "${LIBUV_INCLUDE_DIR}/uv/version.h")
  52. set(_version_regex1 "#[\t ]*define[\t ]+UV_VERSION_MAJOR[\t ]+([0-9]+).*")
  53. set(_version_regex2 "#[\t ]*define[\t ]+UV_VERSION_MINOR[\t ]+([0-9]+).*")
  54. set(_version_regex3 "#[\t ]*define[\t ]+UV_VERSION_PATCH[\t ]+([0-9]+).*")
  55. file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str1 REGEX "${_version_regex1}")
  56. file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str2 REGEX "${_version_regex2}")
  57. file(STRINGS "${LIBUV_INCLUDE_DIR}/uv/version.h" _version_str3 REGEX "${_version_regex3}")
  58. string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
  59. string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
  60. string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
  61. set(LIBUV_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
  62. unset(_version_regex1)
  63. unset(_version_regex2)
  64. unset(_version_regex3)
  65. unset(_version_str1)
  66. unset(_version_str2)
  67. unset(_version_str3)
  68. endif()
  69. include(FindPackageHandleStandardArgs)
  70. find_package_handle_standard_args(Libuv
  71. REQUIRED_VARS
  72. LIBUV_INCLUDE_DIR
  73. LIBUV_LIBRARY
  74. VERSION_VAR
  75. LIBUV_VERSION
  76. )
  77. if(LIBUV_FOUND)
  78. set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
  79. set(LIBUV_LIBRARIES ${LIBUV_LIBRARY})
  80. endif()
  81. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
  82. endif()