if(GLIBC_VERSION_MAX AND GLIBC_VERSION_MAX VERSION_LESS "2.8")
    list(APPEND PATCH_FILES no_qsort_r.patch)
endif()

list(APPEND CMAKE_ARGS
    -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
    # Project options.
    -DZSTD_BUILD_PROGRAMS=FALSE
    -DZSTD_BUILD_SHARED=$<NOT:$<BOOL:${MONOLIBTIC}>>
    -DZSTD_BUILD_STATIC=$<BOOL:${MONOLIBTIC}>
    -DZSTD_LEGACY_SUPPORT=FALSE
    -DZSTD_MULTITHREAD_SUPPORT=FALSE
)

list(APPEND BUILD_CMD COMMAND ninja)

list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} --install .)

if(NOT MONOLIBTIC)
    append_shared_lib_install_commands(INSTALL_CMD zstd VERSION 1)
endif()

external_project(
    DOWNLOAD URL 780fc1896922b1bc52a4e90980cdda48
    https://github.com/facebook/zstd/releases/download/v1.5.7/zstd-1.5.7.tar.gz
    PATCH_FILES ${PATCH_FILES}
    SOURCE_SUBDIR build/cmake
    CMAKE_ARGS ${CMAKE_ARGS}
    BUILD_COMMAND ${BUILD_CMD}
    INSTALL_COMMAND ${INSTALL_CMD}
)
