2016-01-10 03:20:52 -08:00
|
|
|
# ################################################################
|
|
|
|
# zstd - Makefile
|
2016-02-11 18:50:05 -08:00
|
|
|
# Copyright (C) Yann Collet 2014-2016
|
2016-01-10 03:20:52 -08:00
|
|
|
# All rights reserved.
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2016-01-10 03:20:52 -08:00
|
|
|
# BSD license
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
# are permitted provided that the following conditions are met:
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2016-01-10 03:20:52 -08:00
|
|
|
# * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
# list of conditions and the following disclaimer.
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2016-01-10 03:20:52 -08:00
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
# list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
# other materials provided with the distribution.
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2016-01-10 03:20:52 -08:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2016-05-28 17:02:24 -07:00
|
|
|
#
|
2016-01-10 03:20:52 -08:00
|
|
|
# You can contact the author at :
|
2016-02-11 18:50:05 -08:00
|
|
|
# - zstd homepage : http://www.zstd.net/
|
2016-01-10 03:20:52 -08:00
|
|
|
# ################################################################
|
|
|
|
|
|
|
|
# Get library version based on information from input content (use regular exp)
|
|
|
|
function(GetLibraryVersion _content _outputVar1 _outputVar2 _outputVar3)
|
|
|
|
string(REGEX MATCHALL ".*define ZSTD_VERSION_MAJOR+.* ([0-9]+).*define ZSTD_VERSION_MINOR+.* ([0-9]+).*define ZSTD_VERSION_RELEASE+.* ([0-9]+)" VERSION_REGEX "${_content}")
|
|
|
|
SET(${_outputVar1} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
|
|
|
SET(${_outputVar2} ${CMAKE_MATCH_2} PARENT_SCOPE)
|
|
|
|
SET(${_outputVar3} ${CMAKE_MATCH_3} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
PROJECT(libzstd)
|
|
|
|
|
|
|
|
SET(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
|
|
|
|
|
|
|
# Define project root directory
|
|
|
|
SET(ROOT_DIR ../../..)
|
|
|
|
|
|
|
|
# Define library directory, where sources and header files are located
|
|
|
|
SET(LIBRARY_DIR ${ROOT_DIR}/lib)
|
2016-07-17 18:41:59 -07:00
|
|
|
INCLUDE_DIRECTORIES(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# Read file content
|
2016-07-17 18:41:59 -07:00
|
|
|
FILE(READ ${LIBRARY_DIR}/zstd.h HEADER_CONTENT)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# Parse version
|
|
|
|
GetLibraryVersion("${HEADER_CONTENT}" LIBVER_MAJOR LIBVER_MINOR LIBVER_RELEASE)
|
|
|
|
MESSAGE("ZSTD VERSION ${LIBVER_MAJOR}.${LIBVER_MINOR}.${LIBVER_RELEASE}")
|
|
|
|
|
|
|
|
SET(Sources
|
2016-05-13 02:27:56 -07:00
|
|
|
${LIBRARY_DIR}/common/entropy_common.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
|
2016-05-09 07:19:25 -07:00
|
|
|
${LIBRARY_DIR}/common/fse_decompress.c
|
2016-04-22 04:59:21 -07:00
|
|
|
${LIBRARY_DIR}/compress/fse_compress.c
|
|
|
|
${LIBRARY_DIR}/compress/huf_compress.c
|
|
|
|
${LIBRARY_DIR}/compress/zbuff_compress.c
|
|
|
|
${LIBRARY_DIR}/compress/zstd_compress.c
|
|
|
|
${LIBRARY_DIR}/decompress/huf_decompress.c
|
|
|
|
${LIBRARY_DIR}/decompress/zbuff_decompress.c
|
|
|
|
${LIBRARY_DIR}/decompress/zstd_decompress.c
|
|
|
|
${LIBRARY_DIR}/dictBuilder/divsufsort.c
|
|
|
|
${LIBRARY_DIR}/dictBuilder/zdict.c)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
SET(Headers
|
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/zbuff.h
|
|
|
|
${LIBRARY_DIR}/common/zstd_internal.h
|
2016-07-17 18:41:59 -07:00
|
|
|
${LIBRARY_DIR}/zstd.h
|
2016-06-04 12:59:56 -07:00
|
|
|
${LIBRARY_DIR}/dictBuilder/zdict.h)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
IF (ZSTD_LEGACY_SUPPORT)
|
|
|
|
SET(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
|
|
|
|
INCLUDE_DIRECTORIES(${LIBRARY_LEGACY_DIR})
|
|
|
|
|
|
|
|
SET(Sources ${Sources}
|
|
|
|
${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
|
|
|
|
|
|
|
SET(Headers ${Headers}
|
|
|
|
${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)
|
2016-01-10 03:20:52 -08:00
|
|
|
ENDIF (ZSTD_LEGACY_SUPPORT)
|
|
|
|
|
2016-05-31 08:19:05 -07:00
|
|
|
IF (MSVC)
|
2016-09-19 06:08:43 -07:00
|
|
|
SET(MSVC_RESOURCE_DIR ${ROOT_DIR}/build/VS2010/zstdlib)
|
2016-05-31 08:19:05 -07:00
|
|
|
SET(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstdlib.rc)
|
|
|
|
ENDIF (MSVC)
|
|
|
|
|
2016-01-10 03:20:52 -08:00
|
|
|
# Split project to static and shared libraries build
|
|
|
|
ADD_LIBRARY(libzstd_static STATIC ${Sources} ${Headers} ${PlatformDependResources})
|
|
|
|
ADD_LIBRARY(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources})
|
|
|
|
|
|
|
|
# Add specific compile definitions for MSVC project
|
|
|
|
IF (MSVC)
|
|
|
|
SET_TARGET_PROPERTIES(libzstd_static PROPERTIES COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
|
|
|
|
SET_TARGET_PROPERTIES(libzstd_shared PROPERTIES COMPILE_DEFINITIONS "ZSTD_DLL_EXPORT=1;ZSTD_HEAPMODE=0;_CONSOLE;_CRT_SECURE_NO_WARNINGS")
|
|
|
|
ENDIF (MSVC)
|
|
|
|
|
|
|
|
# Define library base name
|
2016-05-31 04:39:36 -07:00
|
|
|
IF (MSVC)
|
2016-01-10 03:20:52 -08:00
|
|
|
SET(LIBRARY_BASE_NAME zstdlib)
|
|
|
|
ELSE ()
|
2016-05-31 04:39:36 -07:00
|
|
|
SET(LIBRARY_BASE_NAME libzstd)
|
|
|
|
ENDIF (MSVC)
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# Define static and shared library names
|
|
|
|
SET(STATIC_LIBRARY_OUTPUT_NAME ${LIBRARY_BASE_NAME})
|
|
|
|
SET(SHARED_LIBRARY_OUTPUT_NAME ${LIBRARY_BASE_NAME}.${LIBVER_MAJOR}.${LIBVER_MINOR}.${LIBVER_RELEASE})
|
|
|
|
|
|
|
|
IF (MSVC)
|
|
|
|
IF (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
|
|
|
SET(STATIC_LIBRARY_OUTPUT_NAME ${STATIC_LIBRARY_OUTPUT_NAME}_x64)
|
|
|
|
SET(SHARED_LIBRARY_OUTPUT_NAME ${SHARED_LIBRARY_OUTPUT_NAME}_x64)
|
|
|
|
ELSE ()
|
|
|
|
SET(STATIC_LIBRARY_OUTPUT_NAME ${STATIC_LIBRARY_OUTPUT_NAME}_x86)
|
|
|
|
SET(SHARED_LIBRARY_OUTPUT_NAME ${SHARED_LIBRARY_OUTPUT_NAME}_x86)
|
|
|
|
ENDIF (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
|
|
|
ENDIF (MSVC)
|
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(
|
|
|
|
libzstd_static
|
|
|
|
PROPERTIES
|
|
|
|
PREFIX ""
|
|
|
|
OUTPUT_NAME ${STATIC_LIBRARY_OUTPUT_NAME})
|
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(
|
|
|
|
libzstd_shared
|
|
|
|
PROPERTIES
|
|
|
|
PREFIX ""
|
|
|
|
OUTPUT_NAME ${SHARED_LIBRARY_OUTPUT_NAME})
|
|
|
|
|
|
|
|
IF (UNIX)
|
2016-06-03 02:40:15 -07:00
|
|
|
IF ("${PREFIX}" STREQUAL "")
|
|
|
|
SET(PREFIX /usr/local)
|
|
|
|
ENDIF()
|
|
|
|
MESSAGE("the variable PREFIX=${PREFIX}")
|
2016-01-10 03:20:52 -08:00
|
|
|
SET(INSTALL_LIBRARY_DIR ${PREFIX}/lib)
|
|
|
|
SET(INSTALL_INCLUDE_DIR ${PREFIX}/include)
|
|
|
|
|
|
|
|
# install target
|
2016-07-17 18:41:59 -07:00
|
|
|
INSTALL(FILES ${LIBRARY_DIR}/zstd.h ${LIBRARY_DIR}/common/zbuff.h ${LIBRARY_DIR}/dictBuilder/zdict.h DESTINATION ${INSTALL_INCLUDE_DIR})
|
2016-01-10 03:20:52 -08:00
|
|
|
INSTALL(TARGETS libzstd_static DESTINATION ${INSTALL_LIBRARY_DIR})
|
|
|
|
INSTALL(TARGETS libzstd_shared LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR})
|
|
|
|
|
|
|
|
# Create symlinks and setup this files
|
|
|
|
SET(SHARED_LIBRARY_LINK ${SHARED_LIBRARY_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
|
|
SET(SHARED_LIBRARY_SYMLINK1 ${LIBRARY_BASE_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
|
|
|
|
SET(SHARED_LIBRARY_SYMLINK2 ${LIBRARY_BASE_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}.${LIBVER_MAJOR})
|
|
|
|
|
|
|
|
SET(SHARED_LIBRARY_LINK_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SHARED_LIBRARY_LINK})
|
|
|
|
SET(SHARED_LIBRARY_SYMLINK1_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SHARED_LIBRARY_SYMLINK1})
|
|
|
|
SET(SHARED_LIBRARY_SYMLINK2_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SHARED_LIBRARY_SYMLINK2})
|
|
|
|
|
|
|
|
if (EXISTS ${SHARED_LIBRARY_SYMLINK1_PATH})
|
|
|
|
FILE(REMOVE ${SHARED_LIBRARY_SYMLINK1_PATH})
|
|
|
|
endif (EXISTS ${SHARED_LIBRARY_SYMLINK1_PATH})
|
|
|
|
|
|
|
|
if (EXISTS ${SHARED_LIBRARY_SYMLINK2_PATH})
|
|
|
|
FILE(REMOVE ${SHARED_LIBRARY_SYMLINK2_PATH})
|
|
|
|
endif (EXISTS ${SHARED_LIBRARY_SYMLINK2_PATH})
|
|
|
|
|
|
|
|
ADD_CUSTOM_COMMAND(TARGET libzstd_shared POST_BUILD
|
|
|
|
COMMAND ln -s ${SHARED_LIBRARY_LINK} ${SHARED_LIBRARY_SYMLINK1}
|
|
|
|
DEPENDS ${SHARED_LIBRARY_LINK_PATH}
|
|
|
|
COMMENT "Generating symbolic link")
|
|
|
|
|
|
|
|
ADD_CUSTOM_COMMAND(TARGET libzstd_shared POST_BUILD
|
|
|
|
COMMAND ln -s ${SHARED_LIBRARY_LINK} ${SHARED_LIBRARY_SYMLINK2}
|
|
|
|
DEPENDS ${SHARED_LIBRARY_LINK_PATH}
|
|
|
|
COMMENT "Generating symbolic link")
|
|
|
|
|
|
|
|
INSTALL(FILES ${SHARED_LIBRARY_SYMLINK1_PATH} DESTINATION ${INSTALL_LIBRARY_DIR})
|
|
|
|
INSTALL(FILES ${SHARED_LIBRARY_SYMLINK2_PATH} DESTINATION ${INSTALL_LIBRARY_DIR})
|
|
|
|
|
|
|
|
# uninstall target
|
|
|
|
CONFIGURE_FILE(
|
|
|
|
"${CMAKE_SOURCE_DIR}/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
|
|
|
|
IMMEDIATE @ONLY)
|
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET(uninstall
|
|
|
|
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)
|
2016-01-09 22:30:16 -08:00
|
|
|
ENDIF (UNIX)
|