diff --git a/CMakeLists.txt b/CMakeLists.txt index 31935e0e..e2f3d716 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,27 @@ cmake_minimum_required (VERSION 2.6) -project (hnsw_lib) +project(hnsw_lib + LANGUAGES CXX) -include_directories("${PROJECT_BINARY_DIR}") +add_library(hnswlib INTERFACE) +target_include_directories(hnswlib INTERFACE .) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(CMAKE_CXX_STANDARD 11) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + SET( CMAKE_CXX_FLAGS "-Ofast -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -ftree-vectorize") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -march=native -fpic -w -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=0" ) + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" ) + endif() -set(SOURCE_EXE main.cpp) + add_executable(test_updates examples/updates_test.cpp) + target_link_libraries(test_updates hnswlib) -set(SOURCE_LIB sift_1b.cpp) + add_executable(searchKnnCloserFirst_test examples/searchKnnCloserFirst_test.cpp) + target_link_libraries(searchKnnCloserFirst_test hnswlib) -add_library(sift_test STATIC ${SOURCE_LIB}) - - -add_executable(main ${SOURCE_EXE}) -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - SET( CMAKE_CXX_FLAGS "-Ofast -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -ftree-vectorize") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize -ftree-vectorizer-verbose=0" ) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - SET( CMAKE_CXX_FLAGS "-Ofast -lrt -DNDEBUG -std=c++11 -DHAVE_CXX0X -openmp -march=native -fpic -w -fopenmp -ftree-vectorize" ) + add_executable(main main.cpp sift_1b.cpp) + target_link_libraries(main hnswlib) endif() - -add_executable(test_updates examples/updates_test.cpp) - -add_executable(searchKnnCloserFirst_test examples/searchKnnCloserFirst_test.cpp) - -target_link_libraries(main sift_test) diff --git a/hnswlib/hnswalg.h b/hnswlib/hnswalg.h index f23c17d9..2bd2eb5e 100644 --- a/hnswlib/hnswalg.h +++ b/hnswlib/hnswalg.h @@ -744,7 +744,7 @@ namespace hnswlib { } template - std::vector getDataByLabel(labeltype label) + std::vector getDataByLabel(labeltype label) const { tableint label_c; auto search = label_lookup_.find(label); diff --git a/hnswlib/visited_list_pool.h b/hnswlib/visited_list_pool.h index 6b0f4458..5e1a4a58 100644 --- a/hnswlib/visited_list_pool.h +++ b/hnswlib/visited_list_pool.h @@ -2,6 +2,7 @@ #include #include +#include namespace hnswlib { typedef unsigned short int vl_type;