From f281cecfca0f0482461b36b09d077bb39578593d Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Fri, 8 Sep 2023 14:52:56 +0100 Subject: [PATCH] Add CMake checking for Berkeley DB Rather than hard coding the fact we build in Berkeley DB support, actually check for the existence of the library and only build it if we find it. --- cmake/FindBDB.cmake | 24 ++++++++++++++++++++++++ keydb/CMakeLists.txt | 7 +++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 cmake/FindBDB.cmake diff --git a/cmake/FindBDB.cmake b/cmake/FindBDB.cmake new file mode 100644 index 0000000..aa82c1a --- /dev/null +++ b/cmake/FindBDB.cmake @@ -0,0 +1,24 @@ +# No pkg-config support in Berkeley DB, so try to find it manually + +set(BDB_PREFIX "" CACHE PATH "path ") + +find_path(BDB_INCLUDE_DIR db.h + PATHS ${BDB_PREFIX}/include /usr/include /usr/local/include) + +find_library(BDB_LIBRARY NAMES db + PATHS ${BDB_PREFIX}/lib /usr/lib /usr/local/lib) + +if(BDB_INCLUDE_DIR AND BDB_LIBRARY) + get_filename_component(BDB_LIBRARY_DIR ${BDB_LIBRARY} PATH) + set(BDB_FOUND TRUE) +endif() + +if(BDB_FOUND) + if(NOT BDB_FIND_QUIETLY) + MESSAGE(STATUS "Found Berkeley DB: ${BDB_LIBRARY}") + endif() +elseif(BDB_FOUND) + if(BDB_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Berkeley DB") + endif() +endif() diff --git a/keydb/CMakeLists.txt b/keydb/CMakeLists.txt index 35911f6..3d09dc4 100644 --- a/keydb/CMakeLists.txt +++ b/keydb/CMakeLists.txt @@ -4,8 +4,11 @@ set(BACKENDS "file" "fs" "keyring" "stacked") # DB4 backend (add check for existence) -LIST(APPEND BACKENDS db4) -set(BACKEND_db4_LIBS db-5.3) +find_package(BDB) +if (BDB_FOUND) + LIST(APPEND BACKENDS db4) + set(BACKEND_db4_LIBS db) +endif() # HKP backend - needs libcurl pkg_check_modules(CURL libcurl) -- 2.39.5