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

Build libfor automatically as part of the build process.

Kishore Nallana789137d55c3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfcd4746..65a928bb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,12 @@ project(typesense)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -O0")
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/)
+ file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/external)
+endif()
+
include(GoogleTest.cmake)
+include(For.cmake)
if (APPLE)
add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)
@@ -13,12 +18,11 @@ if (APPLE)
endif (APPLE)
# FIXME: Need to use find_package() to locate the correct openssl library
-# FIXME: build libfor as part of the build process
FILE(GLOB HEADER_FILES include/*)
include_directories(include)
-include_directories(${CMAKE_SOURCE_DIR}/external/libfor)
+include_directories(${CMAKE_SOURCE_DIR}/external/${FOR_NAME})
include_directories(${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/include)
link_directories(${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build)
@@ -28,13 +32,17 @@ add_executable(search ${HEADER_FILES} src/art.cpp src/intersection.cpp src/main.
add_executable(typesense-server ${HEADER_FILES} src/art.cpp src/intersection.cpp src/collection.cpp src/server.cpp)
target_link_libraries(typesense_test
- ${CMAKE_SOURCE_DIR}/external/libfor/libfor.a
+ ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}/libfor.a
gtest gtest_main
)
-target_link_libraries(search ${CMAKE_SOURCE_DIR}/external/libfor/libfor.a rocksdb)
+target_link_libraries(search ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}/libfor.a rocksdb)
target_link_libraries(typesense-server
- ${CMAKE_SOURCE_DIR}/external/libfor/libfor.a
+ ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}/libfor.a
curl h2o-evloop pthread rocksdb
/usr/local/opt/openssl/lib/libssl.a
- /usr/local/opt/openssl/lib/libcrypto.a)
\ No newline at end of file
+ /usr/local/opt/openssl/lib/libcrypto.a)
+
+#add_dependencies(typesense_test libfor)
+#add_dependencies(search libfor)
+#add_dependencies(typesense-server libfor)
\ No newline at end of file
diff --git a/For.cmake b/For.cmake
new file mode 100644
index 00000000..ee70a574
--- /dev/null
+++ b/For.cmake
@@ -0,0 +1,16 @@
+# Download and build libfor
+
+set(FOR_VERSION 49611808d08d4e47116aa2a3ddcabeb418f405f7)
+set(FOR_NAME libfor-${FOR_VERSION})
+set(FOR_TAR_PATH ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}.tar.gz)
+
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${FOR_NAME})
+ message(STATUS "Downloading and extracting libfor...")
+ file(DOWNLOAD https://github.com/cruppstahl/libfor/archive/${FOR_VERSION}.tar.gz ${FOR_TAR_PATH})
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${FOR_TAR_PATH} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external/)
+endif()
+
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}/libfor.a)
+ message("Building libfor locally...")
+ execute_process(COMMAND make WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external/${FOR_NAME}/)
+endif()
\ No newline at end of file
diff --git a/GoogleTest.cmake b/GoogleTest.cmake
index ff65bc1a..b2d681fc 100644
--- a/GoogleTest.cmake
+++ b/GoogleTest.cmake
@@ -1,11 +1,13 @@
-# Download and compile gtest
+# Download and build gtest
-if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0)
- set(GTEST_TAR_PATH ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0.tar.gz)
+set(GTEST_VERSION 1.8.0)
+set(GTEST_NAME googletest-release-${GTEST_VERSION})
+set(GTEST_TAR_PATH ${CMAKE_SOURCE_DIR}/external/${GTEST_NAME}.tar.gz)
+
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/${GTEST_NAME})
message(STATUS "Downloading and extracting Google Test...")
file(DOWNLOAD https://github.com/google/googletest/archive/release-1.8.0.tar.gz ${GTEST_TAR_PATH})
- execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${GTEST_TAR_PATH})
- file(RENAME ${CMAKE_SOURCE_DIR}/googletest-release-1.8.0 ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${GTEST_TAR_PATH} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/external/)
endif()
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/external/googletest-release-1.8.0/googletest/build)