LibeventConfig.cmake: restore CMAKE_FIND_LIBRARY_SUFFIXES and LIBEVENT_STATIC_LINK default

The current cmake/LibeventConfig.cmake.in has a few problems and I'm not
sure how cleanly developed it is. It seems rater complex for the little
things I would assume it needs to do.

I found two problems that are fixed in this PR:

- If the downstream user does not explicitly set LIBEVENT_STATIC_LINK
  before calling find_package(libevent) then they will not be able to
  detect the static library, even if its the only one that exists. Since
  this may be rather strict, I've changed the behavior so that
  LIBEVENT_STATIC_LINK can be set to ON or OFF, but if unset, it defaults
  to whatever configuration libevent was built as.

- The other problem is a bug. The package configuration needs to unset
  CMAKE_FIND_LIBRARY_SUFFIXES after use, otherwise all packages that are
  detected after libevent will be "infected" by this setting. This was a
  significant problem for us, and is very hard to detect in downstream
  project, because the order of dependencies will lead to different search
  results.

(cherry picked from commit 1675a55620e6f0bbba5776f2df72cd48920421c2)
This commit is contained in:
Mario Emmenlauer 2020-03-03 19:02:24 +01:00 committed by Azat Khuzhin
parent dea51c2e11
commit 640f9cf6ec

View File

@ -40,14 +40,20 @@ set(LIBEVENT_VERSION @EVENT_PACKAGE_VERSION@)
set(LIBEVENT_STATIC_LIBRARIES "@LIBEVENT_STATIC_LIBRARIES@") set(LIBEVENT_STATIC_LIBRARIES "@LIBEVENT_STATIC_LIBRARIES@")
set(LIBEVENT_SHARED_LIBRARIES "@LIBEVENT_SHARED_LIBRARIES@") set(LIBEVENT_SHARED_LIBRARIES "@LIBEVENT_SHARED_LIBRARIES@")
# Default to the same type as libevent was built:
if(NOT DEFINED LIBEVENT_STATIC_LINK)
set(LIBEVENT_STATIC_LINK NOT @BUILD_SHARED_LIBS@)
endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES_SAVE "${CMAKE_FIND_LIBRARY_SUFFIXES}")
if(LIBEVENT_STATIC_LINK) if(LIBEVENT_STATIC_LINK)
set(_LIB_TYPE static) set(_LIB_TYPE static)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(_AVAILABLE_LIBS ${LIBEVENT_STATIC_LIBRARIES}) set(_AVAILABLE_LIBS "${LIBEVENT_STATIC_LIBRARIES}")
else() else()
set(_LIB_TYPE shared) set(_LIB_TYPE shared)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(_AVAILABLE_LIBS ${LIBEVENT_SHARED_LIBRARIES}) set(_AVAILABLE_LIBS "${LIBEVENT_SHARED_LIBRARIES}")
endif() endif()
# Get the path of the current file. # Get the path of the current file.
@ -145,7 +151,6 @@ foreach(_comp ${_EVENT_COMPONENTS})
list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}") list(APPEND LIBEVENT_LIBRARIES "libevent::${_comp}")
set_case_insensitive_found(${_comp}) set_case_insensitive_found(${_comp})
endforeach() endforeach()
endif() endif()
set(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS}) set(LIBEVENT_INCLUDE_DIR ${LIBEVENT_INCLUDE_DIRS})
@ -170,6 +175,7 @@ else()
endif() endif()
endif() endif()
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES_SAVE}")
unset(_LIB_TYPE) unset(_LIB_TYPE)
unset(_AVAILABLE_LIBS) unset(_AVAILABLE_LIBS)
unset(_EVENT_COMPONENTS) unset(_EVENT_COMPONENTS)