DefineOptions.cmake 6.9 KB
Newer Older
Z
zhiru 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

macro(set_option_category name)
    set(MEGASEARCH_OPTION_CATEGORY ${name})
    list(APPEND "MEGASEARCH_OPTION_CATEGORIES" ${name})
endmacro()

macro(define_option name description default)
    option(${name} ${description} ${default})
    list(APPEND "MEGASEARCH_${MEGASEARCH_OPTION_CATEGORY}_OPTION_NAMES" ${name})
    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})
    list(APPEND "MEGASEARCH_${MEGASEARCH_OPTION_CATEGORY}_OPTION_NAMES" ${name})
    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")

set(MEGASEARCH_DEPENDENCY_SOURCE_DEFAULT "AUTO")

define_option_string(MEGASEARCH_DEPENDENCY_SOURCE
                    "Method to use for acquiring MEGASEARCH's build dependencies"
                    "${MEGASEARCH_DEPENDENCY_SOURCE_DEFAULT}"
                    "AUTO"
                    "BUNDLED"
                    "SYSTEM")

define_option(MEGASEARCH_VERBOSE_THIRDPARTY_BUILD
Z
zhiru 已提交
56
        "Show output from ExternalProjects rather than just logging to files" ON)
Z
zhiru 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

define_option(MEGASEARCH_BOOST_USE_SHARED "Rely on boost shared libraries where relevant" OFF)

define_option(MEGASEARCH_BOOST_VENDORED "Use vendored Boost instead of existing Boost. \
Note that this requires linking Boost statically" ON)

define_option(MEGASEARCH_BOOST_HEADER_ONLY "Use only BOOST headers" OFF)

define_option(MEGASEARCH_WITH_BZ2 "Build with BZ2 compression" ON)

define_option(MEGASEARCH_WITH_EASYLOGGINGPP "Build with Easylogging++ library" ON)

define_option(MEGASEARCH_WITH_FAISS "Build with FAISS library" ON)

define_option(MEGASEARCH_WITH_FAISS_GPU_VERSION "Build with FAISS GPU version" ON)

define_option_string(MEGASEARCH_FAISS_GPU_ARCH "Specifying which GPU architectures to build against"
        "-gencode=arch=compute_61,code=sm_61")

define_option(MEGASEARCH_WITH_LAPACK "Build with LAPACK library" ON)

define_option(MEGASEARCH_WITH_LZ4 "Build with lz4 compression" ON)

define_option(MEGASEARCH_WITH_OPENBLAS "Build with OpenBLAS library" ON)

Z
zhiru 已提交
82 83
define_option(MEGASEARCH_WITH_PROMETHEUS "Build with PROMETHEUS library" ON)

Z
zhiru 已提交
84
define_option(MEGASEARCH_WITH_ROCKSDB "Build with RocksDB library" OFF)
Z
zhiru 已提交
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

define_option(MEGASEARCH_WITH_SNAPPY "Build with Snappy compression" ON)

define_option(MEGASEARCH_WITH_SQLITE "Build with SQLite library" ON)

define_option(MEGASEARCH_WITH_SQLITE_ORM "Build with SQLite ORM library" ON)

define_option(MEGASEARCH_WITH_THRIFT "Build with Apache Thrift library" ON)

define_option(MEGASEARCH_WITH_YAMLCPP "Build with yaml-cpp library" ON)

define_option(MEGASEARCH_WITH_ZLIB "Build with zlib compression" ON)

if(CMAKE_VERSION VERSION_LESS 3.7)
    set(MEGASEARCH_WITH_ZSTD_DEFAULT OFF)
else()
    # ExternalProject_Add(SOURCE_SUBDIR) is available since CMake 3.7.
    set(MEGASEARCH_WITH_ZSTD_DEFAULT ON)
endif()
define_option(MEGASEARCH_WITH_ZSTD "Build with zstd compression" ${MEGASEARCH_WITH_ZSTD_DEFAULT})

#----------------------------------------------------------------------
if(MSVC)
    set_option_category("MSVC")

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

    define_option(MEGASEARCH_USE_STATIC_CRT "Build MEGASEARCH with statically linked CRT" OFF)
endif()


#----------------------------------------------------------------------
Z
zhiru 已提交
119 120 121 122 123 124 125
set_option_category("Test and benchmark")

if (BUILD_UNIT_TEST)
    define_option(MEGASEARCH_BUILD_TESTS "Build the MEGASEARCH googletest unit tests" ON)
else()
    define_option(MEGASEARCH_BUILD_TESTS "Build the MEGASEARCH googletest unit tests" OFF)
endif(BUILD_UNIT_TEST)
Z
zhiru 已提交
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 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

#----------------------------------------------------------------------
macro(config_summary)
    message(STATUS "---------------------------------------------------------------------")
    message(STATUS "MEGASEARCH version:                                 ${MEGASEARCH_VERSION}")
    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()

    foreach(category ${MEGASEARCH_OPTION_CATEGORIES})

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

        set(option_names ${MEGASEARCH_${category}_OPTION_NAMES})

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