FindLibUV.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. find_package(PkgConfig)
  8. if (PKG_CONFIG_FOUND)
  9. pkg_check_modules(PC_LIBUV QUIET libuv)
  10. endif()
  11. find_path(LIBUV_INCLUDE_DIR uv.h
  12. HINTS ${PC_LIBUV_INCLUDEDIR} ${PC_LIBUV_INCLUDE_DIRS})
  13. list(APPEND LIBUV_NAMES uv)
  14. find_library(LIBUV_LIBRARY NAMES ${LIBUV_NAMES}
  15. HINTS ${PC_LIBUV_LIBDIR} ${PC_LIBUV_LIBRARY_DIRS})
  16. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
  17. if(PC_LIBUV_LIBRARIES)
  18. list(REMOVE_ITEM PC_LIBUV_LIBRARIES uv)
  19. endif()
  20. set(LIBUV_LIBRARIES ${LIBUV_LIBRARY} ${PC_LIBUV_LIBRARIES})
  21. set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
  22. # Deal with the fact that libuv.pc is missing important dependency information.
  23. include(CheckLibraryExists)
  24. check_library_exists(dl dlopen "dlfcn.h" HAVE_LIBDL)
  25. if(HAVE_LIBDL)
  26. list(APPEND LIBUV_LIBRARIES dl)
  27. endif()
  28. check_library_exists(kstat kstat_lookup "kstat.h" HAVE_LIBKSTAT)
  29. if(HAVE_LIBKSTAT)
  30. list(APPEND LIBUV_LIBRARIES kstat)
  31. endif()
  32. check_library_exists(kvm kvm_open "kvm.h" HAVE_LIBKVM)
  33. if(HAVE_LIBKVM AND NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  34. list(APPEND LIBUV_LIBRARIES kvm)
  35. endif()
  36. check_library_exists(nsl gethostbyname "nsl.h" HAVE_LIBNSL)
  37. if(HAVE_LIBNSL)
  38. list(APPEND LIBUV_LIBRARIES nsl)
  39. endif()
  40. check_library_exists(perfstat perfstat_cpu "libperfstat.h" HAVE_LIBPERFSTAT)
  41. if(HAVE_LIBPERFSTAT)
  42. list(APPEND LIBUV_LIBRARIES perfstat)
  43. endif()
  44. check_library_exists(rt clock_gettime "time.h" HAVE_LIBRT)
  45. if(HAVE_LIBRT)
  46. list(APPEND LIBUV_LIBRARIES rt)
  47. endif()
  48. check_library_exists(sendfile sendfile "" HAVE_LIBSENDFILE)
  49. if(HAVE_LIBSENDFILE)
  50. list(APPEND LIBUV_LIBRARIES sendfile)
  51. endif()
  52. if(WIN32)
  53. # check_library_exists() does not work for Win32 API calls in X86 due to name
  54. # mangling calling conventions
  55. list(APPEND LIBUV_LIBRARIES iphlpapi)
  56. list(APPEND LIBUV_LIBRARIES psapi)
  57. list(APPEND LIBUV_LIBRARIES userenv)
  58. list(APPEND LIBUV_LIBRARIES ws2_32)
  59. endif()
  60. include(FindPackageHandleStandardArgs)
  61. # handle the QUIETLY and REQUIRED arguments and set LIBUV_FOUND to TRUE
  62. # if all listed variables are TRUE
  63. find_package_handle_standard_args(LibUV DEFAULT_MSG
  64. LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
  65. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)