diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index af2151c5a5..7fd7271ca5 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -12,6 +12,8 @@ Please mark all change in change log and use the ticket from JIRA. - MS-5 - Implement Auto Archive Feature - MS-16 - Implement metrics without prometheus +- MS-26 - cmake. Add thirdparty packages + ### Task - MS-1 - Add CHANGELOG.md diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 95463e9fad..7a36bdfd10 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -57,22 +57,22 @@ else() endif() if(CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC -DELPP_THREAD_SAFE -fopenmp") if (GPU_VERSION STREQUAL "ON") set(ENABLE_LICENSE "ON") add_definitions("-DENABLE_LICENSE") endif () else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fPIC -DELPP_THREAD_SAFE -fopenmp") endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -#if (BUILD_UNIT_TEST) -# option(MEGASEARCH_BUILD_TESTS "Build the megasearch test suite" ON) -#endif(BUILD_UNIT_TEST) +if (BUILD_UNIT_TEST) + option(MEGASEARCH_BUILD_TESTS "Build the megasearch test suite" ON) +endif(BUILD_UNIT_TEST) include(ExternalProject) include(DefineOptions) diff --git a/cpp/build.sh b/cpp/build.sh index fde83360ba..abab7bdffa 100755 --- a/cpp/build.sh +++ b/cpp/build.sh @@ -72,7 +72,7 @@ if [[ ${MAKE_CLEAN} = "ON" ]]; then make clean fi -make -j || exit 1 +make -j 1 || exit 1 if [[ ${BUILD_TYPE} != "Debug" ]]; then strip src/vecwise_server diff --git a/cpp/cmake/DefineOptions.cmake b/cpp/cmake/DefineOptions.cmake index bd4279cf63..3171402cf1 100644 --- a/cpp/cmake/DefineOptions.cmake +++ b/cpp/cmake/DefineOptions.cmake @@ -114,11 +114,9 @@ endif() #---------------------------------------------------------------------- -set_option_category("Test and benchmark") - -if (BUILD_UNIT_TEST) - define_option(MEGASEARCH_BUILD_TESTS "Build the MEGASEARCH googletest unit tests" ON) -endif(BUILD_UNIT_TEST) +#set_option_category("Test and benchmark") +# +#define_option(MEGASEARCH_BUILD_TESTS "Build the MEGASEARCH googletest unit tests" ON) #---------------------------------------------------------------------- macro(config_summary) diff --git a/cpp/cmake/ThirdPartyPackages.cmake b/cpp/cmake/ThirdPartyPackages.cmake index 3dcaf0d7e5..121799d9eb 100644 --- a/cpp/cmake/ThirdPartyPackages.cmake +++ b/cpp/cmake/ThirdPartyPackages.cmake @@ -544,6 +544,7 @@ if(MEGASEARCH_WITH_EASYLOGGINGPP) resolve_dependency(Easylogging++) get_target_property(EASYLOGGINGPP_INCLUDE_DIR easyloggingpp INTERFACE_INCLUDE_DIRECTORIES) + link_directories(SYSTEM "${EASYLOGGINGPP_PREFIX}/lib") include_directories(SYSTEM "${EASYLOGGINGPP_INCLUDE_DIR}") endif() @@ -652,7 +653,7 @@ macro(build_faiss) "--prefix=${FAISS_PREFIX}" "CFLAGS=${EP_C_FLAGS}" "CXXFLAGS=${EP_CXX_FLAGS}" - "LDFLAGS=-L${OPENBLAS_PREFIX}/lib" + "LDFLAGS=-L${OPENBLAS_PREFIX}/lib -L${LAPACK_PREFIX}/lib -lopenblas -llapack" --without-python) # if(OPENBLAS_STATIC_LIB) @@ -716,6 +717,7 @@ if(MEGASEARCH_WITH_FAISS) resolve_dependency(LAPACK) get_target_property(LAPACK_INCLUDE_DIR lapack INTERFACE_INCLUDE_DIRECTORIES) include_directories(SYSTEM "${LAPACK_INCLUDE_DIR}") + link_directories(SYSTEM "${LAPACK_PREFIX}/lib") resolve_dependency(FAISS) get_target_property(FAISS_INCLUDE_DIR faiss INTERFACE_INCLUDE_DIRECTORIES) @@ -750,7 +752,14 @@ macro(build_gtest) ${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=${GTEST_PREFIX}" "-DCMAKE_INSTALL_LIBDIR=lib" - -DCMAKE_CXX_FLAGS=${GTEST_CMAKE_CXX_FLAGS}) + -DCMAKE_CXX_FLAGS=${GTEST_CMAKE_CXX_FLAGS} + -DCMAKE_BUILD_TYPE=Release) + + set(GMOCK_INCLUDE_DIR "${GTEST_PREFIX}/include") + set(GMOCK_STATIC_LIB + "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}" + ) + ExternalProject_Add(googletest_ep URL @@ -758,6 +767,7 @@ macro(build_gtest) BUILD_BYPRODUCTS ${GTEST_STATIC_LIB} ${GTEST_MAIN_STATIC_LIB} + ${GMOCK_STATIC_LIB} CMAKE_ARGS ${GTEST_CMAKE_ARGS} ${EP_LOG_OPTIONS}) @@ -775,11 +785,18 @@ macro(build_gtest) PROPERTIES IMPORTED_LOCATION "${GTEST_MAIN_STATIC_LIB}" INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}") + add_library(gmock STATIC IMPORTED) + set_target_properties(gmock + PROPERTIES IMPORTED_LOCATION "${GMOCK_STATIC_LIB}" + INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}") + add_dependencies(gtest googletest_ep) add_dependencies(gtest_main googletest_ep) + add_dependencies(gmock googletest_ep) endmacro() +message(STATUS "MEGASEARCH_BUILD_TESTS: ${MEGASEARCH_BUILD_TESTS}") if (MEGASEARCH_BUILD_TESTS) #message(STATUS "Resolving gtest dependency") resolve_dependency(GTest) @@ -789,6 +806,7 @@ if (MEGASEARCH_BUILD_TESTS) # TODO: Don't use global includes but rather target_include_directories get_target_property(GTEST_INCLUDE_DIR gtest INTERFACE_INCLUDE_DIRECTORIES) + link_directories(SYSTEM "${GTEST_PREFIX}/lib") include_directories(SYSTEM ${GTEST_INCLUDE_DIR}) endif() @@ -1124,7 +1142,7 @@ if(MEGASEARCH_WITH_SQLITE_ORM) # ExternalProject_Get_Property(sqlite_orm_ep source_dir) # set(SQLITE_ORM_INCLUDE_DIR ${source_dir}/sqlite_orm_ep) include_directories(SYSTEM "${SQLITE_ORM_INCLUDE_DIR}") - message(STATUS "SQLITE_ORM_INCLUDE_DIR: ${SQLITE_ORM_INCLUDE_DIR}") + #message(STATUS "SQLITE_ORM_INCLUDE_DIR: ${SQLITE_ORM_INCLUDE_DIR}") endif() # ---------------------------------------------------------------------- diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index 58d2ae9807..40034d59d3 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -78,6 +78,8 @@ set(third_party_libs easyloggingpp faiss gtest + gtest_main + gmock lapack lz4 openblas @@ -179,7 +181,7 @@ add_executable(vecwise_server ${utils_files} ${service_files} ${metrics_files} -# ${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc + #${EASYLOGGINGPP_INCLUDE_DIR}/easylogging++.cc ) if (ENABLE_LICENSE STREQUAL "ON") diff --git a/cpp/src/server/ServerConfig.h b/cpp/src/server/ServerConfig.h index a630442c98..8bb387bdd9 100644 --- a/cpp/src/server/ServerConfig.h +++ b/cpp/src/server/ServerConfig.h @@ -8,7 +8,7 @@ #include "utils/Error.h" #include "config/ConfigNode.h" -#include +#include "yaml-cpp/yaml.h" namespace zilliz { namespace vecwise { diff --git a/cpp/thirdparty/versions.txt b/cpp/thirdparty/versions.txt index 19462f25c4..772c709016 100644 --- a/cpp/thirdparty/versions.txt +++ b/cpp/thirdparty/versions.txt @@ -27,7 +27,7 @@ BOOST_VERSION=1.70.0 BZIP2_VERSION=1.0.6 EASYLOGGINGPP_VERSION=v9.96.7 FAISS_VERSION=master -GTEST_VERSION=1.8.0 +GTEST_VERSION=1.8.1 LAPACK_VERSION=v3.8.0 LZ4_VERSION=v1.9.1 OPENBLAS_VERSION=v0.3.6 diff --git a/cpp/unittest/CMakeLists.txt b/cpp/unittest/CMakeLists.txt index 652fd4927a..7d37042896 100644 --- a/cpp/unittest/CMakeLists.txt +++ b/cpp/unittest/CMakeLists.txt @@ -5,18 +5,26 @@ #------------------------------------------------------------------------------- link_directories( "${CMAKE_BINARY_DIR}/lib" - "${VECWISE_THIRD_PARTY_BUILD}/lib" + #"${VECWISE_THIRD_PARTY_BUILD}/lib" + "${GTEST_PREFIX}/lib/" ) +message(STATUS "GTEST LIB: ${GTEST_PREFIX}/lib") set(unittest_srcs - ${CMAKE_CURRENT_SOURCE_DIR}/vecwise_test.cpp ${VECWISE_THIRD_PARTY_BUILD}/include/easylogging++.cc) + ${CMAKE_CURRENT_SOURCE_DIR}/vecwise_test.cpp) + #${EASYLOGGINGPP_INCLUDE_DIR}/easylogging++.cc) set(unittest_libs yaml-cpp + gtest + gmock gtest_main gmock_main + easyloggingpp pthread - metrics) + metrics + openblas + gfortran) add_subdirectory(server) add_subdirectory(db) diff --git a/cpp/unittest/db/CMakeLists.txt b/cpp/unittest/db/CMakeLists.txt index 30fa0f4a20..2b3d4609b0 100644 --- a/cpp/unittest/db/CMakeLists.txt +++ b/cpp/unittest/db/CMakeLists.txt @@ -42,4 +42,4 @@ set(db_libs lz4 ) -target_link_libraries(db_test ${unittest_libs} ${db_libs}) +target_link_libraries(db_test ${db_libs} ${unittest_libs}) diff --git a/cpp/unittest/faiss_wrapper/CMakeLists.txt b/cpp/unittest/faiss_wrapper/CMakeLists.txt index eb179e6b6a..1ea5431586 100644 --- a/cpp/unittest/faiss_wrapper/CMakeLists.txt +++ b/cpp/unittest/faiss_wrapper/CMakeLists.txt @@ -45,7 +45,7 @@ set(wrapper_libs zstd lz4 ) -target_link_libraries(wrapper_test ${unittest_libs} ${wrapper_libs}) +target_link_libraries(wrapper_test ${wrapper_libs} ${unittest_libs}) set(topk_test_src topk_test.cpp diff --git a/cpp/unittest/license/CMakeLists.txt b/cpp/unittest/license/CMakeLists.txt index 55509c195c..1182d256fc 100644 --- a/cpp/unittest/license/CMakeLists.txt +++ b/cpp/unittest/license/CMakeLists.txt @@ -16,6 +16,7 @@ link_directories(/usr/local/cuda/lib64) link_directories(/usr/lib/x86_64-linux-gnu) link_directories(/usr/lib/nvidia-415) link_directories(/usr/local/cuda/targets/x86_64-linux/lib/stubs/) +link_directories(/usr/local/cuda/lib64/stubs/) set(require_files ../../src/license/LicenseLibrary.cpp @@ -44,4 +45,4 @@ set(db_libs boost_serialization ) -target_link_libraries(license_test ${unittest_libs} ${db_libs}) +target_link_libraries(license_test ${db_libs} ${unittest_libs}) diff --git a/cpp/unittest/metrics/CMakeLists.txt b/cpp/unittest/metrics/CMakeLists.txt index 25fed96694..954f34d141 100644 --- a/cpp/unittest/metrics/CMakeLists.txt +++ b/cpp/unittest/metrics/CMakeLists.txt @@ -57,7 +57,7 @@ set(count_test_src add_executable(metrics_test ${count_test_src} ${require_files} ) target_link_libraries(metrics_test - ${unittest_libs} + faiss cudart cublas @@ -72,5 +72,5 @@ target_link_libraries(metrics_test # prometheus-cpp-core pthread z - + ${unittest_libs} ) \ No newline at end of file diff --git a/cpp/unittest/server/CMakeLists.txt b/cpp/unittest/server/CMakeLists.txt index 5d081d72c9..f4ffe07fa8 100644 --- a/cpp/unittest/server/CMakeLists.txt +++ b/cpp/unittest/server/CMakeLists.txt @@ -51,7 +51,7 @@ set(require_libs ) target_link_libraries(server_test - ${unittest_libs} ${require_libs} ${cuda_library} + ${unittest_libs} )