FindLibuv.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. find_path2(LIBUV_INCLUDE_DIR uv.h)
  2. find_library2(LIBUV_LIBRARY NAMES uv_a uv libuv)
  3. set(LIBUV_LIBRARIES ${LIBUV_LIBRARY})
  4. check_library_exists(dl dlopen "dlfcn.h" HAVE_LIBDL)
  5. if(HAVE_LIBDL)
  6. list(APPEND LIBUV_LIBRARIES dl)
  7. endif()
  8. check_library_exists(kstat kstat_lookup "kstat.h" HAVE_LIBKSTAT)
  9. if(HAVE_LIBKSTAT)
  10. list(APPEND LIBUV_LIBRARIES kstat)
  11. endif()
  12. check_library_exists(kvm kvm_open "kvm.h" HAVE_LIBKVM)
  13. if(HAVE_LIBKVM AND NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
  14. list(APPEND LIBUV_LIBRARIES kvm)
  15. endif()
  16. check_library_exists(nsl gethostbyname "nsl.h" HAVE_LIBNSL)
  17. if(HAVE_LIBNSL)
  18. list(APPEND LIBUV_LIBRARIES nsl)
  19. endif()
  20. check_library_exists(perfstat perfstat_cpu "libperfstat.h" HAVE_LIBPERFSTAT)
  21. if(HAVE_LIBPERFSTAT)
  22. list(APPEND LIBUV_LIBRARIES perfstat)
  23. endif()
  24. check_library_exists(rt clock_gettime "time.h" HAVE_LIBRT)
  25. if(HAVE_LIBRT)
  26. list(APPEND LIBUV_LIBRARIES rt)
  27. endif()
  28. check_library_exists(sendfile sendfile "" HAVE_LIBSENDFILE)
  29. if(HAVE_LIBSENDFILE)
  30. list(APPEND LIBUV_LIBRARIES sendfile)
  31. endif()
  32. if(WIN32)
  33. # check_library_exists() does not work for Win32 API calls in X86 due to name
  34. # mangling calling conventions
  35. list(APPEND LIBUV_LIBRARIES
  36. iphlpapi
  37. psapi
  38. userenv
  39. ws2_32
  40. dbghelp)
  41. endif()
  42. find_package(Threads)
  43. if(Threads_FOUND)
  44. # TODO: Fix the cmake file to properly handle static deps for bundled builds.
  45. # Meanwhile just include the threads library if CMake tells us there's one to
  46. # use.
  47. list(APPEND LIBUV_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  48. endif()
  49. find_package_handle_standard_args(Libuv DEFAULT_MSG
  50. LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
  51. mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
  52. add_library(libuv INTERFACE)
  53. target_include_directories(libuv SYSTEM BEFORE INTERFACE ${LIBUV_INCLUDE_DIR})
  54. target_link_libraries(libuv INTERFACE ${LIBUV_LIBRARIES})