xref: /freebsd-src/contrib/libevent/cmake/LibeventConfig.cmake.in (revision b50261e21f39a6c7249a49e7b60aa878c98512a8)
1*b50261e2SCy Schubert# - Config file for the Libevent package
2*b50261e2SCy Schubert# It defines the following variables
3*b50261e2SCy Schubert#  LIBEVENT_FOUND            - true if libevent and all required components found on the system
4*b50261e2SCy Schubert#  LIBEVENT_xxx_FOUND        - true if component xxx(see available components) found on the system
5*b50261e2SCy Schubert#  LIBEVENT_VERSION          - libevent version in format Major.Minor.Patch
6*b50261e2SCy Schubert#  LIBEVENT_INCLUDE_DIRS     - directories where libevent header is located.
7*b50261e2SCy Schubert#  LIBEVENT_INCLUDE_DIR      - same as DIRS
8*b50261e2SCy Schubert#  LIBEVENT_LIBRARIES        - libevent library to link against.
9*b50261e2SCy Schubert#  LIBEVENT_LIBRARY          - same as LIBRARIES
10*b50261e2SCy Schubert#
11*b50261e2SCy Schubert# These variables are deprecated, don't use them.
12*b50261e2SCy Schubert#  LIBEVENT_STATIC_LIBRARIES - libraries to link against (archive/static)
13*b50261e2SCy Schubert#  LIBEVENT_SHARED_LIBRARIES - libraries to link against (shared)
14*b50261e2SCy Schubert#
15*b50261e2SCy Schubert# When you try to locate the libevent libraries, you should specify which components you want to use.
16*b50261e2SCy Schubert# The following table lists all available components. If none is given, all imported targets will used.
17*b50261e2SCy Schubert#  core        - the core functons of libevent
18*b50261e2SCy Schubert#  extra       - extra functions, contains http, dns and rpc
19*b50261e2SCy Schubert#  pthreads    - multiple threads for libevent, not exists on Windows
20*b50261e2SCy Schubert#  openssl     - openssl support for libevent
21*b50261e2SCy Schubert#
22*b50261e2SCy Schubert# By default, the shared libraries of libevent will be found. To find the static ones instead,
23*b50261e2SCy Schubert# you must set the LIBEVENT_STATIC_LINK variable to TRUE before calling find_package(Libevent ...).
24*b50261e2SCy Schubert# If no component provided, all components will be used.
25*b50261e2SCy Schubert# example:
26*b50261e2SCy Schubert#  set(LIBEVENT_STATIC_LINK TRUE)
27*b50261e2SCy Schubert#  find_package(Libevent 2.2 REQUIRED COMPONENTS core)
28*b50261e2SCy Schubert#  include_directories(${LIBEVENT_INCLUDE_DIRS})  # Can be omitted
29*b50261e2SCy Schubert#  target_link_libraries(myapp ${LIBEVENT_LIBRARIES})
30*b50261e2SCy Schubert#    or target_link_libraries(myapp libevent::core)
31*b50261e2SCy Schubert#
32*b50261e2SCy Schubert# find_package() can handle dependencies automatically. For example, given the 'openssl' component,
33*b50261e2SCy Schubert# all dependencies (libevent_core, libssl, libcrypto and openssl include directories) will be found.
34*b50261e2SCy Schubert
35*b50261e2SCy Schubertset(CONFIG_FOR_INSTALL_TREE @CONFIG_FOR_INSTALL_TREE@)
36*b50261e2SCy Schubert
37*b50261e2SCy Schubertset(LIBEVENT_VERSION @EVENT_PACKAGE_VERSION@)
38*b50261e2SCy Schubert
39*b50261e2SCy Schubert# IMPORTED targets from LibeventTargets.cmake
40*b50261e2SCy Schubertset(LIBEVENT_STATIC_LIBRARIES "@LIBEVENT_STATIC_LIBRARIES@")
41*b50261e2SCy Schubertset(LIBEVENT_SHARED_LIBRARIES "@LIBEVENT_SHARED_LIBRARIES@")
42*b50261e2SCy Schubert
43*b50261e2SCy Schubert# Default to the same type as libevent was built:
44*b50261e2SCy Schubertif(NOT DEFINED LIBEVENT_STATIC_LINK)
45*b50261e2SCy Schubert    set(LIBEVENT_STATIC_LINK NOT @EVENT_LIBRARY_SHARED@)
46*b50261e2SCy Schubertendif()
47*b50261e2SCy Schubert
48*b50261e2SCy Schubertset(CMAKE_FIND_LIBRARY_SUFFIXES_SAVE "${CMAKE_FIND_LIBRARY_SUFFIXES}")
49*b50261e2SCy Schubertif(${LIBEVENT_STATIC_LINK})
50*b50261e2SCy Schubert    set(_LIB_TYPE static)
51*b50261e2SCy Schubert    set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
52*b50261e2SCy Schubert    set(_AVAILABLE_LIBS "${LIBEVENT_STATIC_LIBRARIES}")
53*b50261e2SCy Schubertelse()
54*b50261e2SCy Schubert    set(_LIB_TYPE shared)
55*b50261e2SCy Schubert    set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
56*b50261e2SCy Schubert    set(_AVAILABLE_LIBS "${LIBEVENT_SHARED_LIBRARIES}")
57*b50261e2SCy Schubertendif()
58*b50261e2SCy Schubert
59*b50261e2SCy Schubert# Get the path of the current file.
60*b50261e2SCy Schubertget_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
61*b50261e2SCy Schubertget_filename_component(_INSTALL_PREFIX "${LIBEVENT_CMAKE_DIR}/../../.." ABSOLUTE)
62*b50261e2SCy Schubert
63*b50261e2SCy Schubertmacro(message_if_needed _flag _msg)
64*b50261e2SCy Schubert    if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
65*b50261e2SCy Schubert        message(${_flag} "${_msg}")
66*b50261e2SCy Schubert    endif()
67*b50261e2SCy Schubertendmacro()
68*b50261e2SCy Schubert
69*b50261e2SCy Schubertmacro(no_component_msg _comp)
70*b50261e2SCy Schubert    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED_${_comp})
71*b50261e2SCy Schubert        set(pthreadlib)
72*b50261e2SCy Schubert        if(NOT WIN32)
73*b50261e2SCy Schubert            set(pthreadlib ", pthreads")
74*b50261e2SCy Schubert        endif()
75*b50261e2SCy Schubert        message(FATAL_ERROR "Your libevent library does not contain a ${_comp} component!\n"
76*b50261e2SCy Schubert                "The valid components are core, extra${pthreadlib} and openssl.")
77*b50261e2SCy Schubert    else()
78*b50261e2SCy Schubert        message_if_needed(WARNING "Your libevent library does not contain a ${_comp} component!")
79*b50261e2SCy Schubert    endif()
80*b50261e2SCy Schubertendmacro()
81*b50261e2SCy Schubert
82*b50261e2SCy Schubertset(_EVENT_COMPONENTS)
83*b50261e2SCy Schubertif(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
84*b50261e2SCy Schubert    list(REMOVE_DUPLICATES ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
85*b50261e2SCy Schubert    foreach(_comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
86*b50261e2SCy Schubert        list(FIND _AVAILABLE_LIBS ${_comp} _INDEX)
87*b50261e2SCy Schubert        if(_INDEX GREATER -1)
88*b50261e2SCy Schubert            list(APPEND _EVENT_COMPONENTS ${_comp})
89*b50261e2SCy Schubert        else()
90*b50261e2SCy Schubert            no_component_msg(${_comp})
91*b50261e2SCy Schubert        endif()
92*b50261e2SCy Schubert    endforeach()
93*b50261e2SCy Schubertelse()
94*b50261e2SCy Schubert    set(_EVENT_COMPONENTS ${_AVAILABLE_LIBS})
95*b50261e2SCy Schubertendif()
96*b50261e2SCy Schubert
97*b50261e2SCy Schubertset(_POSSIBLE_PKG_NAMES)
98*b50261e2SCy Schubertlist(APPEND _POSSIBLE_PKG_NAMES ${CMAKE_FIND_PACKAGE_NAME} LIBEVENT Libevent libevent)
99*b50261e2SCy Schubertlist(REMOVE_DUPLICATES _POSSIBLE_PKG_NAMES)
100*b50261e2SCy Schubert
101*b50261e2SCy Schubertmacro(set_case_insensitive_found _comp)
102*b50261e2SCy Schubert    foreach(name ${_POSSIBLE_PKG_NAMES})
103*b50261e2SCy Schubert        if("${_comp}" STREQUAL "")
104*b50261e2SCy Schubert            set(${name}_FOUND TRUE)
105*b50261e2SCy Schubert            set(${name}_NOTFOUND FALSE)
106*b50261e2SCy Schubert        else()
107*b50261e2SCy Schubert            set(${name}_${_comp}_FOUND TRUE)
108*b50261e2SCy Schubert            set(${name}_${_comp}_NOTFOUND FALSE)
109*b50261e2SCy Schubert        endif()
110*b50261e2SCy Schubert    endforeach()
111*b50261e2SCy Schubertendmacro()
112*b50261e2SCy Schubert
113*b50261e2SCy Schubertif(CONFIG_FOR_INSTALL_TREE)
114*b50261e2SCy Schubert    ## Config for install tree ----------------------------------------
115*b50261e2SCy Schubert    # Find includes
116*b50261e2SCy Schubert    unset(_event_h CACHE)
117*b50261e2SCy Schubert    find_path(_event_h
118*b50261e2SCy Schubert              NAMES event2/event.h
119*b50261e2SCy Schubert              PATHS "${_INSTALL_PREFIX}/include"
120*b50261e2SCy Schubert              NO_DEFAULT_PATH)
121*b50261e2SCy Schubert    if(_event_h)
122*b50261e2SCy Schubert        set(LIBEVENT_INCLUDE_DIRS "${_event_h}")
123*b50261e2SCy Schubert        message_if_needed(STATUS "Found libevent include directory: ${_event_h}")
124*b50261e2SCy Schubert    else()
125*b50261e2SCy Schubert        message_if_needed(WARNING "Your libevent library does not contain header files!")
126*b50261e2SCy Schubert    endif()
127*b50261e2SCy Schubert
128*b50261e2SCy Schubert    # Find libraries
129*b50261e2SCy Schubert    macro(find_event_lib _comp)
130*b50261e2SCy Schubert        unset(_event_lib CACHE)
131*b50261e2SCy Schubert        find_library(_event_lib
132*b50261e2SCy Schubert                    NAMES "event_${_comp}"
133*b50261e2SCy Schubert                    PATHS "${_INSTALL_PREFIX}/lib"
134*b50261e2SCy Schubert                    NO_DEFAULT_PATH)
135*b50261e2SCy Schubert        if(_event_lib)
136*b50261e2SCy Schubert            list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
137*b50261e2SCy Schubert            set_case_insensitive_found(${_comp})
138*b50261e2SCy Schubert            message_if_needed(STATUS "Found libevent component: ${_event_lib}")
139*b50261e2SCy Schubert        else()
140*b50261e2SCy Schubert            no_component_msg(${_comp})
141*b50261e2SCy Schubert        endif()
142*b50261e2SCy Schubert    endmacro()
143*b50261e2SCy Schubert
144*b50261e2SCy Schubert    foreach(comp ${_EVENT_COMPONENTS})
145*b50261e2SCy Schubert        find_event_lib(${comp})
146*b50261e2SCy Schubert    endforeach()
147*b50261e2SCy Schubertelse()
148*b50261e2SCy Schubert    ## Config for build tree ----------------------------------------
149*b50261e2SCy Schubert    set(LIBEVENT_INCLUDE_DIRS "@EVENT__INCLUDE_DIRS@")
150*b50261e2SCy Schubert    foreach(_comp ${_EVENT_COMPONENTS})
151*b50261e2SCy Schubert        list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
152*b50261e2SCy Schubert        set_case_insensitive_found(${_comp})
153*b50261e2SCy Schubert    endforeach()
154*b50261e2SCy Schubertendif()
155*b50261e2SCy Schubert
156*b50261e2SCy Schubertset(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS})
157*b50261e2SCy Schubertif(LIBEVENT_LIBRARIES)
158*b50261e2SCy Schubert    set(LIBEVENT_LIBRARY ${LIBEVENT_LIBRARIES})
159*b50261e2SCy Schubert    if(CONFIG_FOR_INSTALL_TREE)
160*b50261e2SCy Schubert        message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${_INSTALL_PREFIX}")
161*b50261e2SCy Schubert    else()
162*b50261e2SCy Schubert        message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${LIBEVENT_CMAKE_DIR}")
163*b50261e2SCy Schubert    endif()
164*b50261e2SCy Schubert
165*b50261e2SCy Schubert    # Avoid including targets more than one times
166*b50261e2SCy Schubert    if(NOT TARGET event_core_${_LIB_TYPE})
167*b50261e2SCy Schubert        # Include the project Targets file, this contains definitions for IMPORTED targets.
168*b50261e2SCy Schubert        include(${LIBEVENT_CMAKE_DIR}/LibeventTargets-${_LIB_TYPE}.cmake)
169*b50261e2SCy Schubert    endif()
170*b50261e2SCy Schubertelse()
171*b50261e2SCy Schubert    if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
172*b50261e2SCy Schubert        message(FATAL_ERROR "Can not find any libraries for libevent.")
173*b50261e2SCy Schubert    else()
174*b50261e2SCy Schubert        message_if_needed(WARNING "Can not find any libraries for libevent.")
175*b50261e2SCy Schubert    endif()
176*b50261e2SCy Schubertendif()
177*b50261e2SCy Schubert
178*b50261e2SCy Schubertset(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES_SAVE}")
179*b50261e2SCy Schubertunset(_LIB_TYPE)
180*b50261e2SCy Schubertunset(_AVAILABLE_LIBS)
181*b50261e2SCy Schubertunset(_EVENT_COMPONENTS)
182*b50261e2SCy Schubertunset(_POSSIBLE_PKG_NAMES)
183*b50261e2SCy Schubertunset(_INSTALL_PREFIX)
184