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