1# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
23MACRO (MYSQL_USE_BUNDLED_LIBEVENT)
24  SET(WITH_LIBEVENT "bundled" CACHE STRING "Use bundled libevent library")
25  SET(LIBEVENT_LIBRARIES  event)
26  SET(LIBEVENT_INCLUDE_DIRS
27    "${CMAKE_SOURCE_DIR}/extra/libevent/include"
28    "${CMAKE_BINARY_DIR}/extra/libevent/include")
29  SET(LIBEVENT_FOUND  TRUE)
30  ADD_DEFINITIONS("-DHAVE_LIBEVENT2")
31  ADD_SUBDIRECTORY(extra/libevent)
32ENDMACRO()
33
34# MYSQL_CHECK_LIBEVENT
35#
36# Provides the following configure options:
37# WITH_LIBEVENT_BUNDLED
38# If this is set,we use bindled libevent
39# If this is not set,search for system libevent.
40# if system libevent is not found, use bundled copy
41# LIBEVENT_LIBRARIES, LIBEVENT_INCLUDE_DIRS
42# are set after this macro has run
43
44MACRO (MYSQL_CHECK_LIBEVENT)
45
46    IF (NOT WITH_LIBEVENT)
47      SET(WITH_LIBEVENT "bundled"  CACHE STRING "By default use bundled libevent on this platform")
48    ENDIF()
49
50  IF(WITH_LIBEVENT STREQUAL "bundled")
51    MYSQL_USE_BUNDLED_LIBEVENT()
52  ELSEIF(WITH_LIBEVENT STREQUAL "system" OR WITH_LIBEVENT STREQUAL "yes")
53    SET(LIBEVENT_FIND_QUIETLY TRUE)
54
55    IF (NOT LIBEVENT_INCLUDE_PATH)
56      SET(LIBEVENT_INCLUDE_PATH /usr/local/include /opt/local/include)
57    ENDIF()
58
59    FIND_PATH(LIBEVENT_INCLUDE_DIR event.h PATHS ${LIBEVENT_INCLUDE_PATH})
60
61    IF (NOT LIBEVENT_INCLUDE_DIR)
62        MESSAGE(SEND_ERROR "Cannot find appropriate event.h in /usr/local/include or /opt/local/include. Use bundled libevent")
63    ENDIF()
64
65    IF (NOT LIBEVENT_LIB_PATHS)
66      SET(LIBEVENT_LIB_PATHS /usr/local/lib /opt/local/lib)
67    ENDIF()
68
69    ## libevent.so is historical, use libevent_core.so if found.
70    FIND_LIBRARY(LIBEVENT_CORE event_core PATHS ${LIBEVENT_LIB_PATHS})
71    FIND_LIBRARY(LIBEVENT_EXTRA event_extra PATHS ${LIBEVENT_LIB_PATHS})
72    FIND_LIBRARY(LIBEVENT_LIB event PATHS ${LIBEVENT_LIB_PATHS})
73
74    IF (NOT LIBEVENT_LIB AND NOT LIBEVENT_CORE)
75        MESSAGE(SEND_ERROR "Cannot find appropriate event lib in /usr/local/lib or /opt/local/lib. Use bundled libevent")
76    ENDIF()
77
78    IF ((LIBEVENT_LIB OR LIBEVENT_CORE) AND LIBEVENT_INCLUDE_DIR)
79      SET(LIBEVENT_FOUND TRUE)
80      IF (LIBEVENT_CORE)
81        SET(LIBEVENT_LIBS ${LIBEVENT_CORE} ${LIBEVENT_EXTRA})
82      ELSE()
83        SET(LIBEVENT_LIBS ${LIBEVENT_LIB})
84      ENDIF()
85    ELSE()
86      SET(LIBEVENT_FOUND FALSE)
87    ENDIF()
88
89    IF(LIBEVENT_FOUND)
90      SET(LIBEVENT_LIBRARIES ${LIBEVENT_LIBS})
91      SET(LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIR})
92      FIND_PATH(LIBEVENT2_INCLUDE_DIR event2 HINTS ${LIBEVENT_INCLUDE_PATH}/event)
93      IF (LIBEVENT2_INCLUDE_DIR)
94        ADD_DEFINITIONS("-DHAVE_LIBEVENT2")
95      ELSE()
96        ADD_DEFINITIONS("-DHAVE_LIBEVENT1")
97      ENDIF()
98    ELSE()
99      IF(WITH_LIBEVENT STREQUAL "system")
100        MESSAGE(SEND_ERROR "Cannot find appropriate system libraries for libevent. Use bundled libevent")
101      ENDIF()
102      MYSQL_USE_BUNDLED_LIBEVENT()
103    ENDIF()
104
105  ENDIF()
106  MESSAGE(STATUS "LIBEVENT_INCLUDE_DIRS ${LIBEVENT_INCLUDE_DIRS}")
107  MESSAGE(STATUS "LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARIES}")
108ENDMACRO()
109