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