summaryrefslogtreecommitdiff
path: root/cmake/libevent.cmake
blob: 54498e1bb1536e116de5f22b3d57aec167a421cb (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (C) 2011 Oracle and/or its affiliates. All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 

MACRO (MYSQL_USE_BUNDLED_LIBEVENT)
  SET(LIBEVENT_LIBRARY  event)
  SET(LIBEVENT_INCLUDE_DIR  ${CMAKE_SOURCE_DIR}/libevent)
  SET(LIBEVENT_FOUND  TRUE)
  SET(WITH_LIBEVENT "bundled" CACHE STRING "Use bundled libevent")
  ADD_SUBDIRECTORY(libevent)
  GET_TARGET_PROPERTY(src libevent SOURCES)
  FOREACH(file ${src})
    SET(LIBEVENT_SOURCES ${LIBEVENT_SOURCES} ${CMAKE_SOURCE_DIR}/libevent/${file})
  ENDFOREACH()
ENDMACRO()

# MYSQL_CHECK_LIBEVENT
#
# Provides the following configure options:
# WITH_LIBEVENT_BUNDLED
# If this is set,we use bindled libevent
# If this is not set,search for system libevent. 
# if system libevent is not found, use bundled copy
# LIBEVENT_LIBRARIES, LIBEVENT_INCLUDE_DIR and LIBEVENT_SOURCES
# are set after this macro has run

MACRO (MYSQL_CHECK_LIBEVENT)

    IF (NOT WITH_LIBEVENT)
      SET(WITH_LIBEVENT "bundled"  CACHE STRING "By default use bundled libevent on this platform")
    ENDIF()
  
  IF(WITH_LIBEVENT STREQUAL "bundled")
    MYSQL_USE_BUNDLED_LIBEVENT()
  ELSEIF(WITH_LIBEVENT STREQUAL "system" OR WITH_LIBEVENT STREQUAL "yes")
    SET(LIBEVENT_FIND_QUIETLY TRUE)

    IF (NOT LIBEVENT_INCLUDE_PATH)
      set(LIBEVENT_INCLUDE_PATH /usr/local/include /opt/local/include)
    ENDIF()

    find_path(LIBEVENT_INCLUDE_DIR event.h PATHS ${LIBEVENT_INCLUDE_PATH})

    if (NOT LIBEVENT_INCLUDE_DIR)
        MESSAGE(SEND_ERROR "Cannot find appropriate event.h in /usr/local/include or /opt/local/include. Use bundled libevent")
    endif() 

    IF (NOT LIBEVENT_LIB_PATHS) 
      set(LIBEVENT_LIB_PATHS /usr/local/lib /opt/local/lib)
    ENDIF()

    find_library(LIBEVENT_LIB event PATHS ${LIBEVENT_LIB_PATHS})

    if (NOT LIBEVENT_LIB)
        MESSAGE(SEND_ERROR "Cannot find appropriate event lib in /usr/local/lib or /opt/local/lib. Use bundled libevent")
    endif() 

    IF (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR)
      set(LIBEVENT_FOUND TRUE)
      set(LIBEVENT_LIBS ${LIBEVENT_LIB})
    ELSE()
      set(LIBEVENT_FOUND FALSE)
    ENDIF()

    IF(LIBEVENT_FOUND)
      SET(LIBEVENT_SOURCES "")
      SET(LIBEVENT_LIBRARIES ${LIBEVENT_LIBS})
      SET(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR})
      SET(LIBEVENT_DEFINES "-DHAVE_LIBEVENT")
    ELSE()
      IF(WITH_LIBEVENT STREQUAL "system")
        MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for libevent. Use bundled libevent")
      ENDIF()
      MYSQL_USE_BUNDLED_LIBEVENT()
    ENDIF()

  ENDIF()
ENDMACRO()