Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Use find_library for locating leveldb and gflags.

kishorencd72351e24d07
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56d1bc41..b8c4e9f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,8 @@ FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(CURL REQUIRED)
FIND_PACKAGE(ICU REQUIRED)
FIND_PACKAGE(Protobuf REQUIRED)
+FIND_PACKAGE(LevelDB REQUIRED)
+FIND_PACKAGE(gflags REQUIRED)
message("OpenSSL library: ${OPENSSL_LIBRARIES}")
@@ -150,7 +152,7 @@ set(ICU_ALL_LIBRARIES ${ICU_I18N_LIBRARIES} ${ICU_LIBRARIES} ${ICU_DATA_LIBRARIE
set(CORE_LIBS h2o-evloop iconv ${CURL_LIBRARIES} for ${ICU_ALL_LIBRARIES} ${G3LOGGER_LIBRARIES}
${ROCKSDB_LIBS} ${OPENSSL_LIBRARIES} pthread dl ${STD_LIB})
-set(CORE_LIBS braft brpc leveldb ${CORE_LIBS} gflags ${PROTOBUF_LIBRARIES} ${SYSTEM_LIBS})
+set(CORE_LIBS braft brpc ${LevelDB_LIBRARIES} ${CORE_LIBS} ${GFLAGS_LIBRARIES} ${PROTOBUF_LIBRARIES} ${SYSTEM_LIBS})
target_link_libraries(typesense-core ${CORE_LIBS})
target_link_libraries(typesense-server ${CORE_LIBS})
diff --git a/cmake/Modules/FindLevelDB.cmake b/cmake/Modules/FindLevelDB.cmake
new file mode 100644
index 00000000..583c9ed0
--- /dev/null
+++ b/cmake/Modules/FindLevelDB.cmake
@@ -0,0 +1,43 @@
+# - Find LevelDB
+#
+# LevelDB_INCLUDES - List of LevelDB includes
+# LevelDB_LIBRARIES - List of libraries when using LevelDB.
+# LevelDB_FOUND - True if LevelDB found.
+
+# Look for the header file.
+find_path(LevelDB_INCLUDE NAMES leveldb/db.h
+ PATHS $ENV{LEVELDB_ROOT}/include /opt/local/include /usr/local/include /usr/include
+ DOC "Path in which the file leveldb/db.h is located." )
+
+# Look for the library.
+find_library(LevelDB_LIBRARY NAMES leveldb
+ PATHS /usr/lib $ENV{LEVELDB_ROOT}/lib
+ DOC "Path to leveldb library." )
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LevelDB DEFAULT_MSG LevelDB_INCLUDE LevelDB_LIBRARY)
+
+if(LEVELDB_FOUND)
+ message(STATUS "Found LevelDB (include: ${LevelDB_INCLUDE}, library: ${LevelDB_LIBRARY})")
+ set(LevelDB_INCLUDES ${LevelDB_INCLUDE})
+ set(LevelDB_LIBRARIES ${LevelDB_LIBRARY})
+ mark_as_advanced(LevelDB_INCLUDE LevelDB_LIBRARY)
+
+ if(EXISTS "${LevelDB_INCLUDE}/leveldb/db.h")
+ file(STRINGS "${LevelDB_INCLUDE}/leveldb/db.h" __version_lines
+ REGEX "static const int k[^V]+Version[ \t]+=[ \t]+[0-9]+;")
+
+ foreach(__line ${__version_lines})
+ if(__line MATCHES "[^k]+kMajorVersion[ \t]+=[ \t]+([0-9]+);")
+ set(LEVELDB_VERSION_MAJOR ${CMAKE_MATCH_1})
+ elseif(__line MATCHES "[^k]+kMinorVersion[ \t]+=[ \t]+([0-9]+);")
+ set(LEVELDB_VERSION_MINOR ${CMAKE_MATCH_1})
+ endif()
+ endforeach()
+
+ if(LEVELDB_VERSION_MAJOR AND LEVELDB_VERSION_MINOR)
+ set(LEVELDB_VERSION "${LEVELDB_VERSION_MAJOR}.${LEVELDB_VERSION_MINOR}")
+ endif()
+
+ endif()
+endif()
\ No newline at end of file