Optimize knowhere CMakeLists.txt (#22000)

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
pull/22033/head
Cai Yudong 2023-02-07 16:12:04 +08:00 committed by GitHub
parent a548ce1cf1
commit fc1d2d18cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 78 deletions

View File

@ -84,6 +84,7 @@ set( CMAKE_INSTALL_RPATH "/usr/lib" "${CMAKE_INSTALL_PREFIX}/lib" "${CMAKE_INSTA
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE ) set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
# **************************** Dependencies **************************** # **************************** Dependencies ****************************
list( APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/conan )
include( ${CMAKE_BINARY_DIR}/conan/conanbuildinfo.cmake ) include( ${CMAKE_BINARY_DIR}/conan/conanbuildinfo.cmake )
set( CONAN_DISABLE_CHECK_COMPILER ON ) set( CONAN_DISABLE_CHECK_COMPILER ON )
conan_basic_setup( KEEP_RPATHS ) conan_basic_setup( KEEP_RPATHS )

View File

@ -22,7 +22,7 @@ class MilvusConan(ConanFile):
"libcurl/7.86.0", "libcurl/7.86.0",
) )
generators = "cmake" generators = ("cmake", "cmake_find_package")
default_options = { default_options = {
"rocksdb:shared": True, "rocksdb:shared": True,
"arrow:parquet": True, "arrow:parquet": True,

View File

@ -11,90 +11,48 @@
# or implied. See the License for the specific language governing permissions and limitations under the License. # or implied. See the License for the specific language governing permissions and limitations under the License.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
set( KNOWHERE_VERSION v1.3.6 ) set( KNOWHERE_SOURCE_VER v1.3.6 )
set( KNOWHERE_SOURCE_MD5 "e711e204a3a6c4918352d464c0b87793") set( KNOWHERE_SOURCE_MD5 "e711e204a3a6c4918352d464c0b87793")
if ( DEFINED ENV{MILVUS_KNOWHERE_URL} ) if ( DEFINED ENV{MILVUS_KNOWHERE_URL} )
set( KNOWHERE_SOURCE_URL "$ENV{MILVUS_KNOWHERE_URL}" ) set( KNOWHERE_SOURCE_URL "$ENV{MILVUS_KNOWHERE_URL}" )
else () else ()
set( KNOWHERE_SOURCE_URL set( KNOWHERE_SOURCE_URL
"https://github.com/milvus-io/knowhere/archive/refs/tags/${KNOWHERE_VERSION}.tar.gz" ) "https://github.com/milvus-io/knowhere/archive/refs/tags/${KNOWHERE_SOURCE_VER}.tar.gz" )
endif () endif ()
macro(build_knowhere) message(STATUS "Building knowhere-${KNOWHERE_SOURCE_VER} from source")
message(STATUS "Building knowhere-${KNOWHERE_VERSION} from source") message(STATUS ${CMAKE_BUILD_TYPE})
set (KNOWHERE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
message(STATUS ${CMAKE_BUILD_TYPE}) if ( BUILD_DISK_ANN STREQUAL "ON" )
set(KNOWHERE_CMAKE_ARGS set(KNOWHERE_WITH_DISKANN ON CACHE BOOL "" FORCE )
${EP_COMMON_CMAKE_ARGS} else ()
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} set(KNOWHERE_WITH_DISKANN OFF CACHE BOOL "" FORCE )
-DCMAKE_INSTALL_PREFIX=${KNOWHERE_INSTALL_PREFIX}
-DCMAKE_PREFIX_PATH=${CONAN_BOOST_ROOT}
)
if ( BUILD_DISK_ANN STREQUAL "ON" )
set(KNOWHERE_CMAKE_ARGS
${KNOWHERE_CMAKE_ARGS}
-DKNOWHERE_WITH_DISKANN=true)
else ()
set(KNOWHERE_CMAKE_ARGS
${KNOWHERE_CMAKE_ARGS}
-DKNOWHERE_WITH_DISKANN=false)
endif ()
externalproject_add(knowhere_ep
# GIT_REPOSITORY "https://github.com/milvus-io/knowhere.git"
# GIT_TAG main
URL ${KNOWHERE_SOURCE_URL}
URL_MD5 ${KNOWHERE_SOURCE_MD5}
CMAKE_ARGS ${KNOWHERE_CMAKE_ARGS}
BUILD_COMMAND ${MAKE} ${MAKE_BUILD_ARGS}
PREFIX ${CMAKE_BINARY_DIR}/3rdparty_download/knowhere-subbuild
BINARY_DIR knowhere-bin
INSTALL_DIR ${KNOWHERE_INSTALL_PREFIX}
)
ExternalProject_Get_Property(knowhere_ep INSTALL_DIR)
message(STATUS ${INSTALL_DIR})
if( NOT IS_DIRECTORY ${INSTALL_DIR}/include )
file( MAKE_DIRECTORY "${INSTALL_DIR}/include" )
endif()
add_library(knowhere SHARED IMPORTED)
if (MSYS)
set_target_properties( knowhere
PROPERTIES
IMPORTED_GLOBAL TRUE
IMPORTED_IMPLIB ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}knowhere${CMAKE_SHARED_LIBRARY_SUFFIX}.a
INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
else ()
set_target_properties( knowhere
PROPERTIES
IMPORTED_GLOBAL TRUE
IMPORTED_LOCATION ${INSTALL_DIR}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}knowhere${CMAKE_SHARED_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
endif ()
add_dependencies(knowhere knowhere_ep)
endmacro()
set(KNOWHERE_SOURCE "AUTO")
if (KNOWHERE_SOURCE STREQUAL "AUTO")
find_package(knowhere)
message(STATUS "knowhere libraries: ${KNOWHERE_LIBRARIES}")
message(STATUS "knowhere found: ${KNOWHERE_FOUND}")
if (KNOWHERE_FOUND)
add_library(knowhere)
else()
build_knowhere()
endif()
elseif (KNOWHERE_SOURCE STREQUAL "BUNDLED")
build_knowhere()
elseif (KNOWHERE_SOURCE STREQUAL "SYSTEM")
find_package(knowhere REQUIRED)
add_library(knowhere)
endif () endif ()
# BUILD_UNIT_TEST OFF will only affect knowhere
set( CMAKE_PREFIX_PATH ${CONAN_BOOST_ROOT} )
set( BUILD_UNIT_TEST OFF )
FetchContent_Declare(
knowhere
# GIT_REPOSITORY "https://github.com/milvus-io/knowhere.git"
# GIT_TAG main
URL ${KNOWHERE_SOURCE_URL}
URL_MD5 ${KNOWHERE_SOURCE_MD5}
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/knowhere-src
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/knowhere-build
DOWNLOAD_DIR ${THIRDPARTY_DOWNLOAD_PATH} )
FetchContent_GetProperties( knowhere )
if ( NOT knowhere_POPULATED )
FetchContent_Populate( knowhere )
# Adding the following target:
# knowhere
add_subdirectory( ${knowhere_SOURCE_DIR}
${knowhere_BINARY_DIR} )
endif()
# get prometheus COMPILE_OPTIONS
get_property( var DIRECTORY "${knowhere_SOURCE_DIR}" PROPERTY COMPILE_OPTIONS )
message( STATUS "knowhere src compile options: ${var}" )