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