FindLibUV.cmake 2.9 KB

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