DefineOptions.cmake 6.9 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_VENDORED "Use vendored Boost instead of existing Boost. \
Z
zhiru 已提交
61 62
Note that this requires linking Boost statically" ON)

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

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

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

X
MS-154  
xj.lin 已提交
69
define_option(MILVUS_WITH_FAISS "Build with FAISS library" OFF)
Z
zhiru 已提交
70

X
MS-154  
xj.lin 已提交
71
define_option(MILVUS_WITH_FAISS_GPU_VERSION "Build with FAISS GPU version" OFF)
Z
zhiru 已提交
72

X
MS-154  
xj.lin 已提交
73
define_option(MILVUS_WITH_LAPACK "Build with LAPACK library" OFF)
Z
zhiru 已提交
74

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

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

X
MS-154  
xj.lin 已提交
79
define_option(MILVUS_WITH_OPENBLAS "Build with OpenBLAS library" OFF)
Z
zhiru 已提交
80

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

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

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

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

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

Z
zhiru 已提交
91 92
define_option(MILVUS_WITH_MYSQLPP "Build with MySQL++" ON)

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

G
groot 已提交
95
define_option(MILVUS_WITH_ZLIB "Build with zlib compression" ON)
Z
zhiru 已提交
96

X
xj.lin 已提交
97
define_option(MILVUS_WITH_KNOWHERE "Build with Knowhere" OFF)
X
MS-154  
xj.lin 已提交
98

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

107 108
define_option(MILVUS_WITH_AWS "Build with AWS SDK" ON)

Y
yudong.cai 已提交
109 110 111 112 113
if (MILVUS_ENABLE_PROFILING STREQUAL "ON")
    define_option(MILVUS_WITH_LIBUNWIND "Build with libunwind" ON)
    define_option(MILVUS_WITH_GPERFTOOLS "Build with gperftools" ON)
endif()

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

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

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


#----------------------------------------------------------------------
Z
zhiru 已提交
127 128 129
set_option_category("Test and benchmark")

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

#----------------------------------------------------------------------
macro(config_summary)
    message(STATUS "---------------------------------------------------------------------")
G
groot 已提交
138
    message(STATUS "MILVUS version:                                 ${MILVUS_VERSION}")
Z
zhiru 已提交
139 140 141 142 143 144 145 146 147 148 149
    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 已提交
150
    foreach(category ${MILVUS_OPTION_CATEGORIES})
Z
zhiru 已提交
151 152 153 154

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

G
groot 已提交
155
        set(option_names ${MILVUS_${category}_OPTION_NAMES})
Z
zhiru 已提交
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 203 204

        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()