2016-01-10 03:20:52 -08:00
|
|
|
# ################################################################
|
2017-08-31 12:20:50 -07:00
|
|
|
# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2017-08-31 12:20:50 -07:00
|
|
|
# This source code is licensed under both the BSD-style license (found in the
|
|
|
|
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
# in the COPYING file in the root directory of this source tree).
|
2016-01-10 03:20:52 -08:00
|
|
|
# ################################################################
|
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
project(libzstd)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
|
|
|
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
|
|
|
|
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" ON)
|
2017-05-24 01:48:10 -07:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if(NOT ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC)
|
|
|
|
message(SEND_ERROR "You need to build at least one flavor of libzstd")
|
|
|
|
endif()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# Define library directory, where sources and header files are located
|
2018-12-22 17:31:59 -08:00
|
|
|
include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
set(Sources
|
2016-05-13 02:27:56 -07:00
|
|
|
${LIBRARY_DIR}/common/entropy_common.c
|
2017-01-01 17:05:45 -08:00
|
|
|
${LIBRARY_DIR}/common/fse_decompress.c
|
|
|
|
${LIBRARY_DIR}/common/threading.c
|
|
|
|
${LIBRARY_DIR}/common/pool.c
|
2016-04-22 08:14:25 -07:00
|
|
|
${LIBRARY_DIR}/common/zstd_common.c
|
2016-10-12 10:23:53 -07:00
|
|
|
${LIBRARY_DIR}/common/error_private.c
|
2016-05-28 17:02:24 -07:00
|
|
|
${LIBRARY_DIR}/common/xxhash.c
|
2018-06-13 16:49:31 -07:00
|
|
|
${LIBRARY_DIR}/compress/hist.c
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/compress/fse_compress.c
|
|
|
|
${LIBRARY_DIR}/compress/huf_compress.c
|
|
|
|
${LIBRARY_DIR}/compress/zstd_compress.c
|
2017-01-01 17:05:45 -08:00
|
|
|
${LIBRARY_DIR}/compress/zstdmt_compress.c
|
2017-09-01 18:22:31 -07:00
|
|
|
${LIBRARY_DIR}/compress/zstd_fast.c
|
|
|
|
${LIBRARY_DIR}/compress/zstd_double_fast.c
|
|
|
|
${LIBRARY_DIR}/compress/zstd_lazy.c
|
|
|
|
${LIBRARY_DIR}/compress/zstd_opt.c
|
2017-09-06 17:56:01 -07:00
|
|
|
${LIBRARY_DIR}/compress/zstd_ldm.c
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/decompress/huf_decompress.c
|
|
|
|
${LIBRARY_DIR}/decompress/zstd_decompress.c
|
2018-10-25 16:28:41 -07:00
|
|
|
${LIBRARY_DIR}/decompress/zstd_decompress_block.c
|
2018-10-23 17:25:49 -07:00
|
|
|
${LIBRARY_DIR}/decompress/zstd_ddict.c
|
2016-12-31 21:08:12 -08:00
|
|
|
${LIBRARY_DIR}/dictBuilder/cover.c
|
2018-08-23 12:06:20 -07:00
|
|
|
${LIBRARY_DIR}/dictBuilder/fastcover.c
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/dictBuilder/divsufsort.c
|
2016-12-05 19:28:19 -08:00
|
|
|
${LIBRARY_DIR}/dictBuilder/zdict.c
|
2016-12-16 13:27:30 -08:00
|
|
|
${LIBRARY_DIR}/deprecated/zbuff_common.c
|
2016-12-05 19:28:19 -08:00
|
|
|
${LIBRARY_DIR}/deprecated/zbuff_compress.c
|
|
|
|
${LIBRARY_DIR}/deprecated/zbuff_decompress.c)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
set(Headers
|
2016-12-05 19:28:19 -08:00
|
|
|
${LIBRARY_DIR}/zstd.h
|
2018-06-14 16:48:40 -07:00
|
|
|
${LIBRARY_DIR}/common/debug.h
|
2017-01-27 12:29:27 -08:00
|
|
|
${LIBRARY_DIR}/common/pool.h
|
|
|
|
${LIBRARY_DIR}/common/threading.h
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/common/bitstream.h
|
|
|
|
${LIBRARY_DIR}/common/error_private.h
|
2016-10-12 10:23:53 -07:00
|
|
|
${LIBRARY_DIR}/common/zstd_errors.h
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/common/fse.h
|
|
|
|
${LIBRARY_DIR}/common/huf.h
|
|
|
|
${LIBRARY_DIR}/common/mem.h
|
|
|
|
${LIBRARY_DIR}/common/zstd_internal.h
|
2018-06-13 16:49:31 -07:00
|
|
|
${LIBRARY_DIR}/compress/hist.h
|
2017-11-10 09:39:11 -08:00
|
|
|
${LIBRARY_DIR}/compress/zstd_compress_internal.h
|
2017-09-01 18:22:31 -07:00
|
|
|
${LIBRARY_DIR}/compress/zstd_fast.h
|
|
|
|
${LIBRARY_DIR}/compress/zstd_double_fast.h
|
|
|
|
${LIBRARY_DIR}/compress/zstd_lazy.h
|
|
|
|
${LIBRARY_DIR}/compress/zstd_opt.h
|
2017-09-06 17:56:01 -07:00
|
|
|
${LIBRARY_DIR}/compress/zstd_ldm.h
|
2017-01-27 10:27:29 -08:00
|
|
|
${LIBRARY_DIR}/compress/zstdmt_compress.h
|
2018-10-23 17:25:49 -07:00
|
|
|
${LIBRARY_DIR}/decompress/zstd_decompress_internal.h
|
2018-10-25 16:28:41 -07:00
|
|
|
${LIBRARY_DIR}/decompress/zstd_decompress_block.h
|
|
|
|
${LIBRARY_DIR}/decompress/zstd_ddict.h
|
2016-12-05 19:28:19 -08:00
|
|
|
${LIBRARY_DIR}/dictBuilder/zdict.h
|
2018-08-23 12:06:20 -07:00
|
|
|
${LIBRARY_DIR}/dictBuilder/cover.h
|
2016-12-05 19:28:19 -08:00
|
|
|
${LIBRARY_DIR}/deprecated/zbuff.h)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_LEGACY_SUPPORT)
|
|
|
|
set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
|
|
|
|
include_directories(${LIBRARY_LEGACY_DIR})
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
set(Sources ${Sources}
|
2016-01-10 03:20:52 -08:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v01.c
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v02.c
|
2016-02-11 18:50:05 -08:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v03.c
|
2016-05-31 08:19:05 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v04.c
|
2016-06-09 09:12:06 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v05.c
|
2016-07-25 08:49:49 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v06.c
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v07.c)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
set(Headers ${Headers}
|
2016-01-10 03:20:52 -08:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_legacy.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v01.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v02.h
|
2016-02-11 18:50:05 -08:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v03.h
|
2016-05-31 08:19:05 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v04.h
|
2016-06-09 09:12:06 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v05.h
|
2016-07-25 08:49:49 -07:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v06.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v07.h)
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if (MSVC)
|
|
|
|
set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/libzstd-dll)
|
|
|
|
set(PlatformDependResources ${MSVC_RESOURCE_DIR}/libzstd-dll.rc)
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-05-31 08:19:05 -07:00
|
|
|
|
2016-01-10 03:20:52 -08:00
|
|
|
# Split project to static and shared libraries build
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_SHARED)
|
|
|
|
add_library(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources})
|
|
|
|
if (ZSTD_MULTITHREAD_SUPPORT)
|
|
|
|
set_property(TARGET libzstd_shared APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
|
|
|
|
if (UNIX)
|
|
|
|
target_link_libraries(libzstd_shared ${THREADS_LIBS})
|
|
|
|
endif ()
|
|
|
|
endif()
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
add_library(libzstd_static STATIC ${Sources} ${Headers})
|
|
|
|
if (ZSTD_MULTITHREAD_SUPPORT)
|
|
|
|
set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
|
|
|
|
if (UNIX)
|
|
|
|
target_link_libraries(libzstd_static ${THREADS_LIBS})
|
|
|
|
endif ()
|
|
|
|
endif ()
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# Add specific compile definitions for MSVC project
|
2018-12-22 17:31:59 -08:00
|
|
|
if (MSVC)
|
|
|
|
if (ZSTD_BUILD_SHARED)
|
|
|
|
set_property(TARGET libzstd_shared APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_DLL_EXPORT=1;ZSTD_HEAPMODE=0;_CONSOLE;_CRT_SECURE_NO_WARNINGS")
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2017-05-24 01:48:10 -07:00
|
|
|
# With MSVC static library needs to be renamed to avoid conflict with import library
|
2018-12-22 17:31:59 -08:00
|
|
|
if (MSVC)
|
|
|
|
set(STATIC_LIBRARY_BASE_NAME zstd_static)
|
|
|
|
else ()
|
|
|
|
set(STATIC_LIBRARY_BASE_NAME zstd)
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2016-12-06 13:45:42 -08:00
|
|
|
# Define static and shared library names
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_SHARED)
|
|
|
|
set_target_properties(
|
2017-05-24 01:48:10 -07:00
|
|
|
libzstd_shared
|
|
|
|
PROPERTIES
|
|
|
|
OUTPUT_NAME zstd
|
2019-03-23 05:03:25 -07:00
|
|
|
VERSION ${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}
|
|
|
|
SOVERSION ${zstd_VERSION_MAJOR})
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
set_target_properties(
|
2017-03-20 07:47:28 -07:00
|
|
|
libzstd_static
|
|
|
|
PROPERTIES
|
2017-05-24 01:48:10 -07:00
|
|
|
OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME})
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2017-03-20 07:47:28 -07:00
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if (UNIX)
|
2017-04-19 10:25:29 -07:00
|
|
|
# pkg-config
|
2018-12-22 17:31:59 -08:00
|
|
|
set(PREFIX "${CMAKE_INSTALL_PREFIX}")
|
|
|
|
set(LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
|
|
|
|
set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
|
2018-12-24 06:18:26 -08:00
|
|
|
set(VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}")
|
2018-12-22 17:31:59 -08:00
|
|
|
add_custom_target(libzstd.pc ALL
|
2017-04-19 10:25:29 -07:00
|
|
|
${CMAKE_COMMAND} -DIN="${LIBRARY_DIR}/libzstd.pc.in" -DOUT="libzstd.pc"
|
|
|
|
-DPREFIX="${PREFIX}" -DLIBDIR="${LIBDIR}" -DINCLUDEDIR="${INCLUDEDIR}" -DVERSION="${VERSION}"
|
2017-04-20 15:47:31 -07:00
|
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.cmake"
|
2017-04-19 10:25:29 -07:00
|
|
|
COMMENT "Creating pkg-config file")
|
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${LIBDIR}/pkgconfig")
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2017-05-24 01:48:10 -07:00
|
|
|
# install target
|
2018-12-22 17:31:59 -08:00
|
|
|
install(FILES
|
2017-08-31 12:20:50 -07:00
|
|
|
${LIBRARY_DIR}/zstd.h
|
|
|
|
${LIBRARY_DIR}/deprecated/zbuff.h
|
|
|
|
${LIBRARY_DIR}/dictBuilder/zdict.h
|
2018-08-23 12:06:20 -07:00
|
|
|
${LIBRARY_DIR}/dictBuilder/cover.h
|
2017-05-24 01:48:10 -07:00
|
|
|
${LIBRARY_DIR}/common/zstd_errors.h
|
|
|
|
DESTINATION "include")
|
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
if (ZSTD_BUILD_SHARED)
|
|
|
|
install(TARGETS libzstd_shared RUNTIME DESTINATION "bin"
|
2018-01-15 11:48:46 -08:00
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
2018-12-22 17:31:59 -08:00
|
|
|
endif()
|
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
install(TARGETS libzstd_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
2018-12-22 17:31:50 -08:00
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
2017-05-24 01:48:10 -07:00
|
|
|
# uninstall target
|
2018-12-22 17:31:59 -08:00
|
|
|
configure_file(
|
2017-05-24 01:48:10 -07:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
add_custom_target(uninstall
|
2017-05-24 01:48:10 -07:00
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|