[backport] [cmake] Fix a potential version mismatch in BerkeleyDB
This is a backport an ABC patch to fix #476 (closed) (segmentation fault on app startup when built on an Arch Linux system containing db
and db5.3
packages.
Merge instructions: no squash, leave commit unchanged (do not change backport commit message)
Summary
If several BerkeleyDB versions are installed, it is possible for the cmake find package to pick a header that doesn't match the library version. This diff fixes the issue by searching first for the most specific pattern as the library file name.
Test Plan
On Archlinux with both db5.3 and db6.2 installed:
ninja all check
Differential Revision: https://reviews.bitcoinabc.org/D12946