ThirdPartyPackages.cmake 66.9 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

G
groot 已提交
17
set(MILVUS_THIRDPARTY_DEPENDENCIES
J
jinhai 已提交
18

Z
zhiru 已提交
19 20 21 22
        BOOST
        BZip2
        GTest
        Lz4
Z
zhiru 已提交
23
        MySQLPP
Z
zhiru 已提交
24
        Prometheus
Z
zhiru 已提交
25 26 27 28 29
        Snappy
        SQLite
        SQLite_ORM
        yaml-cpp
        ZLIB
30
        ZSTD
Y
yudong.cai 已提交
31
        libunwind
Z
zhiru 已提交
32 33
        gperftools
        GRPC)
J
jinhai 已提交
34

G
groot 已提交
35
message(STATUS "Using ${MILVUS_DEPENDENCY_SOURCE} approach to find dependencies")
J
jinhai 已提交
36

Z
zhiru 已提交
37
# For each dependency, set dependency source to global default, if unset
G
groot 已提交
38
foreach(DEPENDENCY ${MILVUS_THIRDPARTY_DEPENDENCIES})
Z
zhiru 已提交
39
    if("${${DEPENDENCY}_SOURCE}" STREQUAL "")
G
groot 已提交
40
        set(${DEPENDENCY}_SOURCE ${MILVUS_DEPENDENCY_SOURCE})
Z
zhiru 已提交
41 42 43 44
    endif()
endforeach()

macro(build_dependency DEPENDENCY_NAME)
Z
zhiru 已提交
45
    if("${DEPENDENCY_NAME}" STREQUAL "BZip2")
Z
zhiru 已提交
46
        build_bzip2()
Z
zhiru 已提交
47 48
    elseif ("${DEPENDENCY_NAME}" STREQUAL "GTest")
        build_gtest()
Z
zhiru 已提交
49 50
    elseif("${DEPENDENCY_NAME}" STREQUAL "Lz4")
        build_lz4()
Z
zhiru 已提交
51 52
    elseif ("${DEPENDENCY_NAME}" STREQUAL "MySQLPP")
        build_mysqlpp()
Z
zhiru 已提交
53 54
    elseif ("${DEPENDENCY_NAME}" STREQUAL "Prometheus")
        build_prometheus()
Z
zhiru 已提交
55 56 57 58 59 60 61 62 63 64 65 66
    elseif ("${DEPENDENCY_NAME}" STREQUAL "Snappy")
        build_snappy()
    elseif ("${DEPENDENCY_NAME}" STREQUAL "SQLite")
        build_sqlite()
    elseif ("${DEPENDENCY_NAME}" STREQUAL "SQLite_ORM")
        build_sqlite_orm()
    elseif("${DEPENDENCY_NAME}" STREQUAL "yaml-cpp")
        build_yamlcpp()
    elseif("${DEPENDENCY_NAME}" STREQUAL "ZLIB")
        build_zlib()
    elseif("${DEPENDENCY_NAME}" STREQUAL "ZSTD")
        build_zstd()
Y
yudong.cai 已提交
67 68 69 70
    elseif("${DEPENDENCY_NAME}" STREQUAL "libunwind")
        build_libunwind()
    elseif("${DEPENDENCY_NAME}" STREQUAL "gperftools")
        build_gperftools()
Z
zhiru 已提交
71 72
    elseif("${DEPENDENCY_NAME}" STREQUAL "GRPC")
        build_grpc()
Z
zhiru 已提交
73 74 75 76
    else()
        message(FATAL_ERROR "Unknown thirdparty dependency to build: ${DEPENDENCY_NAME}")
    endif ()
endmacro()
J
jinhai 已提交
77

Q
quicksilver 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
# ----------------------------------------------------------------------
# Identify OS
if (UNIX)
    if (APPLE)
        set (CMAKE_OS_NAME "osx" CACHE STRING "Operating system name" FORCE)
    else (APPLE)
        ## Check for Debian GNU/Linux ________________
        find_file (DEBIAN_FOUND debian_version debconf.conf
            PATHS /etc
        )
        if (DEBIAN_FOUND)
            set (CMAKE_OS_NAME "debian" CACHE STRING "Operating system name" FORCE)
        endif (DEBIAN_FOUND)
        ##  Check for Fedora _________________________
        find_file (FEDORA_FOUND fedora-release
            PATHS /etc
        )
        if (FEDORA_FOUND)
            set (CMAKE_OS_NAME "fedora" CACHE STRING "Operating system name" FORCE)
        endif (FEDORA_FOUND)
        ##  Check for RedHat _________________________
        find_file (REDHAT_FOUND redhat-release inittab.RH
            PATHS /etc
        )
        if (REDHAT_FOUND)
            set (CMAKE_OS_NAME "redhat" CACHE STRING "Operating system name" FORCE)
        endif (REDHAT_FOUND)
        ## Extra check for Ubuntu ____________________
        if (DEBIAN_FOUND)
            ## At its core Ubuntu is a Debian system, with
            ## a slightly altered configuration; hence from
            ## a first superficial inspection a system will
            ## be considered as Debian, which signifies an
            ## extra check is required.
            find_file (UBUNTU_EXTRA legal issue
                PATHS /etc
            )
            if (UBUNTU_EXTRA)
                ## Scan contents of file
                file (STRINGS ${UBUNTU_EXTRA} UBUNTU_FOUND
                    REGEX Ubuntu
                )
                ## Check result of string search
                if (UBUNTU_FOUND)
                    set (CMAKE_OS_NAME "ubuntu" CACHE STRING "Operating system name" FORCE)
                    set (DEBIAN_FOUND FALSE)
                endif (UBUNTU_FOUND)
            endif (UBUNTU_EXTRA)
        endif (DEBIAN_FOUND)
    endif (APPLE)
endif (UNIX)
Q
quicksilver 已提交
129

Q
quicksilver 已提交
130 131 132 133
# ----------------------------------------------------------------------
# thirdparty directory
set(THIRDPARTY_DIR "${MILVUS_SOURCE_DIR}/thirdparty")

Q
quicksilver 已提交
134 135 136
# ----------------------------------------------------------------------
# JFrog
if(NOT DEFINED USE_JFROG_CACHE)
Q
quicksilver 已提交
137
    set(USE_JFROG_CACHE "OFF")
Q
quicksilver 已提交
138
endif()
S
starlord 已提交
139
if(USE_JFROG_CACHE STREQUAL "ON")
Q
quicksilver 已提交
140 141 142 143 144 145
    if(DEFINED ENV{JFROG_ARTFACTORY_URL})
        set(JFROG_ARTFACTORY_URL "$ENV{JFROG_ARTFACTORY_URL}")
    endif()
    if(NOT DEFINED JFROG_ARTFACTORY_URL)
        message(FATAL_ERROR "JFROG_ARTFACTORY_URL is not set")
    endif()
Q
quicksilver 已提交
146
    set(JFROG_ARTFACTORY_CACHE_URL "${JFROG_ARTFACTORY_URL}/generic-local/milvus/thirdparty/cache/${CMAKE_OS_NAME}/${MILVUS_BUILD_ARCH}/${BUILD_TYPE}")
Q
quicksilver 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159
    if(DEFINED ENV{JFROG_USER_NAME})
        set(JFROG_USER_NAME "$ENV{JFROG_USER_NAME}")
    endif()
    if(NOT DEFINED JFROG_USER_NAME)
        message(FATAL_ERROR "JFROG_USER_NAME is not set")
    endif()
    if(DEFINED ENV{JFROG_PASSWORD})
        set(JFROG_PASSWORD "$ENV{JFROG_PASSWORD}")
    endif()
    if(NOT DEFINED JFROG_PASSWORD)
        message(FATAL_ERROR "JFROG_PASSWORD is not set")
    endif()

Q
quicksilver 已提交
160
    set(THIRDPARTY_PACKAGE_CACHE "${THIRDPARTY_DIR}/cache")
Q
quicksilver 已提交
161
endif()
Q
quicksilver 已提交
162

Z
zhiru 已提交
163 164
macro(resolve_dependency DEPENDENCY_NAME)
    if (${DEPENDENCY_NAME}_SOURCE STREQUAL "AUTO")
Z
zhiru 已提交
165
        #disable find_package for now
Z
zhiru 已提交
166 167 168 169 170 171 172
        build_dependency(${DEPENDENCY_NAME})
    elseif (${DEPENDENCY_NAME}_SOURCE STREQUAL "BUNDLED")
        build_dependency(${DEPENDENCY_NAME})
    elseif (${DEPENDENCY_NAME}_SOURCE STREQUAL "SYSTEM")
        find_package(${DEPENDENCY_NAME} REQUIRED)
    endif ()
endmacro()
J
jinhai 已提交
173

Z
zhiru 已提交
174 175
# ----------------------------------------------------------------------
# ExternalProject options
J
jinhai 已提交
176

Z
zhiru 已提交
177 178 179 180 181
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_BUILD_TYPE)

set(EP_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}}")
set(EP_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${UPPERCASE_BUILD_TYPE}}")

Z
zhiru 已提交
182 183 184
# Set -fPIC on all external projects
set(EP_CXX_FLAGS "${EP_CXX_FLAGS} -fPIC")
set(EP_C_FLAGS "${EP_C_FLAGS} -fPIC")
Z
zhiru 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

# CC/CXX environment variables are captured on the first invocation of the
# builder (e.g make or ninja) instead of when CMake is invoked into to build
# directory. This leads to issues if the variables are exported in a subshell
# and the invocation of make/ninja is in distinct subshell without the same
# environment (CC/CXX).
set(EP_COMMON_TOOLCHAIN -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})

if(CMAKE_AR)
    set(EP_COMMON_TOOLCHAIN ${EP_COMMON_TOOLCHAIN} -DCMAKE_AR=${CMAKE_AR})
endif()

if(CMAKE_RANLIB)
    set(EP_COMMON_TOOLCHAIN ${EP_COMMON_TOOLCHAIN} -DCMAKE_RANLIB=${CMAKE_RANLIB})
endif()

# External projects are still able to override the following declarations.
# cmake command line will favor the last defined variable when a duplicate is
# encountered. This requires that `EP_COMMON_CMAKE_ARGS` is always the first
# argument.
set(EP_COMMON_CMAKE_ARGS
        ${EP_COMMON_TOOLCHAIN}
        -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        -DCMAKE_C_FLAGS=${EP_C_FLAGS}
        -DCMAKE_C_FLAGS_${UPPERCASE_BUILD_TYPE}=${EP_C_FLAGS}
        -DCMAKE_CXX_FLAGS=${EP_CXX_FLAGS}
        -DCMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}=${EP_CXX_FLAGS})

G
groot 已提交
214
if(NOT MILVUS_VERBOSE_THIRDPARTY_BUILD)
Z
zhiru 已提交
215 216 217 218 219 220 221
    set(EP_LOG_OPTIONS LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 LOG_DOWNLOAD 1)
else()
    set(EP_LOG_OPTIONS)
endif()

# Ensure that a default make is set
if("${MAKE}" STREQUAL "")
Z
zhiru 已提交
222
    find_program(MAKE make)
Z
zhiru 已提交
223 224
endif()

Z
zhiru 已提交
225 226 227 228
if (NOT DEFINED MAKE_BUILD_ARGS)
    set(MAKE_BUILD_ARGS "-j8")
endif()
message(STATUS "Third Party MAKE_BUILD_ARGS = ${MAKE_BUILD_ARGS}")
Z
zhiru 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261

# ----------------------------------------------------------------------
# Find pthreads

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

# ----------------------------------------------------------------------
# Versions and URLs for toolchain builds, which also can be used to configure
# offline builds

# Read toolchain versions from cpp/thirdparty/versions.txt
file(STRINGS "${THIRDPARTY_DIR}/versions.txt" TOOLCHAIN_VERSIONS_TXT)
foreach(_VERSION_ENTRY ${TOOLCHAIN_VERSIONS_TXT})
    # Exclude comments
    if(NOT _VERSION_ENTRY MATCHES "^[^#][A-Za-z0-9-_]+_VERSION=")
        continue()
    endif()

    string(REGEX MATCH "^[^=]*" _LIB_NAME ${_VERSION_ENTRY})
    string(REPLACE "${_LIB_NAME}=" "" _LIB_VERSION ${_VERSION_ENTRY})

    # Skip blank or malformed lines
    if(${_LIB_VERSION} STREQUAL "")
        continue()
    endif()

    # For debugging
    #message(STATUS "${_LIB_NAME}: ${_LIB_VERSION}")

    set(${_LIB_NAME} "${_LIB_VERSION}")
endforeach()

G
groot 已提交
262 263
if(DEFINED ENV{MILVUS_BOOST_URL})
    set(BOOST_SOURCE_URL "$ENV{MILVUS_BOOST_URL}")
Z
zhiru 已提交
264 265 266
else()
    string(REPLACE "." "_" BOOST_VERSION_UNDERSCORES ${BOOST_VERSION})
    set(BOOST_SOURCE_URL
Z
zhiru 已提交
267
            "https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERSCORES}.tar.gz")
Z
zhiru 已提交
268
endif()
Q
quicksilver 已提交
269
set(BOOST_MD5 "fea771fe8176828fabf9c09242ee8c26")
Z
zhiru 已提交
270

G
groot 已提交
271 272
if(DEFINED ENV{MILVUS_BZIP2_URL})
    set(BZIP2_SOURCE_URL "$ENV{MILVUS_BZIP2_URL}")
Z
zhiru 已提交
273
else()
Y
yudong.cai 已提交
274
    set(BZIP2_SOURCE_URL "https://sourceware.org/pub/bzip2/bzip2-${BZIP2_VERSION}.tar.gz")
Z
zhiru 已提交
275
endif()
Q
quicksilver 已提交
276
set(BZIP2_MD5 "00b516f4704d4a7cb50a1d97e6e8e15b")
Z
zhiru 已提交
277

G
groot 已提交
278 279
if (DEFINED ENV{MILVUS_GTEST_URL})
    set(GTEST_SOURCE_URL "$ENV{MILVUS_GTEST_URL}")
Z
zhiru 已提交
280 281 282 283
else ()
    set(GTEST_SOURCE_URL
            "https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
284
set(GTEST_MD5 "2e6fbeb6a91310a16efe181886c59596")
Z
zhiru 已提交
285

G
groot 已提交
286 287
if(DEFINED ENV{MILVUS_LZ4_URL})
    set(LZ4_SOURCE_URL "$ENV{MILVUS_LZ4_URL}")
Z
zhiru 已提交
288 289 290
else()
    set(LZ4_SOURCE_URL "https://github.com/lz4/lz4/archive/${LZ4_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
291
set(LZ4_MD5 "a80f28f2a2e5fe59ebfe8407f793da22")
Z
zhiru 已提交
292

Z
zhiru 已提交
293 294 295
if(DEFINED ENV{MILVUS_MYSQLPP_URL})
    set(MYSQLPP_SOURCE_URL "$ENV{MILVUS_MYSQLPP_URL}")
else()
296
    set(MYSQLPP_SOURCE_URL "https://tangentsoft.com/mysqlpp/releases/mysql++-${MYSQLPP_VERSION}.tar.gz")
Z
zhiru 已提交
297
endif()
Q
quicksilver 已提交
298
set(MYSQLPP_MD5 "cda38b5ecc0117de91f7c42292dd1e79")
Z
zhiru 已提交
299

G
groot 已提交
300
if (DEFINED ENV{MILVUS_PROMETHEUS_URL})
Z
zhiru 已提交
301 302 303
    set(PROMETHEUS_SOURCE_URL "$ENV{PROMETHEUS_OPENBLAS_URL}")
else ()
    set(PROMETHEUS_SOURCE_URL
Z
zhiru 已提交
304
            https://github.com/jupp0r/prometheus-cpp.git)
Z
zhiru 已提交
305 306
endif()

G
groot 已提交
307 308
if(DEFINED ENV{MILVUS_SNAPPY_URL})
    set(SNAPPY_SOURCE_URL "$ENV{MILVUS_SNAPPY_URL}")
Z
zhiru 已提交
309 310 311 312
else()
    set(SNAPPY_SOURCE_URL
            "https://github.com/google/snappy/archive/${SNAPPY_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
313
set(SNAPPY_MD5 "ee9086291c9ae8deb4dac5e0b85bf54a")
Z
zhiru 已提交
314

G
groot 已提交
315 316
if(DEFINED ENV{MILVUS_SQLITE_URL})
    set(SQLITE_SOURCE_URL "$ENV{MILVUS_SQLITE_URL}")
Z
zhiru 已提交
317 318 319 320
else()
    set(SQLITE_SOURCE_URL
            "https://www.sqlite.org/2019/sqlite-autoconf-${SQLITE_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
321
set(SQLITE_MD5 "3c68eb400f8354605736cd55400e1572")
Z
zhiru 已提交
322

G
groot 已提交
323 324
if(DEFINED ENV{MILVUS_SQLITE_ORM_URL})
    set(SQLITE_ORM_SOURCE_URL "$ENV{MILVUS_SQLITE_ORM_URL}")
Z
zhiru 已提交
325 326 327 328
else()
    set(SQLITE_ORM_SOURCE_URL
            "https://github.com/fnc12/sqlite_orm/archive/${SQLITE_ORM_VERSION}.zip")
endif()
Q
quicksilver 已提交
329
set(SQLITE_ORM_MD5 "ba9a405a8a1421c093aa8ce988ff8598")
Z
zhiru 已提交
330

G
groot 已提交
331 332
if(DEFINED ENV{MILVUS_YAMLCPP_URL})
    set(YAMLCPP_SOURCE_URL "$ENV{MILVUS_YAMLCPP_URL}")
Z
zhiru 已提交
333 334 335
else()
    set(YAMLCPP_SOURCE_URL "https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-${YAMLCPP_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
336
set(YAMLCPP_MD5 "5b943e9af0060d0811148b037449ef82")
Z
zhiru 已提交
337

G
groot 已提交
338 339
if(DEFINED ENV{MILVUS_ZLIB_URL})
    set(ZLIB_SOURCE_URL "$ENV{MILVUS_ZLIB_URL}")
Z
zhiru 已提交
340 341 342
else()
    set(ZLIB_SOURCE_URL "https://github.com/madler/zlib/archive/${ZLIB_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
343
set(ZLIB_MD5 "0095d2d2d1f3442ce1318336637b695f")
Z
zhiru 已提交
344

G
groot 已提交
345 346
if(DEFINED ENV{MILVUS_ZSTD_URL})
    set(ZSTD_SOURCE_URL "$ENV{MILVUS_ZSTD_URL}")
Z
zhiru 已提交
347 348 349
else()
    set(ZSTD_SOURCE_URL "https://github.com/facebook/zstd/archive/${ZSTD_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
350
set(ZSTD_MD5 "340c837db48354f8d5eafe74c6077120")
Z
zhiru 已提交
351

Y
yudong.cai 已提交
352 353 354 355 356 357
if(DEFINED ENV{MILVUS_LIBUNWIND_URL})
    set(LIBUNWIND_SOURCE_URL "$ENV{MILVUS_LIBUNWIND_URL}")
else()
    set(LIBUNWIND_SOURCE_URL
            "https://github.com/libunwind/libunwind/releases/download/v${LIBUNWIND_VERSION}/libunwind-${LIBUNWIND_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
358
set(LIBUNWIND_MD5 "a04f69d66d8e16f8bf3ab72a69112cd6")
Y
yudong.cai 已提交
359 360 361 362 363 364 365

if(DEFINED ENV{MILVUS_GPERFTOOLS_URL})
    set(GPERFTOOLS_SOURCE_URL "$ENV{MILVUS_GPERFTOOLS_URL}")
else()
    set(GPERFTOOLS_SOURCE_URL
            "https://github.com/gperftools/gperftools/releases/download/gperftools-${GPERFTOOLS_VERSION}/gperftools-${GPERFTOOLS_VERSION}.tar.gz")
endif()
Q
quicksilver 已提交
366
set(GPERFTOOLS_MD5 "c6a852a817e9160c79bdb2d3101b4601")
Y
yudong.cai 已提交
367

Z
zhiru 已提交
368 369 370 371 372 373
if(DEFINED ENV{MILVUS_GRPC_URL})
    set(GRPC_SOURCE_URL "$ENV{MILVUS_GRPC_URL}")
else()
    set(GRPC_SOURCE_URL
            "http://git.zilliz.tech/kun.yu/grpc/-/archive/master/grpc-master.tar.gz")
endif()
Q
quicksilver 已提交
374
set(GRPC_MD5 "7ec59ad54c85a12dcbbfede09bf413a9")
Z
zhiru 已提交
375

S
starlord 已提交
376

Z
zhiru 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
# ----------------------------------------------------------------------
# Add Boost dependencies (code adapted from Apache Kudu (incubating))

set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS
        "1.70.0"
        "1.70"
        "1.69.0"
        "1.69"
        "1.68.0"
        "1.68"
        "1.67.0"
        "1.67"
        "1.66.0"
        "1.66"
        "1.65.0"
        "1.65"
        "1.64.0"
        "1.64"
        "1.63.0"
        "1.63"
        "1.62.0"
        "1.61"
        "1.61.0"
        "1.62"
        "1.60.0"
        "1.60")

G
groot 已提交
405
if(MILVUS_BOOST_VENDORED)
Z
zhiru 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    set(BOOST_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/boost_ep-prefix/src/boost_ep")
    set(BOOST_LIB_DIR "${BOOST_PREFIX}/stage/lib")
    set(BOOST_BUILD_LINK "static")
    set(BOOST_STATIC_SYSTEM_LIBRARY
            "${BOOST_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}boost_system${CMAKE_STATIC_LIBRARY_SUFFIX}"
    )
    set(BOOST_STATIC_FILESYSTEM_LIBRARY
            "${BOOST_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}boost_filesystem${CMAKE_STATIC_LIBRARY_SUFFIX}"
    )
    set(BOOST_STATIC_SERIALIZATION_LIBRARY
            "${BOOST_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}boost_serialization${CMAKE_STATIC_LIBRARY_SUFFIX}"
    )
    set(BOOST_SYSTEM_LIBRARY boost_system_static)
    set(BOOST_FILESYSTEM_LIBRARY boost_filesystem_static)
    set(BOOST_SERIALIZATION_LIBRARY boost_serialization_static)

G
groot 已提交
422
    if(MILVUS_BOOST_HEADER_ONLY)
Z
zhiru 已提交
423 424 425
        set(BOOST_BUILD_PRODUCTS)
        set(BOOST_CONFIGURE_COMMAND "")
        set(BOOST_BUILD_COMMAND "")
J
jinhai 已提交
426
    else()
Z
zhiru 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        set(BOOST_BUILD_PRODUCTS ${BOOST_STATIC_SYSTEM_LIBRARY}
                ${BOOST_STATIC_FILESYSTEM_LIBRARY} ${BOOST_STATIC_SERIALIZATION_LIBRARY})
        set(BOOST_CONFIGURE_COMMAND "./bootstrap.sh" "--prefix=${BOOST_PREFIX}"
                "--with-libraries=filesystem,serialization,system")
        if("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
            set(BOOST_BUILD_VARIANT "debug")
        else()
            set(BOOST_BUILD_VARIANT "release")
        endif()
        set(BOOST_BUILD_COMMAND
                "./b2"
                "link=${BOOST_BUILD_LINK}"
                "variant=${BOOST_BUILD_VARIANT}"
                "cxxflags=-fPIC")

        add_thirdparty_lib(boost_system STATIC_LIB "${BOOST_STATIC_SYSTEM_LIBRARY}")

        add_thirdparty_lib(boost_filesystem STATIC_LIB "${BOOST_STATIC_FILESYSTEM_LIBRARY}")

        add_thirdparty_lib(boost_serialization STATIC_LIB "${BOOST_STATIC_SERIALIZATION_LIBRARY}")

G
groot 已提交
448
        set(MILVUS_BOOST_LIBS ${BOOST_SYSTEM_LIBRARY} ${BOOST_FILESYSTEM_LIBRARY} ${BOOST_STATIC_SERIALIZATION_LIBRARY})
J
jinhai 已提交
449
    endif()
Q
quicksilver 已提交
450 451 452 453 454 455 456 457 458 459 460 461 462 463
    externalproject_add(boost_ep
            URL
            ${BOOST_SOURCE_URL}
            BUILD_BYPRODUCTS
            ${BOOST_BUILD_PRODUCTS}
            BUILD_IN_SOURCE
            1
            CONFIGURE_COMMAND
            ${BOOST_CONFIGURE_COMMAND}
            BUILD_COMMAND
            ${BOOST_BUILD_COMMAND}
            INSTALL_COMMAND
            ""
            ${EP_LOG_OPTIONS})
Q
quicksilver 已提交
464 465


Z
zhiru 已提交
466
    set(Boost_INCLUDE_DIR "${BOOST_PREFIX}")
Z
update  
zhiru 已提交
467
    set(Boost_INCLUDE_DIRS "${Boost_INCLUDE_DIR}")
Z
zhiru 已提交
468 469 470
    add_dependencies(boost_system_static boost_ep)
    add_dependencies(boost_filesystem_static boost_ep)
    add_dependencies(boost_serialization_static boost_ep)
J
jinhai 已提交
471

Z
zhiru 已提交
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
endif()

include_directories(SYSTEM ${Boost_INCLUDE_DIR})
link_directories(SYSTEM ${BOOST_LIB_DIR})

# ----------------------------------------------------------------------
# bzip2

macro(build_bzip2)
    message(STATUS "Building BZip2-${BZIP2_VERSION} from source")
    set(BZIP2_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/bzip2_ep-prefix/src/bzip2_ep")
    set(BZIP2_INCLUDE_DIR "${BZIP2_PREFIX}/include")
    set(BZIP2_STATIC_LIB
            "${BZIP2_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}bz2${CMAKE_STATIC_LIBRARY_SUFFIX}")

S
starlord 已提交
487
    if(USE_JFROG_CACHE STREQUAL "ON")
Q
quicksilver 已提交
488 489 490 491
        set(BZIP2_CACHE_PACKAGE_NAME "bzip2_${BZIP2_MD5}.tar.gz")
        set(BZIP2_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${BZIP2_CACHE_PACKAGE_NAME}")
        set(BZIP2_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${BZIP2_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
492 493 494
        execute_process(COMMAND wget -q --method HEAD ${BZIP2_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote cache file ${BZIP2_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
            externalproject_add(bzip2_ep
                                ${EP_LOG_OPTIONS}
                                CONFIGURE_COMMAND
                                ""
                                BUILD_IN_SOURCE
                                1
                                BUILD_COMMAND
                                ${MAKE}
                                ${MAKE_BUILD_ARGS}
                                CFLAGS=${EP_C_FLAGS}
                                INSTALL_COMMAND
                                ${MAKE}
                                install
                                PREFIX=${BZIP2_PREFIX}
                                CFLAGS=${EP_C_FLAGS}
                                INSTALL_DIR
                                ${BZIP2_PREFIX}
                                URL
                                ${BZIP2_SOURCE_URL}
                                BUILD_BYPRODUCTS
                                "${BZIP2_STATIC_LIB}")

            ExternalProject_Create_Cache(bzip2_ep ${BZIP2_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/bzip2_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${BZIP2_CACHE_URL})
        else()
Q
quicksilver 已提交
519 520 521 522 523 524
            file(DOWNLOAD ${BZIP2_CACHE_URL} ${BZIP2_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${BZIP2_CACHE_URL} TO ${BZIP2_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(bzip2_ep ${BZIP2_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
        endif()
    else()
        externalproject_add(bzip2_ep
                                ${EP_LOG_OPTIONS}
                                CONFIGURE_COMMAND
                                ""
                                BUILD_IN_SOURCE
                                1
                                BUILD_COMMAND
                                ${MAKE}
                                ${MAKE_BUILD_ARGS}
                                CFLAGS=${EP_C_FLAGS}
                                INSTALL_COMMAND
                                ${MAKE}
                                install
                                PREFIX=${BZIP2_PREFIX}
                                CFLAGS=${EP_C_FLAGS}
                                INSTALL_DIR
                                ${BZIP2_PREFIX}
                                URL
                                ${BZIP2_SOURCE_URL}
                                BUILD_BYPRODUCTS
Q
quicksilver 已提交
547 548 549 550
                                "${BZIP2_STATIC_LIB}")
    endif()

    file(MAKE_DIRECTORY "${BZIP2_INCLUDE_DIR}")
Z
zhiru 已提交
551 552 553 554 555 556 557 558 559
    add_library(bzip2 STATIC IMPORTED)
    set_target_properties(
            bzip2
            PROPERTIES IMPORTED_LOCATION "${BZIP2_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIR}")

    add_dependencies(bzip2 bzip2_ep)
endmacro()

G
groot 已提交
560
if(MILVUS_WITH_BZ2)
Z
zhiru 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
    resolve_dependency(BZip2)

    if(NOT TARGET bzip2)
        add_library(bzip2 UNKNOWN IMPORTED)
        set_target_properties(bzip2
                PROPERTIES IMPORTED_LOCATION "${BZIP2_LIBRARIES}"
                INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIR}")
    endif()
    link_directories(SYSTEM ${BZIP2_PREFIX}/lib/)
    include_directories(SYSTEM "${BZIP2_INCLUDE_DIR}")
endif()

# ----------------------------------------------------------------------
# Google gtest

macro(build_gtest)
    message(STATUS "Building gtest-${GTEST_VERSION} from source")
    set(GTEST_VENDORED TRUE)
    set(GTEST_CMAKE_CXX_FLAGS "${EP_CXX_FLAGS}")

    if(APPLE)
        set(GTEST_CMAKE_CXX_FLAGS
                ${GTEST_CMAKE_CXX_FLAGS}
                -DGTEST_USE_OWN_TR1_TUPLE=1
                -Wno-unused-value
                -Wno-ignored-attributes)
    endif()

    set(GTEST_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/googletest_ep-prefix/src/googletest_ep")
    set(GTEST_INCLUDE_DIR "${GTEST_PREFIX}/include")
    set(GTEST_STATIC_LIB
            "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GTEST_MAIN_STATIC_LIB
            "${GTEST_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}")

    set(GTEST_CMAKE_ARGS
            ${EP_COMMON_CMAKE_ARGS}
            "-DCMAKE_INSTALL_PREFIX=${GTEST_PREFIX}"
            "-DCMAKE_INSTALL_LIBDIR=lib"
Z
zhiru 已提交
600 601 602 603 604 605 606
            -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}"
    )
Q
quicksilver 已提交
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649

    if(USE_JFROG_CACHE STREQUAL "ON")
        set(GTEST_CACHE_PACKAGE_NAME "googletest_${GTEST_MD5}.tar.gz")
        set(GTEST_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${GTEST_CACHE_PACKAGE_NAME}")
        set(GTEST_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${GTEST_CACHE_PACKAGE_NAME}")

        file(DOWNLOAD ${GTEST_CACHE_URL} ${GTEST_CACHE_PACKAGE_PATH} STATUS status)
        list(GET status 0 status_code)
        message(STATUS "DOWNLOADING FROM ${GTEST_CACHE_URL} TO ${GTEST_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
        if (NOT status_code EQUAL 0)
            ExternalProject_Add(googletest_ep
                    URL
                    ${GTEST_SOURCE_URL}
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    BUILD_BYPRODUCTS
                    ${GTEST_STATIC_LIB}
                    ${GTEST_MAIN_STATIC_LIB}
                    ${GMOCK_STATIC_LIB}
                    CMAKE_ARGS
                    ${GTEST_CMAKE_ARGS}
                    ${EP_LOG_OPTIONS})

            ExternalProject_Create_Cache(googletest_ep ${GTEST_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/googletest_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${GTEST_CACHE_URL})
        else()
            ExternalProject_Use_Cache(googletest_ep ${GTEST_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
        endif()
    else()
        ExternalProject_Add(googletest_ep
                URL
                ${GTEST_SOURCE_URL}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_BYPRODUCTS
                ${GTEST_STATIC_LIB}
                ${GTEST_MAIN_STATIC_LIB}
                ${GMOCK_STATIC_LIB}
                CMAKE_ARGS
                ${GTEST_CMAKE_ARGS}
                ${EP_LOG_OPTIONS})
    endif()
Z
zhiru 已提交
650 651 652

    # The include directory must exist before it is referenced by a target.
    file(MAKE_DIRECTORY "${GTEST_INCLUDE_DIR}")
J
jinhai 已提交
653 654

    add_library(gtest STATIC IMPORTED)
Z
zhiru 已提交
655 656 657
    set_target_properties(gtest
                            PROPERTIES IMPORTED_LOCATION "${GTEST_STATIC_LIB}"
                            INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}")
J
jinhai 已提交
658 659

    add_library(gtest_main STATIC IMPORTED)
Z
zhiru 已提交
660 661 662 663
    set_target_properties(gtest_main
                            PROPERTIES IMPORTED_LOCATION "${GTEST_MAIN_STATIC_LIB}"
                            INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}")

Z
zhiru 已提交
664 665 666 667 668
    add_library(gmock STATIC IMPORTED)
    set_target_properties(gmock
            PROPERTIES IMPORTED_LOCATION "${GMOCK_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIR}")

Z
zhiru 已提交
669 670
    add_dependencies(gtest googletest_ep)
    add_dependencies(gtest_main googletest_ep)
Z
zhiru 已提交
671
    add_dependencies(gmock googletest_ep)
Z
zhiru 已提交
672 673 674

endmacro()

G
groot 已提交
675
if (MILVUS_BUILD_TESTS)
Z
zhiru 已提交
676 677 678 679
    resolve_dependency(GTest)

    if(NOT GTEST_VENDORED)
    endif()
S
starlord 已提交
680

Z
zhiru 已提交
681
    get_target_property(GTEST_INCLUDE_DIR gtest INTERFACE_INCLUDE_DIRECTORIES)
Z
zhiru 已提交
682
    link_directories(SYSTEM "${GTEST_PREFIX}/lib")
Z
zhiru 已提交
683 684 685 686 687 688 689 690 691 692 693
    include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
endif()

# ----------------------------------------------------------------------
# lz4

macro(build_lz4)
    message(STATUS "Building lz4-${LZ4_VERSION} from source")
    set(LZ4_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/lz4_ep-prefix/src/lz4_ep")
    set(LZ4_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/lz4_ep-prefix/")

Z
zhiru 已提交
694 695
    set(LZ4_STATIC_LIB "${LZ4_BUILD_DIR}/lib/liblz4.a")
    set(LZ4_BUILD_COMMAND BUILD_COMMAND ${MAKE} ${MAKE_BUILD_ARGS} CFLAGS=${EP_C_FLAGS})
Z
zhiru 已提交
696 697

    # We need to copy the header in lib to directory outside of the build
Q
quicksilver 已提交
698 699 700 701 702
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(LZ4_CACHE_PACKAGE_NAME "lz4_${LZ4_MD5}.tar.gz")
        set(LZ4_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${LZ4_CACHE_PACKAGE_NAME}")
        set(LZ4_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${LZ4_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
703 704 705
        execute_process(COMMAND wget -q --method HEAD ${LZ4_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${LZ4_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
            externalproject_add(lz4_ep
                    URL
                    ${LZ4_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    UPDATE_COMMAND
                    ${CMAKE_COMMAND}
                    -E
                    copy_directory
                    "${LZ4_BUILD_DIR}/lib"
                    "${LZ4_PREFIX}/include"
                    ${LZ4_PATCH_COMMAND}
                    CONFIGURE_COMMAND
                    ""
                    INSTALL_COMMAND
                    ""
                    BINARY_DIR
                    ${LZ4_BUILD_DIR}
                    BUILD_BYPRODUCTS
                    ${LZ4_STATIC_LIB}
                    ${LZ4_BUILD_COMMAND})

            ExternalProject_Create_Cache(lz4_ep ${LZ4_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/lz4_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${LZ4_CACHE_URL})
        else()
Q
quicksilver 已提交
729 730 731 732 733 734
            file(DOWNLOAD ${LZ4_CACHE_URL} ${LZ4_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${LZ4_CACHE_URL} TO ${LZ4_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(lz4_ep ${LZ4_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
        endif()
    else()
        externalproject_add(lz4_ep
                URL
                ${LZ4_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                UPDATE_COMMAND
                ${CMAKE_COMMAND}
                -E
                copy_directory
                "${LZ4_BUILD_DIR}/lib"
                "${LZ4_PREFIX}/include"
                ${LZ4_PATCH_COMMAND}
                CONFIGURE_COMMAND
                ""
                INSTALL_COMMAND
                ""
                BINARY_DIR
                ${LZ4_BUILD_DIR}
                BUILD_BYPRODUCTS
                ${LZ4_STATIC_LIB}
                ${LZ4_BUILD_COMMAND})
    endif()
Z
zhiru 已提交
758

Q
quicksilver 已提交
759
    file(MAKE_DIRECTORY "${LZ4_PREFIX}/include")
Z
zhiru 已提交
760 761 762 763 764 765 766
    add_library(lz4 STATIC IMPORTED)
    set_target_properties(lz4
            PROPERTIES IMPORTED_LOCATION "${LZ4_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${LZ4_PREFIX}/include")
    add_dependencies(lz4 lz4_ep)
endmacro()

G
groot 已提交
767
if(MILVUS_WITH_LZ4)
Z
zhiru 已提交
768 769 770 771 772 773 774
    resolve_dependency(Lz4)

    get_target_property(LZ4_INCLUDE_DIR lz4 INTERFACE_INCLUDE_DIRECTORIES)
    link_directories(SYSTEM ${LZ4_BUILD_DIR}/lib/)
    include_directories(SYSTEM ${LZ4_INCLUDE_DIR})
endif()

Z
zhiru 已提交
775
# ----------------------------------------------------------------------
Z
zhiru 已提交
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
# MySQL++

macro(build_mysqlpp)
    message(STATUS "Building MySQL++-${MYSQLPP_VERSION} from source")
    set(MYSQLPP_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/mysqlpp_ep-prefix/src/mysqlpp_ep")
    set(MYSQLPP_INCLUDE_DIR "${MYSQLPP_PREFIX}/include")
    set(MYSQLPP_SHARED_LIB
            "${MYSQLPP_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}mysqlpp${CMAKE_SHARED_LIBRARY_SUFFIX}")

    set(MYSQLPP_CONFIGURE_ARGS
            "--prefix=${MYSQLPP_PREFIX}"
            "--enable-thread-check"
            "CFLAGS=${EP_C_FLAGS}"
            "CXXFLAGS=${EP_CXX_FLAGS}"
            "LDFLAGS=-pthread")

Q
quicksilver 已提交
792 793 794 795 796
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(MYSQLPP_CACHE_PACKAGE_NAME "mysqlpp_${MYSQLPP_MD5}.tar.gz")
        set(MYSQLPP_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${MYSQLPP_CACHE_PACKAGE_NAME}")
        set(MYSQLPP_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${MYSQLPP_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
797 798 799
        execute_process(COMMAND wget -q --method HEAD ${MYSQLPP_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${MYSQLPP_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
            externalproject_add(mysqlpp_ep
                    URL
                    ${MYSQLPP_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    CONFIGURE_COMMAND
                    "./configure"
                    ${MYSQLPP_CONFIGURE_ARGS}
                    BUILD_COMMAND
                    ${MAKE} ${MAKE_BUILD_ARGS}
                    BUILD_IN_SOURCE
                    1
                    BUILD_BYPRODUCTS
                    ${MYSQLPP_SHARED_LIB})

            ExternalProject_Create_Cache(mysqlpp_ep ${MYSQLPP_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/mysqlpp_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${MYSQLPP_CACHE_URL})
        else()
Q
quicksilver 已提交
816 817 818 819 820 821
            file(DOWNLOAD ${MYSQLPP_CACHE_URL} ${MYSQLPP_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${MYSQLPP_CACHE_URL} TO ${MYSQLPP_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(mysqlpp_ep ${MYSQLPP_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
        endif()
    else()
        externalproject_add(mysqlpp_ep
                URL
                ${MYSQLPP_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                CONFIGURE_COMMAND
                "./configure"
                ${MYSQLPP_CONFIGURE_ARGS}
                BUILD_COMMAND
                ${MAKE} ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                BUILD_BYPRODUCTS
                ${MYSQLPP_SHARED_LIB})
    endif()
Z
zhiru 已提交
838

Q
quicksilver 已提交
839
    file(MAKE_DIRECTORY "${MYSQLPP_INCLUDE_DIR}")
Z
zhiru 已提交
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
    add_library(mysqlpp SHARED IMPORTED)
    set_target_properties(
            mysqlpp
            PROPERTIES
            IMPORTED_LOCATION "${MYSQLPP_SHARED_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${MYSQLPP_INCLUDE_DIR}")

    add_dependencies(mysqlpp mysqlpp_ep)

endmacro()

if(MILVUS_WITH_MYSQLPP)

    resolve_dependency(MySQLPP)
    get_target_property(MYSQLPP_INCLUDE_DIR mysqlpp INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(SYSTEM "${MYSQLPP_INCLUDE_DIR}")
    link_directories(SYSTEM ${MYSQLPP_PREFIX}/lib)
endif()

# ----------------------------------------------------------------------
Z
zhiru 已提交
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
# Prometheus

macro(build_prometheus)
    message(STATUS "Building Prometheus-${PROMETHEUS_VERSION} from source")
    set(PROMETHEUS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/prometheus_ep-prefix/src/prometheus_ep")
    set(PROMETHEUS_STATIC_LIB_NAME prometheus-cpp)
    set(PROMETHEUS_CORE_STATIC_LIB
            "${PROMETHEUS_PREFIX}/core/${CMAKE_STATIC_LIBRARY_PREFIX}${PROMETHEUS_STATIC_LIB_NAME}-core${CMAKE_STATIC_LIBRARY_SUFFIX}"
            )
    set(PROMETHEUS_PUSH_STATIC_LIB
            "${PROMETHEUS_PREFIX}/push/${CMAKE_STATIC_LIBRARY_PREFIX}${PROMETHEUS_STATIC_LIB_NAME}-push${CMAKE_STATIC_LIBRARY_SUFFIX}"
            )
    set(PROMETHEUS_PULL_STATIC_LIB
            "${PROMETHEUS_PREFIX}/pull/${CMAKE_STATIC_LIBRARY_PREFIX}${PROMETHEUS_STATIC_LIB_NAME}-pull${CMAKE_STATIC_LIBRARY_SUFFIX}"
            )

    set(PROMETHEUS_CMAKE_ARGS
            ${EP_COMMON_CMAKE_ARGS}
            -DCMAKE_INSTALL_LIBDIR=lib
            -DBUILD_SHARED_LIBS=OFF
Z
zhiru 已提交
880 881
            "-DCMAKE_INSTALL_PREFIX=${PROMETHEUS_PREFIX}"
            -DCMAKE_BUILD_TYPE=Release)
Z
zhiru 已提交
882

Q
quicksilver 已提交
883 884 885 886 887 888 889 890
    if(USE_JFROG_CACHE STREQUAL "ON")
        execute_process(COMMAND sh -c "git ls-remote --heads --tags ${PROMETHEUS_SOURCE_URL} ${PROMETHEUS_VERSION} | cut -f 1" OUTPUT_VARIABLE PROMETHEUS_LAST_COMMIT_ID)
        if(${PROMETHEUS_LAST_COMMIT_ID} MATCHES "^[^#][a-z0-9]+")
            string(MD5 PROMETHEUS_COMBINE_MD5 "${PROMETHEUS_LAST_COMMIT_ID}")
            set(PROMETHEUS_CACHE_PACKAGE_NAME "prometheus_${PROMETHEUS_COMBINE_MD5}.tar.gz")
            set(PROMETHEUS_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${PROMETHEUS_CACHE_PACKAGE_NAME}")
            set(PROMETHEUS_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${PROMETHEUS_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
891 892 893
            execute_process(COMMAND wget -q --method HEAD ${PROMETHEUS_CACHE_URL} RESULT_VARIABLE return_code)
            message(STATUS "Check the remote file ${PROMETHEUS_CACHE_URL}. return code = ${return_code}")
            if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
                externalproject_add(prometheus_ep
                        GIT_REPOSITORY
                        ${PROMETHEUS_SOURCE_URL}
                        GIT_TAG
                        ${PROMETHEUS_VERSION}
                        GIT_SHALLOW
                        TRUE
                        ${EP_LOG_OPTIONS}
                        CMAKE_ARGS
                        ${PROMETHEUS_CMAKE_ARGS}
                        BUILD_COMMAND
                        ${MAKE}
                        ${MAKE_BUILD_ARGS}
                        BUILD_IN_SOURCE
                        1
                        INSTALL_COMMAND
                        ${MAKE}
                        "DESTDIR=${PROMETHEUS_PREFIX}"
                        install
                        BUILD_BYPRODUCTS
                        "${PROMETHEUS_CORE_STATIC_LIB}"
                        "${PROMETHEUS_PUSH_STATIC_LIB}"
                        "${PROMETHEUS_PULL_STATIC_LIB}")

                ExternalProject_Create_Cache(prometheus_ep ${PROMETHEUS_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/prometheus_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${PROMETHEUS_CACHE_URL})
            else()
Q
quicksilver 已提交
920 921 922 923 924 925
                file(DOWNLOAD ${PROMETHEUS_CACHE_URL} ${PROMETHEUS_CACHE_PACKAGE_PATH} STATUS status)
                list(GET status 0 status_code)
                message(STATUS "DOWNLOADING FROM ${PROMETHEUS_CACHE_URL} TO ${PROMETHEUS_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
                if (status_code EQUAL 0)
                    ExternalProject_Use_Cache(prometheus_ep ${PROMETHEUS_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
                endif()
Q
quicksilver 已提交
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
            endif()
        else()
            message(FATAL_ERROR "The last commit ID of \"${PROMETHEUS_SOURCE_URL}\" repository don't match!")
        endif()
    else()
        externalproject_add(prometheus_ep
                GIT_REPOSITORY
                ${PROMETHEUS_SOURCE_URL}
                GIT_TAG
                ${PROMETHEUS_VERSION}
                GIT_SHALLOW
                TRUE
                ${EP_LOG_OPTIONS}
                CMAKE_ARGS
                ${PROMETHEUS_CMAKE_ARGS}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                INSTALL_COMMAND
                ${MAKE}
                "DESTDIR=${PROMETHEUS_PREFIX}"
                install
                BUILD_BYPRODUCTS
                "${PROMETHEUS_CORE_STATIC_LIB}"
                "${PROMETHEUS_PUSH_STATIC_LIB}"
                "${PROMETHEUS_PULL_STATIC_LIB}")
    endif()
Z
zhiru 已提交
955

956
    file(MAKE_DIRECTORY "${PROMETHEUS_PREFIX}/push/include")
Z
zhiru 已提交
957 958
    add_library(prometheus-cpp-push STATIC IMPORTED)
    set_target_properties(prometheus-cpp-push
959 960
            PROPERTIES IMPORTED_LOCATION "${PROMETHEUS_PUSH_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${PROMETHEUS_PREFIX}/push/include")
Z
zhiru 已提交
961 962
    add_dependencies(prometheus-cpp-push prometheus_ep)

963
    file(MAKE_DIRECTORY "${PROMETHEUS_PREFIX}/pull/include")
Z
zhiru 已提交
964 965
    add_library(prometheus-cpp-pull STATIC IMPORTED)
    set_target_properties(prometheus-cpp-pull
966 967
            PROPERTIES IMPORTED_LOCATION "${PROMETHEUS_PULL_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${PROMETHEUS_PREFIX}/pull/include")
Z
zhiru 已提交
968 969
    add_dependencies(prometheus-cpp-pull prometheus_ep)

970
    file(MAKE_DIRECTORY "${PROMETHEUS_PREFIX}/core/include")
Z
zhiru 已提交
971 972
    add_library(prometheus-cpp-core STATIC IMPORTED)
    set_target_properties(prometheus-cpp-core
973 974
            PROPERTIES IMPORTED_LOCATION "${PROMETHEUS_CORE_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${PROMETHEUS_PREFIX}/core/include")
Z
zhiru 已提交
975 976 977
    add_dependencies(prometheus-cpp-core prometheus_ep)
endmacro()

G
groot 已提交
978
if(MILVUS_WITH_PROMETHEUS)
Z
zhiru 已提交
979 980 981 982 983 984 985 986 987 988 989

    resolve_dependency(Prometheus)

    link_directories(SYSTEM ${PROMETHEUS_PREFIX}/push/)
    include_directories(SYSTEM ${PROMETHEUS_PREFIX}/push/include)

    link_directories(SYSTEM ${PROMETHEUS_PREFIX}/pull/)
    include_directories(SYSTEM ${PROMETHEUS_PREFIX}/pull/include)

    link_directories(SYSTEM ${PROMETHEUS_PREFIX}/core/)
    include_directories(SYSTEM ${PROMETHEUS_PREFIX}/core/include)
Y
yu yunfeng 已提交
990

Z
zhiru 已提交
991 992
endif()

Z
zhiru 已提交
993 994 995 996 997 998
# ----------------------------------------------------------------------
# Snappy

macro(build_snappy)
    message(STATUS "Building snappy-${SNAPPY_VERSION} from source")
    set(SNAPPY_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/snappy_ep-prefix/src/snappy_ep")
Q
quicksilver 已提交
999
    set(SNAPPY_INCLUDE_DIRS "${SNAPPY_PREFIX}/include")
Z
zhiru 已提交
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
    set(SNAPPY_STATIC_LIB_NAME snappy)
    set(SNAPPY_STATIC_LIB
            "${SNAPPY_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${SNAPPY_STATIC_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}"
    )

    set(SNAPPY_CMAKE_ARGS
            ${EP_COMMON_CMAKE_ARGS}
            -DCMAKE_INSTALL_LIBDIR=lib
            -DSNAPPY_BUILD_TESTS=OFF
            "-DCMAKE_INSTALL_PREFIX=${SNAPPY_PREFIX}")

Q
quicksilver 已提交
1011 1012 1013 1014 1015
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(SNAPPY_CACHE_PACKAGE_NAME "snappy_${SNAPPY_MD5}.tar.gz")
        set(SNAPPY_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${SNAPPY_CACHE_PACKAGE_NAME}")
        set(SNAPPY_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${SNAPPY_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
1016 1017 1018
        execute_process(COMMAND wget -q --method HEAD ${SNAPPY_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${SNAPPY_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
            externalproject_add(snappy_ep
                    ${EP_LOG_OPTIONS}
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    BUILD_IN_SOURCE
                    1
                    INSTALL_DIR
                    ${SNAPPY_PREFIX}
                    URL
                    ${SNAPPY_SOURCE_URL}
                    CMAKE_ARGS
                    ${SNAPPY_CMAKE_ARGS}
                    BUILD_BYPRODUCTS
                    "${SNAPPY_STATIC_LIB}")

            ExternalProject_Create_Cache(snappy_ep ${SNAPPY_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/snappy_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${SNAPPY_CACHE_URL})
        else()
Q
quicksilver 已提交
1037 1038 1039 1040 1041 1042
            file(DOWNLOAD ${SNAPPY_CACHE_URL} ${SNAPPY_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${SNAPPY_CACHE_URL} TO ${SNAPPY_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(snappy_ep ${SNAPPY_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
        endif()
    else()
        externalproject_add(snappy_ep
                ${EP_LOG_OPTIONS}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                INSTALL_DIR
                ${SNAPPY_PREFIX}
                URL
                ${SNAPPY_SOURCE_URL}
                CMAKE_ARGS
                ${SNAPPY_CMAKE_ARGS}
                BUILD_BYPRODUCTS
                "${SNAPPY_STATIC_LIB}")
    endif()
Z
zhiru 已提交
1061

Q
quicksilver 已提交
1062
    file(MAKE_DIRECTORY "${SNAPPY_INCLUDE_DIR}")
Z
zhiru 已提交
1063 1064 1065 1066
    add_library(snappy STATIC IMPORTED)
    set_target_properties(snappy
                        PROPERTIES IMPORTED_LOCATION "${SNAPPY_STATIC_LIB}"
                        INTERFACE_INCLUDE_DIRECTORIES
Q
quicksilver 已提交
1067
                        "${SNAPPY_INCLUDE_DIR}")
Z
zhiru 已提交
1068 1069 1070
    add_dependencies(snappy snappy_ep)
endmacro()

G
groot 已提交
1071
if(MILVUS_WITH_SNAPPY)
Z
zhiru 已提交
1072 1073

    resolve_dependency(Snappy)
S
starlord 已提交
1074

Z
zhiru 已提交
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
    get_target_property(SNAPPY_INCLUDE_DIRS snappy INTERFACE_INCLUDE_DIRECTORIES)
    link_directories(SYSTEM ${SNAPPY_PREFIX}/lib/)
    include_directories(SYSTEM ${SNAPPY_INCLUDE_DIRS})
endif()

# ----------------------------------------------------------------------
# SQLite

macro(build_sqlite)
    message(STATUS "Building SQLITE-${SQLITE_VERSION} from source")
    set(SQLITE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/sqlite_ep-prefix/src/sqlite_ep")
    set(SQLITE_INCLUDE_DIR "${SQLITE_PREFIX}/include")
    set(SQLITE_STATIC_LIB
            "${SQLITE_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}sqlite3${CMAKE_STATIC_LIBRARY_SUFFIX}")

    set(SQLITE_CONFIGURE_ARGS
            "--prefix=${SQLITE_PREFIX}"
            "CC=${CMAKE_C_COMPILER}"
            "CXX=${CMAKE_CXX_COMPILER}"
            "CFLAGS=${EP_C_FLAGS}"
            "CXXFLAGS=${EP_CXX_FLAGS}")

Q
quicksilver 已提交
1097 1098 1099 1100 1101
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(SQLITE_CACHE_PACKAGE_NAME "sqlite_${SQLITE_MD5}.tar.gz")
        set(SQLITE_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${SQLITE_CACHE_PACKAGE_NAME}")
        set(SQLITE_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${SQLITE_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
1102 1103 1104
        execute_process(COMMAND wget -q --method HEAD ${SQLITE_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${SQLITE_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
            externalproject_add(sqlite_ep
                    URL
                    ${SQLITE_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    CONFIGURE_COMMAND
                    "./configure"
                    ${SQLITE_CONFIGURE_ARGS}
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    BUILD_IN_SOURCE
                    1
                    BUILD_BYPRODUCTS
                    "${SQLITE_STATIC_LIB}")

            ExternalProject_Create_Cache(sqlite_ep ${SQLITE_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/sqlite_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${SQLITE_CACHE_URL})
        else()
Q
quicksilver 已提交
1122 1123 1124 1125 1126 1127
            file(DOWNLOAD ${SQLITE_CACHE_URL} ${SQLITE_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${SQLITE_CACHE_URL} TO ${SQLITE_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(sqlite_ep ${SQLITE_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
        endif()
    else()
        externalproject_add(sqlite_ep
                URL
                ${SQLITE_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                CONFIGURE_COMMAND
                "./configure"
                ${SQLITE_CONFIGURE_ARGS}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                BUILD_BYPRODUCTS
                "${SQLITE_STATIC_LIB}")
    endif()
Z
zhiru 已提交
1145

Q
quicksilver 已提交
1146
    file(MAKE_DIRECTORY "${SQLITE_INCLUDE_DIR}")
Z
zhiru 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155
    add_library(sqlite STATIC IMPORTED)
    set_target_properties(
            sqlite
            PROPERTIES IMPORTED_LOCATION "${SQLITE_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${SQLITE_INCLUDE_DIR}")

    add_dependencies(sqlite sqlite_ep)
endmacro()

G
groot 已提交
1156
if(MILVUS_WITH_SQLITE)
Z
zhiru 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
    resolve_dependency(SQLite)
    include_directories(SYSTEM "${SQLITE_INCLUDE_DIR}")
    link_directories(SYSTEM ${SQLITE_PREFIX}/lib/)
endif()

# ----------------------------------------------------------------------
# SQLite_ORM

macro(build_sqlite_orm)
    message(STATUS "Building SQLITE_ORM-${SQLITE_ORM_VERSION} from source")

    set(SQLITE_ORM_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/sqlite_orm_ep-prefix")
Z
zhiru 已提交
1169 1170 1171
    set(SQLITE_ORM_TAR_NAME "${SQLITE_ORM_PREFIX}/sqlite_orm-${SQLITE_ORM_VERSION}.tar.gz")
    set(SQLITE_ORM_INCLUDE_DIR "${SQLITE_ORM_PREFIX}/sqlite_orm-${SQLITE_ORM_VERSION}/include/sqlite_orm")
    if (NOT EXISTS ${SQLITE_ORM_INCLUDE_DIR})
Z
zhiru 已提交
1172
        file(MAKE_DIRECTORY ${SQLITE_ORM_PREFIX})
Z
zhiru 已提交
1173
        file(DOWNLOAD ${SQLITE_ORM_SOURCE_URL}
Z
zhiru 已提交
1174 1175 1176 1177 1178 1179 1180 1181
                ${SQLITE_ORM_TAR_NAME})
        execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${SQLITE_ORM_TAR_NAME}
                        WORKING_DIRECTORY ${SQLITE_ORM_PREFIX})

    endif ()

endmacro()

G
groot 已提交
1182
if(MILVUS_WITH_SQLITE_ORM)
Z
zhiru 已提交
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
    resolve_dependency(SQLite_ORM)
    include_directories(SYSTEM "${SQLITE_ORM_INCLUDE_DIR}")
endif()

# ----------------------------------------------------------------------
# yaml-cpp

macro(build_yamlcpp)
    message(STATUS "Building yaml-cpp-${YAMLCPP_VERSION} from source")
    set(YAMLCPP_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/yaml-cpp_ep-prefix/src/yaml-cpp_ep")
    set(YAMLCPP_STATIC_LIB "${YAMLCPP_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}")
Q
quicksilver 已提交
1194
    set(YAMLCPP_INCLUDE_DIR "${YAMLCPP_PREFIX}/include")
Z
zhiru 已提交
1195 1196 1197 1198 1199 1200 1201
    set(YAMLCPP_CMAKE_ARGS
            ${EP_COMMON_CMAKE_ARGS}
            "-DCMAKE_INSTALL_PREFIX=${YAMLCPP_PREFIX}"
            -DCMAKE_INSTALL_LIBDIR=lib
            -DYAML_CPP_BUILD_TESTS=OFF
            -DYAML_CPP_BUILD_TOOLS=OFF)

Q
quicksilver 已提交
1202 1203 1204 1205
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(YAMLCPP_CACHE_PACKAGE_NAME "yaml-cpp_${YAMLCPP_MD5}.tar.gz")
        set(YAMLCPP_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${YAMLCPP_CACHE_PACKAGE_NAME}")
        set(YAMLCPP_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${YAMLCPP_CACHE_PACKAGE_NAME}")
Z
zhiru 已提交
1206

Q
quicksilver 已提交
1207 1208 1209
        execute_process(COMMAND wget -q --method HEAD ${YAMLCPP_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${YAMLCPP_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
            externalproject_add(yaml-cpp_ep
                    URL
                    ${YAMLCPP_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    BUILD_BYPRODUCTS
                    "${YAMLCPP_STATIC_LIB}"
                    CMAKE_ARGS
                    ${YAMLCPP_CMAKE_ARGS})

            ExternalProject_Create_Cache(yaml-cpp_ep ${YAMLCPP_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/yaml-cpp_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${YAMLCPP_CACHE_URL})
        else()
Q
quicksilver 已提交
1224 1225 1226 1227 1228 1229
            file(DOWNLOAD ${YAMLCPP_CACHE_URL} ${YAMLCPP_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${YAMLCPP_CACHE_URL} TO ${YAMLCPP_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(yaml-cpp_ep ${YAMLCPP_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
        endif()
    else()
        externalproject_add(yaml-cpp_ep
                URL
                ${YAMLCPP_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_BYPRODUCTS
                "${YAMLCPP_STATIC_LIB}"
                CMAKE_ARGS
                ${YAMLCPP_CMAKE_ARGS})
    endif()
Z
zhiru 已提交
1244

Q
quicksilver 已提交
1245
    file(MAKE_DIRECTORY "${YAMLCPP_INCLUDE_DIR}")
Z
zhiru 已提交
1246 1247 1248
    add_library(yaml-cpp STATIC IMPORTED)
    set_target_properties(yaml-cpp
            PROPERTIES IMPORTED_LOCATION "${YAMLCPP_STATIC_LIB}"
Q
quicksilver 已提交
1249
            INTERFACE_INCLUDE_DIRECTORIES "${YAMLCPP_INCLUDE_DIR}")
Z
zhiru 已提交
1250 1251 1252 1253

    add_dependencies(yaml-cpp yaml-cpp_ep)
endmacro()

G
groot 已提交
1254
if(MILVUS_WITH_YAMLCPP)
Z
zhiru 已提交
1255
    resolve_dependency(yaml-cpp)
S
starlord 已提交
1256

Z
zhiru 已提交
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
    get_target_property(YAMLCPP_INCLUDE_DIR yaml-cpp INTERFACE_INCLUDE_DIRECTORIES)
    link_directories(SYSTEM ${YAMLCPP_PREFIX}/lib/)
    include_directories(SYSTEM ${YAMLCPP_INCLUDE_DIR})
endif()

# ----------------------------------------------------------------------
# zlib

macro(build_zlib)
    message(STATUS "Building ZLIB-${ZLIB_VERSION} from source")
    set(ZLIB_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zlib_ep-prefix/src/zlib_ep")
Z
zhiru 已提交
1268
    set(ZLIB_STATIC_LIB_NAME libz.a)
Z
zhiru 已提交
1269
    set(ZLIB_STATIC_LIB "${ZLIB_PREFIX}/lib/${ZLIB_STATIC_LIB_NAME}")
Q
quicksilver 已提交
1270
    set(ZLIB_INCLUDE_DIR "${ZLIB_PREFIX}/include")
Z
zhiru 已提交
1271 1272 1273
    set(ZLIB_CMAKE_ARGS ${EP_COMMON_CMAKE_ARGS} "-DCMAKE_INSTALL_PREFIX=${ZLIB_PREFIX}"
            -DBUILD_SHARED_LIBS=OFF)

Q
quicksilver 已提交
1274 1275 1276 1277 1278
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(ZLIB_CACHE_PACKAGE_NAME "zlib_${ZLIB_MD5}.tar.gz")
        set(ZLIB_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${ZLIB_CACHE_PACKAGE_NAME}")
        set(ZLIB_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${ZLIB_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
1279 1280 1281
        execute_process(COMMAND wget -q --method HEAD ${ZLIB_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${ZLIB_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
            externalproject_add(zlib_ep
                    URL
                    ${ZLIB_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    BUILD_BYPRODUCTS
                    "${ZLIB_STATIC_LIB}"
                    CMAKE_ARGS
                    ${ZLIB_CMAKE_ARGS})

            ExternalProject_Create_Cache(zlib_ep ${ZLIB_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/zlib_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${ZLIB_CACHE_URL})
        else()
Q
quicksilver 已提交
1296 1297 1298 1299 1300 1301
            file(DOWNLOAD ${ZLIB_CACHE_URL} ${ZLIB_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${ZLIB_CACHE_URL} TO ${ZLIB_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(zlib_ep ${ZLIB_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
        endif()
    else()
        externalproject_add(zlib_ep
                URL
                ${ZLIB_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                BUILD_BYPRODUCTS
                "${ZLIB_STATIC_LIB}"
                CMAKE_ARGS
                ${ZLIB_CMAKE_ARGS})
    endif()
Z
zhiru 已提交
1316

Q
quicksilver 已提交
1317
    file(MAKE_DIRECTORY "${ZLIB_INCLUDE_DIR}")
Z
zhiru 已提交
1318 1319 1320
    add_library(zlib STATIC IMPORTED)
    set_target_properties(zlib
            PROPERTIES IMPORTED_LOCATION "${ZLIB_STATIC_LIB}"
Q
quicksilver 已提交
1321
            INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIR}")
Z
zhiru 已提交
1322 1323 1324 1325

    add_dependencies(zlib zlib_ep)
endmacro()

G
groot 已提交
1326
if(MILVUS_WITH_ZLIB)
Z
zhiru 已提交
1327
    resolve_dependency(ZLIB)
S
starlord 已提交
1328

Z
zhiru 已提交
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
    get_target_property(ZLIB_INCLUDE_DIR zlib INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(SYSTEM ${ZLIB_INCLUDE_DIR})
endif()

# ----------------------------------------------------------------------
# zstd

macro(build_zstd)
    message(STATUS "Building zstd-${ZSTD_VERSION} from source")
    set(ZSTD_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/zstd_ep-prefix/src/zstd_ep")

    set(ZSTD_CMAKE_ARGS
            ${EP_COMMON_TOOLCHAIN}
            "-DCMAKE_INSTALL_PREFIX=${ZSTD_PREFIX}"
            -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
            -DCMAKE_INSTALL_LIBDIR=lib #${CMAKE_INSTALL_LIBDIR}
            -DZSTD_BUILD_PROGRAMS=off
            -DZSTD_BUILD_SHARED=off
            -DZSTD_BUILD_STATIC=on
            -DZSTD_MULTITHREAD_SUPPORT=off)

Z
zhiru 已提交
1350 1351

    set(ZSTD_STATIC_LIB "${ZSTD_PREFIX}/lib/libzstd.a")
Q
quicksilver 已提交
1352
    set(ZSTD_INCLUDE_DIR "${ZSTD_PREFIX}/include")
Z
zhiru 已提交
1353 1354 1355 1356 1357 1358
    set(ZSTD_CMAKE_ARGS
            ${ZSTD_CMAKE_ARGS}
            -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
            -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
            -DCMAKE_C_FLAGS=${EP_C_FLAGS}
            -DCMAKE_CXX_FLAGS=${EP_CXX_FLAGS})
Z
zhiru 已提交
1359 1360 1361 1362 1363

    if(CMAKE_VERSION VERSION_LESS 3.7)
        message(FATAL_ERROR "Building zstd using ExternalProject requires at least CMake 3.7")
    endif()

Q
quicksilver 已提交
1364 1365 1366 1367 1368
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(ZSTD_CACHE_PACKAGE_NAME "zstd_${ZSTD_MD5}.tar.gz")
        set(ZSTD_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${ZSTD_CACHE_PACKAGE_NAME}")
        set(ZSTD_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${ZSTD_CACHE_PACKAGE_NAME}")

Q
quicksilver 已提交
1369 1370 1371
        execute_process(COMMAND wget -q --method HEAD ${ZSTD_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${ZSTD_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
Q
quicksilver 已提交
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
            externalproject_add(zstd_ep
                    ${EP_LOG_OPTIONS}
                    CMAKE_ARGS
                    ${ZSTD_CMAKE_ARGS}
                    SOURCE_SUBDIR
                    "build/cmake"
                    BUILD_COMMAND
                    ${MAKE}
                    ${MAKE_BUILD_ARGS}
                    INSTALL_DIR
                    ${ZSTD_PREFIX}
                    URL
                    ${ZSTD_SOURCE_URL}
                    BUILD_BYPRODUCTS
                    "${ZSTD_STATIC_LIB}")

            ExternalProject_Create_Cache(zstd_ep ${ZSTD_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/zstd_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${ZSTD_CACHE_URL})
        else()
Q
quicksilver 已提交
1390 1391 1392 1393 1394 1395
            file(DOWNLOAD ${ZSTD_CACHE_URL} ${ZSTD_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${ZSTD_CACHE_URL} TO ${ZSTD_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(zstd_ep ${ZSTD_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
Q
quicksilver 已提交
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
        endif()
    else()
        externalproject_add(zstd_ep
                ${EP_LOG_OPTIONS}
                CMAKE_ARGS
                ${ZSTD_CMAKE_ARGS}
                SOURCE_SUBDIR
                "build/cmake"
                BUILD_COMMAND
                ${MAKE}
                ${MAKE_BUILD_ARGS}
                INSTALL_DIR
                ${ZSTD_PREFIX}
                URL
                ${ZSTD_SOURCE_URL}
                BUILD_BYPRODUCTS
                "${ZSTD_STATIC_LIB}")
    endif()
Z
zhiru 已提交
1414

Q
quicksilver 已提交
1415
    file(MAKE_DIRECTORY "${ZSTD_INCLUDE_DIR}")
Z
zhiru 已提交
1416 1417 1418
    add_library(zstd STATIC IMPORTED)
    set_target_properties(zstd
            PROPERTIES IMPORTED_LOCATION "${ZSTD_STATIC_LIB}"
Q
quicksilver 已提交
1419
            INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIR}")
Z
zhiru 已提交
1420 1421 1422 1423

    add_dependencies(zstd zstd_ep)
endmacro()

G
groot 已提交
1424
if(MILVUS_WITH_ZSTD)
Z
zhiru 已提交
1425
    resolve_dependency(ZSTD)
S
starlord 已提交
1426

Z
zhiru 已提交
1427 1428 1429 1430
    get_target_property(ZSTD_INCLUDE_DIR zstd INTERFACE_INCLUDE_DIRECTORIES)
    link_directories(SYSTEM ${ZSTD_PREFIX}/lib)
    include_directories(SYSTEM ${ZSTD_INCLUDE_DIR})
endif()
1431

Y
yudong.cai 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
# ----------------------------------------------------------------------
# libunwind

macro(build_libunwind)
    message(STATUS "Building libunwind-${LIBUNWIND_VERSION} from source")
    set(LIBUNWIND_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libunwind_ep-prefix/src/libunwind_ep/install")
    set(LIBUNWIND_INCLUDE_DIR "${LIBUNWIND_PREFIX}/include")
    set(LIBUNWIND_SHARED_LIB "${LIBUNWIND_PREFIX}/lib/libunwind${CMAKE_SHARED_LIBRARY_SUFFIX}")
    set(LIBUNWIND_CONFIGURE_ARGS "--prefix=${LIBUNWIND_PREFIX}")

Q
quicksilver 已提交
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(LIBUNWIND_CACHE_PACKAGE_NAME "libunwind_${LIBUNWIND_MD5}.tar.gz")
        set(LIBUNWIND_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${LIBUNWIND_CACHE_PACKAGE_NAME}")
        set(LIBUNWIND_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${LIBUNWIND_CACHE_PACKAGE_NAME}")

        execute_process(COMMAND wget -q --method HEAD ${LIBUNWIND_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${LIBUNWIND_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
            externalproject_add(libunwind_ep
                    URL
                    ${LIBUNWIND_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    CONFIGURE_COMMAND
                    "./configure"
                    ${LIBUNWIND_CONFIGURE_ARGS}
                    BUILD_COMMAND
                    ${MAKE} ${MAKE_BUILD_ARGS}
                    BUILD_IN_SOURCE
                    1
                    INSTALL_COMMAND
                    ${MAKE} install
                    BUILD_BYPRODUCTS
                    ${LIBUNWIND_SHARED_LIB})

            ExternalProject_Create_Cache(libunwind_ep ${LIBUNWIND_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/libunwind_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${LIBUNWIND_CACHE_URL})
        else()
            file(DOWNLOAD ${LIBUNWIND_CACHE_URL} ${LIBUNWIND_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${LIBUNWIND_CACHE_URL} TO ${LIBUNWIND_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(libunwind_ep ${LIBUNWIND_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
        endif()
    else()
        externalproject_add(libunwind_ep
                URL
                ${LIBUNWIND_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                CONFIGURE_COMMAND
                "./configure"
                ${LIBUNWIND_CONFIGURE_ARGS}
                BUILD_COMMAND
                ${MAKE} ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                INSTALL_COMMAND
                ${MAKE} install
                BUILD_BYPRODUCTS
                ${LIBUNWIND_SHARED_LIB})
    endif()
Y
yudong.cai 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519

    file(MAKE_DIRECTORY "${LIBUNWIND_INCLUDE_DIR}")

    add_library(libunwind SHARED IMPORTED)
    set_target_properties(libunwind
            PROPERTIES IMPORTED_LOCATION "${LIBUNWIND_SHARED_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${LIBUNWIND_INCLUDE_DIR}")

    add_dependencies(libunwind libunwind_ep)
endmacro()

if(MILVUS_WITH_LIBUNWIND)
    resolve_dependency(libunwind)

    get_target_property(LIBUNWIND_INCLUDE_DIR libunwind INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(SYSTEM ${LIBUNWIND_INCLUDE_DIR})
endif()

# ----------------------------------------------------------------------
# gperftools

macro(build_gperftools)
    message(STATUS "Building gperftools-${GPERFTOOLS_VERSION} from source")
    set(GPERFTOOLS_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/gperftools_ep-prefix/src/gperftools_ep")
    set(GPERFTOOLS_INCLUDE_DIR "${GPERFTOOLS_PREFIX}/include")
    set(GPERFTOOLS_STATIC_LIB "${GPERFTOOLS_PREFIX}/lib/libprofiler${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GPERFTOOLS_CONFIGURE_ARGS "--prefix=${GPERFTOOLS_PREFIX}")

Q
quicksilver 已提交
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(GPERFTOOLS_CACHE_PACKAGE_NAME "gperftools_${GPERFTOOLS_MD5}.tar.gz")
        set(GPERFTOOLS_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${GPERFTOOLS_CACHE_PACKAGE_NAME}")
        set(GPERFTOOLS_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${GPERFTOOLS_CACHE_PACKAGE_NAME}")

        execute_process(COMMAND wget -q --method HEAD ${GPERFTOOLS_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${GPERFTOOLS_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
            externalproject_add(gperftools_ep
                    URL
                    ${GPERFTOOLS_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    CONFIGURE_COMMAND
                    "./configure"
                    ${GPERFTOOLS_CONFIGURE_ARGS}
                    BUILD_COMMAND
                    ${MAKE} ${MAKE_BUILD_ARGS}
                    BUILD_IN_SOURCE
                    1
                    INSTALL_COMMAND
                    ${MAKE} install
                    BUILD_BYPRODUCTS
                    ${GPERFTOOLS_STATIC_LIB})

            ExternalProject_Create_Cache(gperftools_ep ${GPERFTOOLS_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/gperftools_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${GPERFTOOLS_CACHE_URL})
        else()
            file(DOWNLOAD ${GPERFTOOLS_CACHE_URL} ${GPERFTOOLS_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${GPERFTOOLS_CACHE_URL} TO ${GPERFTOOLS_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(gperftools_ep ${GPERFTOOLS_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
        endif()
    else()
        externalproject_add(gperftools_ep
                URL
                ${GPERFTOOLS_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                CONFIGURE_COMMAND
                "./configure"
                ${GPERFTOOLS_CONFIGURE_ARGS}
                BUILD_COMMAND
                ${MAKE} ${MAKE_BUILD_ARGS}
                BUILD_IN_SOURCE
                1
                INSTALL_COMMAND
                ${MAKE} install
                BUILD_BYPRODUCTS
                ${GPERFTOOLS_STATIC_LIB})
    endif()
Y
yudong.cai 已提交
1570

Q
quicksilver 已提交
1571 1572
    ExternalProject_Add_StepDependencies(gperftools_ep build libunwind_ep)

Y
yudong.cai 已提交
1573 1574
    file(MAKE_DIRECTORY "${GPERFTOOLS_INCLUDE_DIR}")

Y
yudong.cai 已提交
1575
    add_library(gperftools STATIC IMPORTED)
Y
yudong.cai 已提交
1576 1577
    set_target_properties(gperftools
            PROPERTIES IMPORTED_LOCATION "${GPERFTOOLS_STATIC_LIB}"
Y
yudong.cai 已提交
1578 1579
            INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}"
            INTERFACE_LINK_LIBRARIES libunwind)
Y
yudong.cai 已提交
1580 1581

    add_dependencies(gperftools gperftools_ep)
Y
yudong.cai 已提交
1582
    add_dependencies(gperftools libunwind_ep)
Y
yudong.cai 已提交
1583 1584 1585 1586 1587 1588 1589
endmacro()

if(MILVUS_WITH_GPERFTOOLS)
    resolve_dependency(gperftools)

    get_target_property(GPERFTOOLS_INCLUDE_DIR gperftools INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(SYSTEM ${GPERFTOOLS_INCLUDE_DIR})
Y
yudong.cai 已提交
1590
    link_directories(SYSTEM ${GPERFTOOLS_PREFIX}/lib)
Y
yudong.cai 已提交
1591
endif()
Z
zhiru 已提交
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606

# ----------------------------------------------------------------------
# GRPC

macro(build_grpc)
    message(STATUS "Building GRPC-${GRPC_VERSION} from source")
    set(GRPC_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/grpc_ep-prefix/src/grpc_ep/install")
    set(GRPC_INCLUDE_DIR "${GRPC_PREFIX}/include")
    set(GRPC_STATIC_LIB "${GRPC_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}grpc${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GRPC++_STATIC_LIB "${GRPC_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}grpc++${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GRPCPP_CHANNELZ_STATIC_LIB "${GRPC_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}grpcpp_channelz${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GRPC_PROTOBUF_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/grpc_ep-prefix/src/grpc_ep/libs/opt/protobuf")
    set(GRPC_PROTOBUF_STATIC_LIB "${GRPC_PROTOBUF_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}protobuf${CMAKE_STATIC_LIBRARY_SUFFIX}")
    set(GRPC_PROTOC_STATIC_LIB "${GRPC_PROTOBUF_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}protoc${CMAKE_STATIC_LIBRARY_SUFFIX}")

Q
quicksilver 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
    if(USE_JFROG_CACHE STREQUAL "ON")
        set(GRPC_CACHE_PACKAGE_NAME "grpc_${GRPC_MD5}.tar.gz")
        set(GRPC_CACHE_URL "${JFROG_ARTFACTORY_CACHE_URL}/${GRPC_CACHE_PACKAGE_NAME}")
        set(GRPC_CACHE_PACKAGE_PATH "${THIRDPARTY_PACKAGE_CACHE}/${GRPC_CACHE_PACKAGE_NAME}")

        execute_process(COMMAND wget -q --method HEAD ${GRPC_CACHE_URL} RESULT_VARIABLE return_code)
        message(STATUS "Check the remote file ${GRPC_CACHE_URL}. return code = ${return_code}")
        if (NOT return_code EQUAL 0)
            externalproject_add(grpc_ep
                    URL
                    ${GRPC_SOURCE_URL}
                    ${EP_LOG_OPTIONS}
                    CONFIGURE_COMMAND
                    ""
                    BUILD_IN_SOURCE
                    1
                    BUILD_COMMAND
                    ${MAKE} ${MAKE_BUILD_ARGS} prefix=${GRPC_PREFIX}
                    INSTALL_COMMAND
                    ${MAKE} install prefix=${GRPC_PREFIX}
                    BUILD_BYPRODUCTS
                    ${GRPC_STATIC_LIB}
                    ${GRPC++_STATIC_LIB}
                    ${GRPCPP_CHANNELZ_STATIC_LIB}
                    ${GRPC_PROTOBUF_STATIC_LIB}
                    ${GRPC_PROTOC_STATIC_LIB})

            ExternalProject_Create_Cache(grpc_ep ${GRPC_CACHE_PACKAGE_PATH} "${CMAKE_CURRENT_BINARY_DIR}/grpc_ep-prefix" ${JFROG_USER_NAME} ${JFROG_PASSWORD} ${GRPC_CACHE_URL})
        else()
            file(DOWNLOAD ${GRPC_CACHE_URL} ${GRPC_CACHE_PACKAGE_PATH} STATUS status)
            list(GET status 0 status_code)
            message(STATUS "DOWNLOADING FROM ${GRPC_CACHE_URL} TO ${GRPC_CACHE_PACKAGE_PATH}. STATUS = ${status_code}")
            if (status_code EQUAL 0)
                ExternalProject_Use_Cache(grpc_ep ${GRPC_CACHE_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR})
            endif()
        endif()
    else()
        externalproject_add(grpc_ep
                URL
                ${GRPC_SOURCE_URL}
                ${EP_LOG_OPTIONS}
                CONFIGURE_COMMAND
                ""
                BUILD_IN_SOURCE
                1
                BUILD_COMMAND
                ${MAKE} ${MAKE_BUILD_ARGS} prefix=${GRPC_PREFIX}
                INSTALL_COMMAND
                ${MAKE} install prefix=${GRPC_PREFIX}
                BUILD_BYPRODUCTS
                ${GRPC_STATIC_LIB}
                ${GRPC++_STATIC_LIB}
                ${GRPCPP_CHANNELZ_STATIC_LIB}
                ${GRPC_PROTOBUF_STATIC_LIB}
                ${GRPC_PROTOC_STATIC_LIB})
    endif()
Z
zhiru 已提交
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695

    file(MAKE_DIRECTORY "${GRPC_INCLUDE_DIR}")

    add_library(grpc STATIC IMPORTED)
    set_target_properties(grpc
            PROPERTIES IMPORTED_LOCATION "${GRPC_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${GRPC_INCLUDE_DIR}")

    add_library(grpc++ STATIC IMPORTED)
    set_target_properties(grpc++
            PROPERTIES IMPORTED_LOCATION "${GRPC++_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${GRPC_INCLUDE_DIR}")

    add_library(grpcpp_channelz STATIC IMPORTED)
    set_target_properties(grpcpp_channelz
            PROPERTIES IMPORTED_LOCATION "${GRPCPP_CHANNELZ_STATIC_LIB}"
            INTERFACE_INCLUDE_DIRECTORIES "${GRPC_INCLUDE_DIR}")

    add_library(grpc_protobuf STATIC IMPORTED)
    set_target_properties(grpc_protobuf
            PROPERTIES IMPORTED_LOCATION "${GRPC_PROTOBUF_STATIC_LIB}")

    add_library(grpc_protoc STATIC IMPORTED)
    set_target_properties(grpc_protoc
            PROPERTIES IMPORTED_LOCATION "${GRPC_PROTOC_STATIC_LIB}")

    add_dependencies(grpc grpc_ep)
    add_dependencies(grpc++ grpc_ep)
    add_dependencies(grpcpp_channelz grpc_ep)
    add_dependencies(grpc_protobuf grpc_ep)
    add_dependencies(grpc_protoc grpc_ep)
endmacro()

Z
zhiru 已提交
1696 1697
if(MILVUS_WITH_GRPC)
    resolve_dependency(GRPC)
Z
zhiru 已提交
1698

Z
zhiru 已提交
1699 1700 1701
    get_target_property(GRPC_INCLUDE_DIR grpc INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(SYSTEM ${GRPC_INCLUDE_DIR})
    link_directories(SYSTEM ${GRPC_PREFIX}/lib)
Z
zhiru 已提交
1702

Z
zhiru 已提交
1703 1704 1705 1706
    set(GRPC_THIRD_PARTY_DIR ${CMAKE_CURRENT_BINARY_DIR}/grpc_ep-prefix/src/grpc_ep/third_party)
    include_directories(SYSTEM ${GRPC_THIRD_PARTY_DIR}/protobuf/src)
    link_directories(SYSTEM ${GRPC_PROTOBUF_LIB_DIR})
endif()