From 905cbb44d02c8e8f922099432cc6b6a1beeddd88 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Sun, 16 Jan 2022 09:35:17 -0500 Subject: buildsystem - replace our ancient FindBDB with more modern FindBerkeleyDB Copied from https://github.com/sum01/FindBerkeleyDB This file has an "unlicense" --- .krazy | 2 +- CMakeLists.txt | 12 ++- ReleaseNotes.txt | 1 + cmake/modules/FindBerkeleyDB.cmake | 184 +++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/FindBerkeleyDB.cmake diff --git a/.krazy b/.krazy index 6a4b02b9..73637b29 100644 --- a/.krazy +++ b/.krazy @@ -30,7 +30,7 @@ SKIP /src/libical/caldate\.c SKIP /cmake/Kitware/ SKIP /cmake/modules/GObjectIntrospectionMacros\.cmake|/cmake/modules/FindGObjectIntrospection\.cmake SKIP /doc/Doxyfile\.cmake -SKIP /cmake/Toolchain-iOS.cmake|/cmake/Toolchain-QNX65.cmake|/cmake/Toolchain-QNX66.cmake|/cmake/Toolchain-android.cmake +SKIP /cmake/Toolchain-iOS.cmake|/cmake/Toolchain-QNX65.cmake|/cmake/Toolchain-QNX66.cmake|/cmake/Toolchain-android.cmake|/cmake/modules/FindBerkeleyDB.cmake #Skip zoneinfo SKIP /zoneinfo/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 9553cbf5..8f9df2be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -235,19 +235,23 @@ if(ICU_FOUND) endif() # compile in Berkeley DB support -find_package(BDB) -set_package_properties(BDB PROPERTIES +find_package(BerkeleyDB) +set_package_properties(BerkeleyDB PROPERTIES TYPE OPTIONAL PURPOSE "For Berkeley DB storage support" ) add_feature_info( "Berkeley DB storage support" - BDB_FOUND + BerkeleyDB_FOUND "build in support for Berkeley DB storage" ) -if(BDB_FOUND) +if(BerkeleyDB_FOUND) set(HAVE_BDB True) add_definitions(-DDB_DBM_HSEARCH=0) #set to 1 if hsearch support is needed + #for compatibility to our old FindBDB + set(BDB_FOUND True) + set(BDB_INCLUDE_DIR ${BerkeleyDB_INCLUDE_DIRS}) + set(BDB_LIBRARY ${BerkeleyDB_LIBRARIES}) endif() # MSVC specific definitions diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index c7bd29de..2be88400 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -5,6 +5,7 @@ Version 3.0.13 (UNRELEASED): ---------------------------- * icalcomponent_get_dtend() return icaltime_null_time(), unless called on VEVENT, VAVAILABILITY or VFREEBUSY * icalcomponent_get_duration() for VTODO calculate with DUE instead of DTEND + * Replace CMake FindBDB with FindBerleyDB (https://github.com/sum01/FindBerkeleyDB) Version 3.0.12 (08 December 2021): ---------------------------------- diff --git a/cmake/modules/FindBerkeleyDB.cmake b/cmake/modules/FindBerkeleyDB.cmake new file mode 100644 index 00000000..f2d0a658 --- /dev/null +++ b/cmake/modules/FindBerkeleyDB.cmake @@ -0,0 +1,184 @@ +# Author: sum01 +# Git: https://github.com/sum01/FindBerkeleyDB + +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or distribute +# this software, either in source code form or as a compiled binary, for any +# purpose, commercial or non-commercial, and by any means. +# +# In jurisdictions that recognize copyright laws, the author or authors of this +# software dedicate any and all copyright interest in the software to the public +# domain. We make this dedication for the benefit of the public at large and to +# the detriment of our heirs and successors. We intend this dedication to be an +# overt act of relinquishment in perpetuity of all present and future rights to +# this software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# For more information, please refer to +# + +# NOTE: If Berkeley DB ever gets a Pkg-config ".pc" file, add pkg_check_modules() here + +# Checks if environment paths are empty, set them if they aren't +if(NOT "$ENV{BERKELEYDB_ROOT}" STREQUAL "") + set(_BERKELEYDB_HINTS "$ENV{BERKELEYDB_ROOT}") +elseif(NOT "$ENV{Berkeleydb_ROOT}" STREQUAL "") + set(_BERKELEYDB_HINTS "$ENV{Berkeleydb_ROOT}") +elseif(NOT "$ENV{BERKELEYDBROOT}" STREQUAL "") + set(_BERKELEYDB_HINTS "$ENV{BERKELEYDBROOT}") +else() + # Set just in case, as it's used regardless if it's empty or not + set(_BERKELEYDB_HINTS "") +endif() + +# Allow user to pass a path instead of guessing +if(BerkeleyDB_ROOT_DIR) + set(_BERKELEYDB_PATHS "${BerkeleyDB_ROOT_DIR}") +elseif(CMAKE_SYSTEM_NAME MATCHES ".*[wW]indows.*") + # MATCHES is used to work on any devies with windows in the name + # Shameless copy-paste from FindOpenSSL.cmake v3.8 + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) + list(APPEND _BERKELEYDB_HINTS "${_programfiles}") + + # There's actually production release and version numbers in the file path. + # For example, if they're on v6.2.32: C:/Program Files/Oracle/Berkeley DB 12cR1 6.2.32/ + # But this still works to find it, so I'm guessing it can accept partial path matches. + + foreach(_TARGET_BERKELEYDB_PATH "Oracle/Berkeley DB" "Berkeley DB") + list(APPEND _BERKELEYDB_PATHS + "${_programfiles}/${_TARGET_BERKELEYDB_PATH}" + "C:/Program Files (x86)/${_TARGET_BERKELEYDB_PATH}" + "C:/Program Files/${_TARGET_BERKELEYDB_PATH}" + "C:/${_TARGET_BERKELEYDB_PATH}" + ) + endforeach() +else() + # Paths for anything other than Windows + # Cellar/berkeley-db is for macOS from homebrew installation + list(APPEND _BERKELEYDB_PATHS + "/usr" + "/usr/local" + "/usr/local/Cellar/berkeley-db" + "/opt" + "/opt/local" + ) +endif() + +# Find includes path +find_path(BerkeleyDB_INCLUDE_DIRS + NAMES "db.h" + HINTS ${_BERKELEYDB_HINTS} + PATH_SUFFIXES "include" "includes" + PATHS ${_BERKELEYDB_PATHS} +) + +# Checks if the version file exists, save the version file to a var, and fail if there's no version file +if(BerkeleyDB_INCLUDE_DIRS) + # Read the version file db.h into a variable + file(READ "${BerkeleyDB_INCLUDE_DIRS}/db.h" _BERKELEYDB_DB_HEADER) + # Parse the DB version into variables to be used in the lib names + string(REGEX REPLACE ".*DB_VERSION_MAJOR ([0-9]+).*" "\\1" BerkeleyDB_VERSION_MAJOR "${_BERKELEYDB_DB_HEADER}") + string(REGEX REPLACE ".*DB_VERSION_MINOR ([0-9]+).*" "\\1" BerkeleyDB_VERSION_MINOR "${_BERKELEYDB_DB_HEADER}") + # Patch version example on non-crypto installs: x.x.xNC + string(REGEX REPLACE ".*DB_VERSION_PATCH ([0-9]+(NC)?).*" "\\1" BerkeleyDB_VERSION_PATCH "${_BERKELEYDB_DB_HEADER}") +else() + if(BerkeleyDB_FIND_REQUIRED) + # If the find_package(BerkeleyDB REQUIRED) was used, fail since we couldn't find the header + message(FATAL_ERROR "Failed to find Berkeley DB's header file \"db.h\"! Try setting \"BerkeleyDB_ROOT_DIR\" when initiating Cmake.") + elseif(NOT BerkeleyDB_FIND_QUIETLY) + message(WARNING "Failed to find Berkeley DB's header file \"db.h\"! Try setting \"BerkeleyDB_ROOT_DIR\" when initiating Cmake.") + endif() + # Set some garbage values to the versions since we didn't find a file to read + set(BerkeleyDB_VERSION_MAJOR "0") + set(BerkeleyDB_VERSION_MINOR "0") + set(BerkeleyDB_VERSION_PATCH "0") +endif() + +# The actual returned/output version variable (the others can be used if needed) +set(BerkeleyDB_VERSION "${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}.${BerkeleyDB_VERSION_PATCH}") + +# Finds the target library for berkeley db, since they all follow the same naming conventions +macro(findpackage_berkeleydb_get_lib _BERKELEYDB_OUTPUT_VARNAME _TARGET_BERKELEYDB_LIB) + # Different systems sometimes have a version in the lib name... + # and some have a dash or underscore before the versions. + # CMake recommends to put unversioned names before versioned names + find_library(${_BERKELEYDB_OUTPUT_VARNAME} + NAMES + "${_TARGET_BERKELEYDB_LIB}" + "lib${_TARGET_BERKELEYDB_LIB}" + "lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}.${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}${BerkeleyDB_VERSION_MINOR}" + "lib${_TARGET_BERKELEYDB_LIB}${BerkeleyDB_VERSION_MAJOR}" + "lib${_TARGET_BERKELEYDB_LIB}-${BerkeleyDB_VERSION_MAJOR}" + "lib${_TARGET_BERKELEYDB_LIB}_${BerkeleyDB_VERSION_MAJOR}" + HINTS ${_BERKELEYDB_HINTS} + PATH_SUFFIXES "lib" "lib64" "libs" "libs64" + PATHS ${_BERKELEYDB_PATHS} + ) + # If the library was found, add it to our list of libraries + if(${_BERKELEYDB_OUTPUT_VARNAME}) + # If found, append to our libraries variable + # The ${{}} is because the first expands to target the real variable, the second expands the variable's contents... + # and the real variable's contents is the path to the lib. Thus, it appends the path of the lib to BerkeleyDB_LIBRARIES. + list(APPEND BerkeleyDB_LIBRARIES "${${_BERKELEYDB_OUTPUT_VARNAME}}") + endif() +endmacro() + +# Find and set the paths of the specific library to the variable +findpackage_berkeleydb_get_lib(BerkeleyDB_LIBRARY "db") +# NOTE: Windows doesn't have a db_cxx lib, but instead compiles the cxx code into the "db" lib +findpackage_berkeleydb_get_lib(BerkeleyDB_Cxx_LIBRARY "db_cxx") +# NOTE: I don't think Linux/Unix gets an SQL lib +findpackage_berkeleydb_get_lib(BerkeleyDB_Sql_LIBRARY "db_sql") +findpackage_berkeleydb_get_lib(BerkeleyDB_Stl_LIBRARY "db_stl") + +# Needed for find_package_handle_standard_args() +include(FindPackageHandleStandardArgs) +# Fails if required vars aren't found, or if the version doesn't meet specifications. +find_package_handle_standard_args(BerkeleyDB + FOUND_VAR BerkeleyDB_FOUND + REQUIRED_VARS + BerkeleyDB_INCLUDE_DIRS + BerkeleyDB_LIBRARY + VERSION_VAR BerkeleyDB_VERSION +) + +# Create an imported lib for easy linking by external projects +if(BerkeleyDB_FOUND AND BerkeleyDB_LIBRARIES AND NOT TARGET Oracle::BerkeleyDB) + add_library(Oracle::BerkeleyDB UNKNOWN IMPORTED) + set_target_properties(Oracle::BerkeleyDB PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${BerkeleyDB_INCLUDE_DIRS}" + IMPORTED_LOCATION "${BerkeleyDB_LIBRARY}" + INTERFACE_LINK_LIBRARIES "${BerkeleyDB_LIBRARIES}" + ) +endif() + +# Only show the includes path and libraries in the GUI if they click "advanced". +# Does nothing when using the CLI +mark_as_advanced(FORCE + BerkeleyDB_INCLUDE_DIRS + BerkeleyDB_LIBRARIES + BerkeleyDB_LIBRARY + BerkeleyDB_Cxx_LIBRARY + BerkeleyDB_Sql_LIBRARY + BerkeleyDB_Stl_LIBRARY +) + +include(FindPackageMessage) +# A message that tells the user what includes/libs were found, and obeys the QUIET command. +find_package_message(BerkeleyDB + "Found BerkeleyDB libraries: ${BerkeleyDB_LIBRARIES}" + "[${BerkeleyDB_LIBRARIES}[${BerkeleyDB_INCLUDE_DIRS}]]" +) -- cgit v1.2.1