THRIFT-5668: Install FindLibevent.cmake (#2726)
Client: cpp
ThriftConfig.cmake uses our FindLibevent.cmake but "make install"
doesn't install FindLibevent.cmake. It causes an error with
find_package(Thrift) like the following:
-- Found thrift: /tmp/xxx/tmp/local
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.13")
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.7")
CMake Warning at /usr/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
By not providing "FindLibevent.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Libevent",
but CMake did not find one.
Could not find a package configuration file provided by "Libevent" with any
of the following names:
LibeventConfig.cmake
libevent-config.cmake
Add the installation prefix of "Libevent" to CMAKE_PREFIX_PATH or set
"Libevent_DIR" to a directory containing one of the above files. If
"Libevent" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
/tmp/xxx/tmp/local/lib/cmake/thrift/ThriftConfig.cmake:93 (find_dependency)
diff --git a/build/cmake/GenerateConfigModule.cmake b/build/cmake/GenerateConfigModule.cmake
index 9533c82..26f018a 100644
--- a/build/cmake/GenerateConfigModule.cmake
+++ b/build/cmake/GenerateConfigModule.cmake
@@ -40,5 +40,6 @@
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ThriftConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ThriftConfigVersion.cmake"
+ "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/FindLibevent.cmake"
DESTINATION "${CMAKE_INSTALL_DIR}/thrift")
endif()
diff --git a/build/cmake/ThriftConfig.cmake.in b/build/cmake/ThriftConfig.cmake.in
index c055200..2f2003b 100644
--- a/build/cmake/ThriftConfig.cmake.in
+++ b/build/cmake/ThriftConfig.cmake.in
@@ -59,7 +59,19 @@
endif()
if(@Libevent_FOUND@ AND @WITH_LIBEVENT@)
+ if(DEFINED CMAKE_MODULE_PATH)
+ set(THRIFT_CMAKE_MODULE_PATH_OLD ${CMAKE_MODULE_PATH})
+ else()
+ unset(THRIFT_CMAKE_MODULE_PATH_OLD)
+ endif()
+ set(CMAKE_MODULE_PATH "${THRIFT_CMAKE_DIR}")
find_dependency(Libevent)
+ if(DEFINED THRIFT_CMAKE_MODULE_PATH_OLD)
+ set(CMAKE_MODULE_PATH ${THRIFT_CMAKE_MODULE_PATH_OLD})
+ unset(THRIFT_CMAKE_MODULE_PATH_OLD)
+ else()
+ unset(CMAKE_MODULE_PATH)
+ endif()
endif()
check_required_components(Thrift)