Let the installed dereko2vec find libcollocatordb
An installed dereko2vec stopped with
error while loading shared libraries: libcollocatordb.so.1
because collocatordb is installed below /usr/local, which the loader does not
search by default. The installed binary gets the directory of the collocatordb
it was linked against as its rpath now, unless that is a system directory
anyway, or the binary is static and does not need one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: I0b4aa70094c596825851dc48ba3e9a44dabf9439
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9c5d2b..c6377a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,6 +64,18 @@
# converter that writes the memory mappable form derekovecs maps. The remaining
# programs keep the generic names they inherited from word2vec, like distance
# or kmeans_txt, which have no business in a directory on everybody's PATH.
+#
+# The installed dereko2vec gets the directory of the collocatordb it was linked
+# against as its rpath. An installation below /usr/local is not in the search
+# path of the loader by default, and without this it only starts with
+# LD_LIBRARY_PATH set.
+if (NOT STATIC_DEREKO2VEC)
+ get_filename_component(COLLOCATORDB_LIBDIR "${COLLOCATORDB}" DIRECTORY)
+ list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${COLLOCATORDB_LIBDIR}" isSystemLibDir)
+ if ("${isSystemLibDir}" STREQUAL "-1")
+ set_target_properties(dereko2vec PROPERTIES INSTALL_RPATH "${COLLOCATORDB_LIBDIR}")
+ endif ()
+endif ()
install(TARGETS dereko2vec vecs2mmap RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
enable_testing()