DefineOptions.cmake 7.0 KB
Newer Older
Z
zhiru 已提交
1 2

macro(set_option_category name)
G
groot 已提交
3 4
    set(MILVUS_OPTION_CATEGORY ${name})
    list(APPEND "MILVUS_OPTION_CATEGORIES" ${name})
Z
zhiru 已提交
5 6 7 8
endmacro()

macro(define_option name description default)
    option(${name} ${description} ${default})
G
groot 已提交
9
    list(APPEND "MILVUS_${MILVUS_OPTION_CATEGORY}_OPTION_NAMES" ${name})
Z
zhiru 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    set("${name}_OPTION_DESCRIPTION" ${description})
    set("${name}_OPTION_DEFAULT" ${default})
    set("${name}_OPTION_TYPE" "bool")
endmacro()

function(list_join lst glue out)
    if("${${lst}}" STREQUAL "")
        set(${out} "" PARENT_SCOPE)
        return()
    endif()

    list(GET ${lst} 0 joined)
    list(REMOVE_AT ${lst} 0)
    foreach(item ${${lst}})
        set(joined "${joined}${glue}${item}")
    endforeach()
    set(${out} ${joined} PARENT_SCOPE)
endfunction()

macro(define_option_string name description default)
    set(${name} ${default} CACHE STRING ${description})
G
groot 已提交
31
    list(APPEND "MILVUS_${MILVUS_OPTION_CATEGORY}_OPTION_NAMES" ${name})
Z
zhiru 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45
    set("${name}_OPTION_DESCRIPTION" ${description})
    set("${name}_OPTION_DEFAULT" "\"${default}\"")
    set("${name}_OPTION_TYPE" "string")

    set("${name}_OPTION_ENUM" ${ARGN})
    list_join("${name}_OPTION_ENUM" "|" "${name}_OPTION_ENUM")
    if(NOT ("${${name}_OPTION_ENUM}" STREQUAL ""))
        set_property(CACHE ${name} PROPERTY STRINGS ${ARGN})
    endif()
endmacro()

#----------------------------------------------------------------------
set_option_category("Thirdparty")

G
groot 已提交
46
set(MILVUS_DEPENDENCY_SOURCE_DEFAULT "AUTO")
Z
zhiru 已提交
47

G
groot 已提交
48 49 50
define_option_string(MILVUS_DEPENDENCY_SOURCE
                    "Method to use for acquiring MILVUS's build dependencies"
                    "${MILVUS_DEPENDENCY_SOURCE_DEFAULT}"
Z
zhiru 已提交
51 52 53 54
                    "AUTO"
                    "BUNDLED"
                    "SYSTEM")

G
groot 已提交
55
define_option(MILVUS_VERBOSE_THIRDPARTY_BUILD
Z
zhiru 已提交
56
        "Show output from ExternalProjects rather than just logging to files" ON)
Z
zhiru 已提交
57

G
groot 已提交
58
define_option(MILVUS_WITH_ARROW "Build with ARROW" OFF)
Z
zhiru 已提交
59

G
groot 已提交
60
define_option(MILVUS_BOOST_USE_SHARED "Rely on boost shared libraries where relevant" OFF)
Z
zhiru 已提交
61

G
groot 已提交
62
define_option(MILVUS_BOOST_VENDORED "Use vendored Boost instead of existing Boost. \
Z
zhiru 已提交
63 64
Note that this requires linking Boost statically" ON)

G
groot 已提交
65
define_option(MILVUS_BOOST_HEADER_ONLY "Use only BOOST headers" OFF)
Z
zhiru 已提交
66

G
groot 已提交
67
define_option(MILVUS_WITH_BZ2 "Build with BZ2 compression" ON)
Z
zhiru 已提交
68

G
groot 已提交
69
define_option(MILVUS_WITH_EASYLOGGINGPP "Build with Easylogging++ library" ON)
Z
zhiru 已提交
70

G
groot 已提交
71
define_option(MILVUS_WITH_FAISS "Build with FAISS library" ON)
Z
zhiru 已提交
72

G
groot 已提交
73
define_option(MILVUS_WITH_FAISS_GPU_VERSION "Build with FAISS GPU version" ON)
Z
zhiru 已提交
74

G
groot 已提交
75
#define_option_string(MILVUS_FAISS_GPU_ARCH "Specifying which GPU architectures to build against"
Z
zhiru 已提交
76
#        "-gencode=arch=compute_35,code=compute_35 -gencode=arch=compute_52,code=compute_52 -gencode=arch=compute_60,code=compute_60 -gencode=arch=compute_61,code=compute_61")
Z
zhiru 已提交
77

G
groot 已提交
78
define_option(MILVUS_WITH_LAPACK "Build with LAPACK library" ON)
Z
zhiru 已提交
79

G
groot 已提交
80
define_option(MILVUS_WITH_LZ4 "Build with lz4 compression" ON)
Z
zhiru 已提交
81

G
groot 已提交
82
define_option(MILVUS_WITH_JSONCONS "Build with JSONCONS" OFF)
Z
zhiru 已提交
83

G
groot 已提交
84
define_option(MILVUS_WITH_OPENBLAS "Build with OpenBLAS library" ON)
Z
zhiru 已提交
85

G
groot 已提交
86
define_option(MILVUS_WITH_PROMETHEUS "Build with PROMETHEUS library" ON)
Z
zhiru 已提交
87

G
groot 已提交
88
define_option(MILVUS_WITH_ROCKSDB "Build with RocksDB library" OFF)
Z
zhiru 已提交
89

G
groot 已提交
90
define_option(MILVUS_WITH_SNAPPY "Build with Snappy compression" ON)
Z
zhiru 已提交
91

G
groot 已提交
92
define_option(MILVUS_WITH_SQLITE "Build with SQLite library" ON)
Z
zhiru 已提交
93

G
groot 已提交
94
define_option(MILVUS_WITH_SQLITE_ORM "Build with SQLite ORM library" ON)
Z
zhiru 已提交
95

G
groot 已提交
96
define_option(MILVUS_WITH_THRIFT "Build with Apache Thrift library" ON)
Z
zhiru 已提交
97

G
groot 已提交
98
define_option(MILVUS_WITH_YAMLCPP "Build with yaml-cpp library" ON)
Z
zhiru 已提交
99

G
groot 已提交
100
define_option(MILVUS_WITH_ZLIB "Build with zlib compression" ON)
Z
zhiru 已提交
101 102

if(CMAKE_VERSION VERSION_LESS 3.7)
G
groot 已提交
103
    set(MILVUS_WITH_ZSTD_DEFAULT OFF)
Z
zhiru 已提交
104 105
else()
    # ExternalProject_Add(SOURCE_SUBDIR) is available since CMake 3.7.
G
groot 已提交
106
    set(MILVUS_WITH_ZSTD_DEFAULT ON)
Z
zhiru 已提交
107
endif()
G
groot 已提交
108
define_option(MILVUS_WITH_ZSTD "Build with zstd compression" ${MILVUS_WITH_ZSTD_DEFAULT})
Z
zhiru 已提交
109

110 111
define_option(MILVUS_WITH_AWS "Build with AWS SDK" ON)

Z
zhiru 已提交
112 113 114 115 116 117 118 119
#----------------------------------------------------------------------
if(MSVC)
    set_option_category("MSVC")

    define_option(MSVC_LINK_VERBOSE
            "Pass verbose linking options when linking libraries and executables"
            OFF)

G
groot 已提交
120
    define_option(MILVUS_USE_STATIC_CRT "Build MILVUS with statically linked CRT" OFF)
Z
zhiru 已提交
121 122 123 124
endif()


#----------------------------------------------------------------------
Z
zhiru 已提交
125 126 127
set_option_category("Test and benchmark")

if (BUILD_UNIT_TEST)
G
groot 已提交
128
    define_option(MILVUS_BUILD_TESTS "Build the MILVUS googletest unit tests" ON)
Z
zhiru 已提交
129
else()
G
groot 已提交
130
    define_option(MILVUS_BUILD_TESTS "Build the MILVUS googletest unit tests" OFF)
Z
zhiru 已提交
131
endif(BUILD_UNIT_TEST)
Z
zhiru 已提交
132 133 134 135

#----------------------------------------------------------------------
macro(config_summary)
    message(STATUS "---------------------------------------------------------------------")
G
groot 已提交
136
    message(STATUS "MILVUS version:                                 ${MILVUS_VERSION}")
Z
zhiru 已提交
137 138 139 140 141 142 143 144 145 146 147
    message(STATUS)
    message(STATUS "Build configuration summary:")

    message(STATUS "  Generator: ${CMAKE_GENERATOR}")
    message(STATUS "  Build type: ${CMAKE_BUILD_TYPE}")
    message(STATUS "  Source directory: ${CMAKE_CURRENT_SOURCE_DIR}")
    if(${CMAKE_EXPORT_COMPILE_COMMANDS})
        message(
                STATUS "  Compile commands: ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json")
    endif()

G
groot 已提交
148
    foreach(category ${MILVUS_OPTION_CATEGORIES})
Z
zhiru 已提交
149 150 151 152

        message(STATUS)
        message(STATUS "${category} options:")

G
groot 已提交
153
        set(option_names ${MILVUS_${category}_OPTION_NAMES})
Z
zhiru 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

        set(max_value_length 0)
        foreach(name ${option_names})
            string(LENGTH "\"${${name}}\"" value_length)
            if(${max_value_length} LESS ${value_length})
                set(max_value_length ${value_length})
            endif()
        endforeach()

        foreach(name ${option_names})
            if("${${name}_OPTION_TYPE}" STREQUAL "string")
                set(value "\"${${name}}\"")
            else()
                set(value "${${name}}")
            endif()

            set(default ${${name}_OPTION_DEFAULT})
            set(description ${${name}_OPTION_DESCRIPTION})
            string(LENGTH ${description} description_length)
            if(${description_length} LESS 70)
                string(
                        SUBSTRING
                        "                                                                     "
                        ${description_length} -1 description_padding)
            else()
                set(description_padding "
                ")
            endif()

            set(comment "[${name}]")

            if("${value}" STREQUAL "${default}")
                set(comment "[default] ${comment}")
            endif()

            if(NOT ("${${name}_OPTION_ENUM}" STREQUAL ""))
                set(comment "${comment} [${${name}_OPTION_ENUM}]")
            endif()

            string(
                    SUBSTRING "${value}                                                             "
                    0 ${max_value_length} value)

            message(STATUS "  ${description} ${description_padding} ${value} ${comment}")
        endforeach()

    endforeach()

endmacro()