aboutsummaryrefslogtreecommitdiff
path: root/cmake/FindLibEV.cmake
blob: 29035e387643cabb7e362a7e2287ba0e7e2e0ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

SET(LIBEV_PATH "" CACHE PATH "Base path for include/ev.h and lib/libev*")
SET(LIBEV_INCLUDE_PATH "" CACHE PATH "Include path for ev.h")
SET(LIBEV_LIBDIR "" CACHE PATH "Path containing libev")

IF(LIBEV_PATH)
	SET(LIBEV_INCLUDE_PATH "${LIBEV_PATH}/include" CACHE PATH "Include path for ev.h" FORCE)
	SET(LIBEV_LIBDIR "${LIBEV_PATH}/lib" CACHE PATH "Path containing libev" FORCE)
ENDIF(LIBEV_PATH)

IF(LIBEV_INCLUDE_PATH)
	INCLUDE_DIRECTORIES(${LIBEV_INCLUDE_PATH})
ENDIF(LIBEV_INCLUDE_PATH)

# Use cached result
IF(NOT LIBEV_FOUND)
	UNSET(HAVE_EV_H)
	UNSET(HAVE_LIBEV)
	UNSET(HAVE_EV_H CACHE)
	UNSET(HAVE_LIBEV CACHE)
	UNSET(LIBEV_CFLAGS)
	UNSET(LIBEV_LDFLAGS)

	IF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
		SET(CMAKE_REQUIRED_INCLUDES ${LIBEV_INCLUDE_PATH})
# 		MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
		CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
		IF(HAVE_EV_H)
# 			MESSAGE(STATUS "Looking for lib ev in ${LIBEV_LIBDIR}")
			CHECK_LIBRARY_EXISTS(ev ev_time "${LIBEV_LIBDIR}" HAVE_LIBEV)
			IF(HAVE_LIBEV)
				SET(LIBEV_LIBRARIES ev CACHE INTERNAL "")
				SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
				SET(LIBEV_LDFLAGS "-L${LIBEV_LIBDIR} -lev" CACHE INTERNAL "")
				SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
			ELSE(HAVE_LIBEV)
				MESSAGE(STATUS "Couldn't find lib ev in ${LIBEV_LIBDIR}")
			ENDIF(HAVE_LIBEV)
		ELSE(HAVE_EV_H)
			MESSAGE(STATUS "Couldn't find <ev.h> in ${LIBEV_INCLUDE_PATH}")
		ENDIF(HAVE_EV_H)
	ELSE(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)
		pkg_check_modules(LIBEV libev)
		IF(NOT LIBEV_FOUND)
# 			MESSAGE(STATUS "Looking for ev.h in ${CMAKE_REQUIRED_INCLUDES}")
			CHECK_INCLUDE_FILES(ev.h HAVE_EV_H)
			IF(HAVE_EV_H)
# 				MESSAGE(STATUS "Looking for lib ev")
				CHECK_LIBRARY_EXISTS(ev ev_time "" HAVE_LIBEV)
				IF(HAVE_LIBEV)
					SET(LIBEV_CFLAGS "" CACHE INTERNAL "")
					SET(LIBEV_LDFLAGS "-lev" CACHE INTERNAL "")
					SET(LIBEV_FOUND TRUE CACHE INTERNAL "Found libev" FORCE)
				ELSE(HAVE_LIBEV)
					MESSAGE(STATUS "Couldn't find lib ev")
				ENDIF(HAVE_LIBEV)
			ELSE(HAVE_EV_H)
				MESSAGE(STATUS "Couldn't find <ev.h>")
			ENDIF(HAVE_EV_H)
		ENDIF(NOT LIBEV_FOUND)
	ENDIF(LIBEV_INCLUDE_PATH OR LIBEV_LIBDIR)

ENDIF(NOT LIBEV_FOUND)

IF(NOT LIBEV_FOUND)
	IF(LibEV_FIND_REQUIRED)
		MESSAGE(FATAL_ERROR "Could not find libev")
	ENDIF(LibEV_FIND_REQUIRED)
ENDIF(NOT LIBEV_FOUND)

MARK_AS_ADVANCED(LIBEV_PATH LIBEV_INCLUDE_PATH LIBEV_LIBDIR)