1# Locate libev library
2# This module defines
3#  HAVE_LIBEV, if false, do not try to link with libev
4#  LIBEV_LIBRARIES, Library path and libs
5#  LIBEV_INCLUDE_DIR, where to find the libev headers
6
7FIND_PATH(LIBEV_INCLUDE_DIR ev.h
8    PATHS ${LIBEV_ROOT}
9    PATH_SUFFIXES include libev
10    NO_DEFAULT_PATH)
11
12FIND_LIBRARY(LIBEV_LIBRARIES
13    NAMES ev libev
14    PATHS ${LIBEV_ROOT}
15    PATH_SUFFIXES lib libev
16    NO_DEFAULT_PATH)
17
18FIND_PATH(LIBEV_INCLUDE_DIR ev.h
19    HINTS
20        ENV LIBEV_DIR
21    PATH_SUFFIXES include include/libev
22    PATHS
23        ${DEPS_INCLUDE_DIR}
24        ~/Library/Frameworks
25        /Library/Frameworks
26        /opt/local
27        /opt/csw
28        /opt/libev
29        /opt)
30
31FIND_LIBRARY(LIBEV_LIBRARIES
32    NAMES ev libev
33    HINTS
34        ENV LIBEV_DIR
35    PATH_SUFFIXES lib libev
36    PATHS
37        ${DEPS_LIB_DIR}
38        ~/Library/Frameworks
39        /Library/Frameworks
40        /opt/local
41        /opt/csw
42        /opt/libev
43        /opt)
44
45IF (LIBEV_LIBRARIES AND LIBEV_INCLUDE_DIR)
46    SET(HAVE_LIBEV true)
47    MESSAGE(STATUS "Found libev in ${LIBEV_INCLUDE_DIR} : ${LIBEV_LIBRARIES}")
48ELSE (LIBEV_LIBRARIES)
49    SET(HAVE_LIBEV false)
50ENDIF (LIBEV_LIBRARIES AND LIBEV_INCLUDE_DIR)
51
52INCLUDE(CMakePushCheckState)
53INCLUDE(CheckFunctionExists)
54IF(HAVE_LIBEV)
55    CMAKE_PUSH_CHECK_STATE()
56    SET(CMAKE_REQUIRED_FLAGS "-I${LIBEV_INCLUDE_DIR}")
57    SET(CMAKE_REQUIRED_LIBRARIES ${LIBEV_LIBRARIES})
58    SET(CMAKE_REQUIRED_INCLUDES "ev.h")
59    CHECK_FUNCTION_EXISTS(ev_loop HAVE_LIBEV3)
60    IF(NOT HAVE_LIBEV3)
61        CHECK_FUNCTION_EXISTS(ev_run HAVE_LIBEV4)
62    ENDIF()
63    CMAKE_POP_CHECK_STATE()
64    IF(HAVE_LIBEV3)
65        MESSAGE(STATUS "libev3 found")
66    ELSEIF(HAVE_LIBEV4)
67        MESSAGE(STATUS "libev4 found")
68    ELSE()
69        MESSAGE(STATUS "libev not found")
70    ENDIF()
71ENDIF()
72
73MARK_AS_ADVANCED(HAVE_LIBEV LIBEV_INCLUDE_DIR LIBEV_LIBRARIES)
74