FindLibUV.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. find_package(Threads)
  61. if(Threads_FOUND)
  62. # TODO: Fix the cmake file to properly handle static deps for bundled builds.
  63. # Meanwhile just include the threads library if CMake tells us there's one to
  64. # use.
  65. list(APPEND LIBUV_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  66. endif()
  67. include(FindPackageHandleStandardArgs)
  68. # handle the QUIETLY and REQUIRED arguments and set LIBUV_FOUND to TRUE
  69. # if all listed variables are TRUE
  70. find_package_handle_standard_args(LibUV DEFAULT_MSG
  71. LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
  72. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)