DefineOptions.cmake 5.7 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_EASYLOGGINGPP "Build with Easylogging++ library" ON)
Z
zhiru 已提交
59

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

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

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

Z
zhiru 已提交
66 67
define_option(MILVUS_WITH_MYSQLPP "Build with MySQL++" ON)

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

Y
yudong.cai 已提交
70 71 72 73 74
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 已提交
75 76
define_option(MILVUS_WITH_GRPC "Build with GRPC" ON)

Z
Zhiru Zhu 已提交
77 78
define_option(MILVUS_WITH_ZLIB "Build with zlib compression" ON)

Z
zhiru 已提交
79 80 81 82 83 84 85 86
#----------------------------------------------------------------------
if(MSVC)
    set_option_category("MSVC")

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

G
groot 已提交
87
    define_option(MILVUS_USE_STATIC_CRT "Build MILVUS with statically linked CRT" OFF)
Z
zhiru 已提交
88 89 90 91
endif()


#----------------------------------------------------------------------
Z
zhiru 已提交
92 93
set_option_category("Test and benchmark")

94
unset(MILVUS_BUILD_TESTS CACHE)
Z
zhiru 已提交
95
if (BUILD_UNIT_TEST)
G
groot 已提交
96
    define_option(MILVUS_BUILD_TESTS "Build the MILVUS googletest unit tests" ON)
Z
zhiru 已提交
97
else()
G
groot 已提交
98
    define_option(MILVUS_BUILD_TESTS "Build the MILVUS googletest unit tests" OFF)
Z
zhiru 已提交
99
endif(BUILD_UNIT_TEST)
Z
zhiru 已提交
100 101 102 103

#----------------------------------------------------------------------
macro(config_summary)
    message(STATUS "---------------------------------------------------------------------")
G
groot 已提交
104
    message(STATUS "MILVUS version:                                 ${MILVUS_VERSION}")
Z
zhiru 已提交
105 106 107 108 109 110 111 112 113 114 115
    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 已提交
116
    foreach(category ${MILVUS_OPTION_CATEGORIES})
Z
zhiru 已提交
117 118 119 120

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

G
groot 已提交
121
        set(option_names ${MILVUS_${category}_OPTION_NAMES})
Z
zhiru 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

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