2016-01-10 11:20:52 +00:00
|
|
|
# ################################################################
|
2017-08-31 19:20:50 +00:00
|
|
|
# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
2016-05-29 00:02:24 +00:00
|
|
|
#
|
2017-08-31 19:20:50 +00: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 11:20:52 +00:00
|
|
|
# ################################################################
|
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
project(libzstd)
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00: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 08:48:10 +00:00
|
|
|
|
2018-12-23 01:31:59 +00: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 11:20:52 +00:00
|
|
|
|
|
|
|
# Define library directory, where sources and header files are located
|
2018-12-23 01:31:59 +00:00
|
|
|
include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2019-07-03 20:40:37 +00:00
|
|
|
file(GLOB CommonSources ${LIBRARY_DIR}/common/*.c)
|
|
|
|
file(GLOB CompressSources ${LIBRARY_DIR}/compress/*.c)
|
|
|
|
file(GLOB DecompressSources ${LIBRARY_DIR}/decompress/*.c)
|
|
|
|
file(GLOB DictBuilderSources ${LIBRARY_DIR}/dictBuilder/*.c)
|
|
|
|
file(GLOB DeprecatedSources ${LIBRARY_DIR}/deprecated/*.c)
|
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
set(Sources
|
2019-07-03 20:40:37 +00:00
|
|
|
${CommonSources}
|
|
|
|
${CompressSources}
|
|
|
|
${DecompressSources}
|
|
|
|
${DictBuilderSources}
|
|
|
|
${DeprecatedSources})
|
|
|
|
|
|
|
|
file(GLOB CommonHeaders ${LIBRARY_DIR}/common/*.h)
|
|
|
|
file(GLOB CompressHeaders ${LIBRARY_DIR}/compress/*.h)
|
|
|
|
file(GLOB DecompressHeaders ${LIBRARY_DIR}/decompress/*.h)
|
|
|
|
file(GLOB DictBuilderHeaders ${LIBRARY_DIR}/dictBuilder/*.h)
|
|
|
|
file(GLOB DeprecatedHeaders ${LIBRARY_DIR}/deprecated/*.h)
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
set(Headers
|
2016-12-06 03:28:19 +00:00
|
|
|
${LIBRARY_DIR}/zstd.h
|
2019-07-03 20:40:37 +00:00
|
|
|
${CommonHeaders}
|
|
|
|
${CompressHeaders}
|
|
|
|
${DecompressHeaders}
|
|
|
|
${DictBuilderHeaders}
|
|
|
|
${DeprecatedHeaders})
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_LEGACY_SUPPORT)
|
|
|
|
set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
|
|
|
|
include_directories(${LIBRARY_LEGACY_DIR})
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
set(Sources ${Sources}
|
2016-01-10 11:20:52 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v01.c
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v02.c
|
2016-02-12 02:50:05 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v03.c
|
2016-05-31 15:19:05 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v04.c
|
2016-06-09 16:12:06 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v05.c
|
2016-07-25 15:49:49 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v06.c
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v07.c)
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
set(Headers ${Headers}
|
2016-01-10 11:20:52 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_legacy.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v01.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v02.h
|
2016-02-12 02:50:05 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v03.h
|
2016-05-31 15:19:05 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v04.h
|
2016-06-09 16:12:06 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v05.h
|
2016-07-25 15:49:49 +00:00
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v06.h
|
|
|
|
${LIBRARY_LEGACY_DIR}/zstd_v07.h)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (MSVC)
|
|
|
|
set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/libzstd-dll)
|
|
|
|
set(PlatformDependResources ${MSVC_RESOURCE_DIR}/libzstd-dll.rc)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-05-31 15:19:05 +00:00
|
|
|
|
2016-01-10 11:20:52 +00:00
|
|
|
# Split project to static and shared libraries build
|
2018-12-23 01:31:59 +00: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-23 01:31:50 +00:00
|
|
|
endif ()
|
2018-12-23 01:31:59 +00: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-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
|
|
|
# Add specific compile definitions for MSVC project
|
2018-12-23 01:31:59 +00: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-23 01:31:50 +00:00
|
|
|
endif ()
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2017-05-24 08:48:10 +00:00
|
|
|
# With MSVC static library needs to be renamed to avoid conflict with import library
|
2018-12-23 01:31:59 +00:00
|
|
|
if (MSVC)
|
|
|
|
set(STATIC_LIBRARY_BASE_NAME zstd_static)
|
|
|
|
else ()
|
|
|
|
set(STATIC_LIBRARY_BASE_NAME zstd)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2016-12-06 21:45:42 +00:00
|
|
|
# Define static and shared library names
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_BUILD_SHARED)
|
|
|
|
set_target_properties(
|
2017-05-24 08:48:10 +00:00
|
|
|
libzstd_shared
|
|
|
|
PROPERTIES
|
|
|
|
OUTPUT_NAME zstd
|
2019-03-23 12:03:25 +00:00
|
|
|
VERSION ${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}
|
|
|
|
SOVERSION ${zstd_VERSION_MAJOR})
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_BUILD_STATIC)
|
|
|
|
set_target_properties(
|
2017-03-20 14:47:28 +00:00
|
|
|
libzstd_static
|
|
|
|
PROPERTIES
|
2019-12-06 16:14:33 +00:00
|
|
|
POSITION_INDEPENDENT_CODE On
|
2017-05-24 08:48:10 +00:00
|
|
|
OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME})
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2017-03-20 14:47:28 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (UNIX)
|
2017-04-19 17:25:29 +00:00
|
|
|
# pkg-config
|
2018-12-23 01:31:59 +00:00
|
|
|
set(PREFIX "${CMAKE_INSTALL_PREFIX}")
|
2020-02-26 18:52:49 +00:00
|
|
|
set(LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
|
2018-12-24 14:18:26 +00:00
|
|
|
set(VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}")
|
2018-12-23 01:31:59 +00:00
|
|
|
add_custom_target(libzstd.pc ALL
|
2017-04-19 17:25:29 +00:00
|
|
|
${CMAKE_COMMAND} -DIN="${LIBRARY_DIR}/libzstd.pc.in" -DOUT="libzstd.pc"
|
2020-02-26 18:52:49 +00:00
|
|
|
-DPREFIX="${PREFIX}" -DVERSION="${VERSION}"
|
2017-04-20 22:47:31 +00:00
|
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.cmake"
|
2017-04-19 17:25:29 +00:00
|
|
|
COMMENT "Creating pkg-config file")
|
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${LIBDIR}/pkgconfig")
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2017-05-24 08:48:10 +00:00
|
|
|
# install target
|
2018-12-23 01:31:59 +00:00
|
|
|
install(FILES
|
2019-12-06 16:14:33 +00:00
|
|
|
"${LIBRARY_DIR}/zstd.h"
|
|
|
|
"${LIBRARY_DIR}/deprecated/zbuff.h"
|
|
|
|
"${LIBRARY_DIR}/dictBuilder/zdict.h"
|
|
|
|
"${LIBRARY_DIR}/dictBuilder/cover.h"
|
|
|
|
"${LIBRARY_DIR}/common/zstd_errors.h"
|
2019-09-16 08:36:37 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
2017-05-24 08:48:10 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_BUILD_SHARED)
|
2019-12-06 16:14:33 +00:00
|
|
|
install(TARGETS libzstd_shared EXPORT zstdExports
|
|
|
|
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
2018-01-15 19:48:46 +00:00
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
2019-12-06 16:14:33 +00:00
|
|
|
)
|
2018-12-23 01:31:59 +00:00
|
|
|
endif()
|
|
|
|
if (ZSTD_BUILD_STATIC)
|
2019-12-06 16:14:33 +00:00
|
|
|
install(TARGETS libzstd_static EXPORT zstdExports
|
|
|
|
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
|
|
)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2017-05-24 08:48:10 +00:00
|
|
|
# uninstall target
|
2019-05-26 00:29:04 +00:00
|
|
|
if (NOT TARGET uninstall)
|
|
|
|
configure_file(
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
|
|
|
add_custom_target(uninstall
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
|
|
|
endif ()
|