FindLibUV.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # - Try to find libuv
  2. # Once done, this will define
  3. #
  4. # LIBUV_FOUND - system has libuv
  5. # LIBUV_INCLUDE_DIRS - the libuv include directories
  6. # LIBUV_LIBRARIES - link these to use libuv
  7. #
  8. # Set the LIBUV_USE_STATIC variable to specify if static libraries should
  9. # be preferred to shared ones.
  10. find_package(PkgConfig)
  11. if (PKG_CONFIG_FOUND)
  12. pkg_check_modules(PC_LIBUV QUIET libuv)
  13. endif()
  14. find_path(LIBUV_INCLUDE_DIR uv.h
  15. HINTS ${PC_LIBUV_INCLUDEDIR} ${PC_LIBUV_INCLUDE_DIRS}
  16. ${LIMIT_SEARCH})
  17. # If we're asked to use static linkage, add libuv.a as a preferred library name.
  18. if(LIBUV_USE_STATIC)
  19. list(APPEND LIBUV_NAMES
  20. "${CMAKE_STATIC_LIBRARY_PREFIX}uv${CMAKE_STATIC_LIBRARY_SUFFIX}")
  21. endif(LIBUV_USE_STATIC)
  22. list(APPEND LIBUV_NAMES uv)
  23. find_library(LIBUV_LIBRARY NAMES ${LIBUV_NAMES}
  24. HINTS ${PC_LIBUV_LIBDIR} ${PC_LIBUV_LIBRARY_DIRS}
  25. ${LIMIT_SEARCH})
  26. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
  27. set(LIBUV_LIBRARIES ${LIBUV_LIBRARY})
  28. set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
  29. # Deal with the fact that libuv.pc is missing important dependency information.
  30. include(CheckLibraryExists)
  31. check_library_exists(dl dlopen "dlfcn.h" HAVE_LIBDL)
  32. if(HAVE_LIBDL)
  33. list(APPEND LIBUV_LIBRARIES dl)
  34. endif()
  35. check_library_exists(kstat kstat_lookup "kstat.h" HAVE_LIBKSTAT)
  36. if(HAVE_LIBKSTAT)
  37. list(APPEND LIBUV_LIBRARIES kstat)
  38. endif()
  39. check_library_exists(kvm kvm_open "kvm.h" HAVE_LIBKVM)
  40. if(HAVE_LIBKVM)
  41. list(APPEND LIBUV_LIBRARIES kvm)
  42. endif()
  43. check_library_exists(nsl gethostbyname "nsl.h" HAVE_LIBNSL)
  44. if(HAVE_LIBNSL)
  45. list(APPEND LIBUV_LIBRARIES nsl)
  46. endif()
  47. check_library_exists(perfstat perfstat_cpu "libperfstat.h" HAVE_LIBPERFSTAT)
  48. if(HAVE_LIBPERFSTAT)
  49. list(APPEND LIBUV_LIBRARIES perfstat)
  50. endif()
  51. check_library_exists(rt clock_gettime "time.h" HAVE_LIBRT)
  52. if(HAVE_LIBRT)
  53. list(APPEND LIBUV_LIBRARIES rt)
  54. endif()
  55. check_library_exists(sendfile sendfile "" HAVE_LIBSENDFILE)
  56. if(HAVE_LIBSENDFILE)
  57. list(APPEND LIBUV_LIBRARIES sendfile)
  58. endif()
  59. include(FindPackageHandleStandardArgs)
  60. # handle the QUIETLY and REQUIRED arguments and set LIBUV_FOUND to TRUE
  61. # if all listed variables are TRUE
  62. find_package_handle_standard_args(LibUV DEFAULT_MSG
  63. LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
  64. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)