summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Mayer <tobim@fastmail.fm>2023-01-15 07:49:19 +0100
committerAzat Khuzhin <azat@libevent.org>2023-05-14 22:43:47 +0200
commit16be768dac438efafbafb6395066f262410459ca (patch)
treec11d17e96adf777d8d6f9a73028fd83c29c06700
parent41a7393f3ecd1e9f58331df4653dac2e6739304e (diff)
downloadlibevent-16be768dac438efafbafb6395066f262410459ca.tar.gz
Make sure exported include dirs are correct
CMake config files don't need any logic to detect the location of installed headers or DSOs, because these locations are already determined at project configuration time. They also don't need to distinguish between build and install trees, because that is already handled by the generated `LibeventTargets-*.cmake` files.
-rw-r--r--cmake/LibeventConfig.cmake.in81
1 files changed, 11 insertions, 70 deletions
diff --git a/cmake/LibeventConfig.cmake.in b/cmake/LibeventConfig.cmake.in
index 582739fa..f9b00363 100644
--- a/cmake/LibeventConfig.cmake.in
+++ b/cmake/LibeventConfig.cmake.in
@@ -32,8 +32,6 @@
# find_package() can handle dependencies automatically. For example, given the 'openssl' component,
# all dependencies (libevent_core, libssl, libcrypto and openssl include directories) will be found.
-set(CONFIG_FOR_INSTALL_TREE @CONFIG_FOR_INSTALL_TREE@)
-
set(LIBEVENT_VERSION @EVENT_PACKAGE_VERSION@)
# IMPORTED targets from LibeventTargets.cmake
@@ -45,20 +43,14 @@ if(NOT DEFINED LIBEVENT_STATIC_LINK)
set(LIBEVENT_STATIC_LINK NOT @EVENT_LIBRARY_SHARED@)
endif()
-set(CMAKE_FIND_LIBRARY_SUFFIXES_SAVE "${CMAKE_FIND_LIBRARY_SUFFIXES}")
if(${LIBEVENT_STATIC_LINK})
set(_LIB_TYPE static)
- set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(_AVAILABLE_LIBS "${LIBEVENT_STATIC_LIBRARIES}")
else()
set(_LIB_TYPE shared)
- set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(_AVAILABLE_LIBS "${LIBEVENT_SHARED_LIBRARIES}")
endif()
-# Get the path of the current file.
-get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
-
macro(message_if_needed _flag _msg)
if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
message(${_flag} "${_msg}")
@@ -109,73 +101,22 @@ macro(set_case_insensitive_found _comp)
endforeach()
endmacro()
-if(CONFIG_FOR_INSTALL_TREE)
- ## Config for install tree ----------------------------------------
- # Find includes
- unset(_event_h CACHE)
- find_path(_event_h
- NAMES event2/event.h
- PATHS "@CMAKE_INSTALL_INCLUDEDIR@"
- NO_DEFAULT_PATH)
- if(_event_h)
- set(LIBEVENT_INCLUDE_DIRS "${_event_h}")
- message_if_needed(STATUS "Found libevent include directory: ${_event_h}")
- else()
- message_if_needed(WARNING "Your libevent library does not contain header files!")
- endif()
+foreach(_comp ${_EVENT_COMPONENTS})
+ list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
+ set_case_insensitive_found(${_comp})
+endforeach()
- # Find libraries
- macro(find_event_lib _comp)
- unset(_event_lib_dbg CACHE)
- unset(_event_lib_rel CACHE)
- find_library(_event_lib_dbg
- NAMES "event_${_comp}d"
- PATHS "${_INSTALL_PREFIX}/lib"
- NO_DEFAULT_PATH)
- find_library(_event_lib_rel
- NAMES "event_${_comp}"
- PATHS "@CMAKE_INSTALL_LIBDIR@"
- NO_DEFAULT_PATH)
- if(_event_lib_rel OR _event_lib_dbg)
- list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
- set_case_insensitive_found(${_comp})
- if(_event_lib_dbg)
- message_if_needed(STATUS "Found libevent component: ${_event_lib_dbg}")
- endif()
- if(_event_lib_rel)
- message_if_needed(STATUS "Found libevent component: ${_event_lib_rel}")
- endif()
- else()
- no_component_msg(${_comp})
- endif()
- endmacro()
-
- foreach(comp ${_EVENT_COMPONENTS})
- find_event_lib(${comp})
- endforeach()
-else()
- ## Config for build tree ----------------------------------------
- set(LIBEVENT_INCLUDE_DIRS "@EVENT__INCLUDE_DIRS@")
- foreach(_comp ${_EVENT_COMPONENTS})
- list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
- set_case_insensitive_found(${_comp})
- endforeach()
-endif()
-
-set(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS})
if(LIBEVENT_LIBRARIES)
set(LIBEVENT_LIBRARY ${LIBEVENT_LIBRARIES})
- if(CONFIG_FOR_INSTALL_TREE)
- message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in @CMAKE_INSTALL_LIBDIR@")
- else()
- message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${LIBEVENT_CMAKE_DIR}")
- endif()
- # Avoid including targets more than one times
- if(NOT TARGET event_core_${_LIB_TYPE})
+ # Avoid including targets more than once.
+ if(NOT TARGET libevent::core)
# Include the project Targets file, this contains definitions for IMPORTED targets.
- include(${LIBEVENT_CMAKE_DIR}/LibeventTargets-${_LIB_TYPE}.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/LibeventTargets-${_LIB_TYPE}.cmake)
endif()
+ get_target_property(LIBEVENT_INCLUDE_DIRS libevent::core INTERFACE_INCLUDE_DIRECTORIES)
+ get_filename_component(LIBEVENT_INSTALL_PREFIX "${LIBEVENT_INCLUDE_DIRS}" PATH)
+ message_if_needed(STATUS "Found libevent ${LIBEVENT_VERSION} in ${LIBEVENT_INSTALL_PREFIX}")
else()
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
message(FATAL_ERROR "Can not find any libraries for libevent.")
@@ -183,8 +124,8 @@ else()
message_if_needed(WARNING "Can not find any libraries for libevent.")
endif()
endif()
+set(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS})
-set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES_SAVE}")
unset(_LIB_TYPE)
unset(_AVAILABLE_LIBS)
unset(_EVENT_COMPONENTS)