Stop when there is no rocksdb, and find its headers where it is
Without a rocksdb the build did not complain: the shared library was linked
with unresolved rocksdb symbols, which a linker permits, and the first thing
that linked it failed with a page of undefined references, blaming
collocatordb. It stops at the configure step now and says what to do.
The headers of the rocksdb that was found are used, instead of relying on the
compiler to look in the right place, and they are put before the other include
directories. That way -DCMAKE_PREFIX_PATH=<prefix> is enough for a rocksdb that
was built by hand, which is what Rocky Linux and RHEL need, as they do not
necessarily have a package. The README says how.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: I21f5cb5eb17c15c0fe77536027b112591c546e58
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 912a49b..bfdcca0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,13 +46,25 @@
find_library(ROCKSDB NAMES rocksdb)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_collocatordb_lib_suffixes})
endif()
+if (NOT ROCKSDB)
+ message(FATAL_ERROR
+ "No rocksdb found. Install the development package of the "
+ "distribution, e.g. librocksdb-dev or rocksdb-devel. Where there is "
+ "none, build rocksdb and say where it is: "
+ "-DCMAKE_PREFIX_PATH=<prefix it was installed to>. Without this the "
+ "shared library would be built with unresolved rocksdb symbols, "
+ "which only shows up when something links it.")
+endif()
message(STATUS "Using RocksDB library ${ROCKSDB}")
-# The compiler looks into /usr/local/include before /usr/include, so a leftover
-# rocksdb installation there is used for the headers while the library of the
-# distribution is linked. That ends in a wall of undefined references, so say
-# what is wrong while it is still obvious.
+# The headers have to belong to that library. Looked up rather than assumed, so
+# that CMAKE_PREFIX_PATH also works for a rocksdb that was built by hand, and
+# put before the rest, so that a leftover rocksdb below /usr/local cannot
+# shadow it - the compiler looks into /usr/local/include before /usr/include.
find_path(ROCKSDB_INCLUDE_DIR rocksdb/version.h)
+if (ROCKSDB_INCLUDE_DIR)
+ include_directories(BEFORE ${ROCKSDB_INCLUDE_DIR})
+endif()
if (ROCKSDB_INCLUDE_DIR AND ROCKSDB)
file(STRINGS "${ROCKSDB_INCLUDE_DIR}/rocksdb/version.h" _rocksdb_major_line
REGEX "^#define ROCKSDB_MAJOR ")