@@ -10,6 +10,7 @@ Module defines the following `IMPORTED` target(s):
1010* `BerkeleyDB_FOUND` - Whether the package has been found.
1111* `BerkeleyDB_INCLUDE_DIRS`- Include directories needed to use this package.
1212* `BerkeleyDB_LIBRARIES`- Libraries needed to link to the package library.
13+ * `BerkeleyDB_VERSION` - Package version, if found.
1314
1415## Cache variables
1516
@@ -42,6 +43,7 @@ set(_reason "")
4243find_path (
4344 BerkeleyDB_INCLUDE_DIR
4445 NAMES db.h
46+ PATH_SUFFIXES db
4547 DOC "Directory containing Berkeley DB library headers"
4648)
4749
@@ -63,12 +65,15 @@ if(BerkeleyDB_USE_DB1)
6365 find_path (
6466 BerkeleyDB_DB1_INCLUDE_DIR
6567 NAMES db_185.h
68+ PATH_SUFFIXES db
6669 DOC "Directory containing Berkeley DB db_185.h header for v1 emulation"
6770 )
6871
72+ message (CHECK_START "Checking for Berkeley DB 1.x support/emulation" )
6973 cmake_push_check_state(RESET)
7074 set (CMAKE_REQUIRED_LIBRARIES ${BerkeleyDB_LIBRARY} )
7175 set (CMAKE_REQUIRED_INCLUDES ${BerkeleyDB_DB1_INCLUDE_DIR} )
76+ set (CMAKE_REQUIRED_QUIET TRUE )
7277
7378 check_source_compiles(C [[
7479 #include <db_185.h>
@@ -82,8 +87,9 @@ if(BerkeleyDB_USE_DB1)
8287
8388 if (NOT _berkeleydb_db1_sanity_check)
8489 unset (BerkeleyDB_DB1_INCLUDE_DIR CACHE )
90+ message (CHECK_FAIL "disabled, not found" )
8591 else ()
86- message (WARNING "Berkeley DB 1.x support/emulation not enabled" )
92+ message (CHECK_PASS " enabled" )
8793 endif ()
8894endif ()
8995
@@ -92,6 +98,7 @@ if(BerkeleyDB_LIBRARY)
9298 cmake_push_check_state(RESET)
9399 set (CMAKE_REQUIRED_LIBRARIES ${BerkeleyDB_LIBRARY} )
94100 set (CMAKE_REQUIRED_INCLUDES ${BerkeleyDB_INCLUDE_DIR} )
101+ set (CMAKE_REQUIRED_QUIET TRUE )
95102
96103 check_source_compiles(C [[
97104 #include <db.h>
@@ -109,6 +116,32 @@ if(BerkeleyDB_LIBRARY)
109116 endif ()
110117endif ()
111118
119+ # Get package version.
120+ block(PROPAGATE BerkeleyDB_VERSION)
121+ if (BerkeleyDB_INCLUDE_DIR)
122+ file (
123+ STRINGS
124+ ${BerkeleyDB_INCLUDE_DIR} /db.h
125+ results
126+ REGEX "^[ \t ]*#[ \t ]*define[ \t ]+DB_VERSION_(MAJOR|MINOR|PATCH)[ \t ]+[0-9]+[^\r\n ]*$"
127+ )
128+
129+ unset (BerkeleyDB_VERSION)
130+
131+ foreach (item MAJOR MINOR PATCH)
132+ foreach (line ${results} )
133+ if (line MATCHES "^[ \t ]*#[ \t ]*define[ \t ]+DB_VERSION_${item} [ \t ]+([0-9]+)[^\r\n ]*$" )
134+ if (DEFINED BerkeleyDB_VERSION)
135+ string (APPEND BerkeleyDB_VERSION ".${CMAKE_MATCH_1} " )
136+ else ()
137+ set (BerkeleyDB_VERSION "${CMAKE_MATCH_1} " )
138+ endif ()
139+ endif ()
140+ endforeach ()
141+ endforeach ()
142+ endif ()
143+ endblock()
144+
112145mark_as_advanced (
113146 BerkeleyDB_DB1_INCLUDE_DIR
114147 BerkeleyDB_INCLUDE_DIR
@@ -121,6 +154,7 @@ find_package_handle_standard_args(
121154 BerkeleyDB_LIBRARY
122155 BerkeleyDB_INCLUDE_DIR
123156 _berkeleydb_sanity_check
157+ VERSION_VAR BerkeleyDB_VERSION
124158 REASON_FAILURE_MESSAGE "${_reason} "
125159)
126160
0 commit comments