Skip to content

Commit

Permalink
Add USE_SYSTEM_ZSTD cmake flag to use system provided zstd #411
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Feb 12, 2021
1 parent bbd5641 commit 877344c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
43 changes: 26 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(HAVE_POWER9 0 CACHE BOOL "Have POWER9 CPU")
set(HAVE_POWER8 0 CACHE BOOL "Have POWER8 CPU")
set(HAVE_ARM8 0 CACHE BOOL "Have ARMv8 CPU")
set(NATIVE_ARCH 1 CACHE BOOL "Assume native architecture for SIMD. Use one of the HAVE_* options or set CMAKE_CXX_FLAGS to the appropriate flags if you disable this.")
set(USE_SYSTEM_ZSTD 0 CACHE BOOL "Use zstd provided by system instead of bundled version")

if (HAVE_SANITIZER)
include(FindUBSan)
Expand Down Expand Up @@ -167,23 +168,31 @@ if (CMAKE_COMPILER_IS_CLANG AND (NOT EMSCRIPTEN))
set(MMSEQS_CXX_FLAGS "${MMSEQS_CXX_FLAGS} -stdlib=libc++")
endif ()


# zstd
# We use ZSTD_findDecompressedSize which is only available with ZSTD_STATIC_LINKING_ONLY
# Thus we cannot use a system provided libzstd
set(ZSTD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/zstd")
set(CMAKE_INSTALL_LIBDIR bin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/lib/zstd/build/cmake/CMakeModules")
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
option(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" OFF)
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
option(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF)
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
include_directories(lib/zstd/lib)
add_subdirectory(lib/zstd/build/cmake/lib EXCLUDE_FROM_ALL)
set_target_properties(libzstd_static PROPERTIES COMPILE_FLAGS "${MMSEQS_C_FLAGS}" LINK_FLAGS "${MMSEQS_C_FLAGS}")
if (USE_SYSTEM_ZSTD)
include(FindPackageHandleStandardArgs)
find_path(ZSTD_INCLUDE_DIRS NAMES zstd.h REQUIRED)
# We use ZSTD_findDecompressedSize which is only available with ZSTD_STATIC_LINKING_ONLY
find_library(ZSTD_LIBRARIES NAMES libzstd.a libzstd_static REQUIRED)
find_package_handle_standard_args(ZSTD DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS)
mark_as_advanced(ZSTD_LIBRARIES ZSTD_INCLUDE_DIRS)
include_directories(${ZSTD_INCLUDE_DIRS})
else ()
# We use ZSTD_findDecompressedSize which is only available with ZSTD_STATIC_LINKING_ONLY
set(ZSTD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib/zstd")
set(CMAKE_INSTALL_LIBDIR bin)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/lib/zstd/build/cmake/CMakeModules")
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
option(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" OFF)
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
option(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF)
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
include_directories(lib/zstd/lib)
add_subdirectory(lib/zstd/build/cmake/lib EXCLUDE_FROM_ALL)
set_target_properties(libzstd_static PROPERTIES COMPILE_FLAGS "${MMSEQS_C_FLAGS}" LINK_FLAGS "${MMSEQS_C_FLAGS}")
set(ZSTD_LIBRARIES libzstd_static)
endif()

# tinyexpr
include_directories(lib/tinyexpr)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ else ()
message("-- OMPTL sorting fallback")
endif ()

target_link_libraries(mmseqs-framework tinyexpr libzstd_static microtar)
target_link_libraries(mmseqs-framework tinyexpr ${ZSTD_LIBRARIES} microtar)
if (CYGWIN)
target_link_libraries(mmseqs-framework nedmalloc)
endif ()
Expand Down

0 comments on commit 877344c

Please sign in to comment.