2016-01-07 10:37:00 +00:00
|
|
|
# ################################################################
|
2016-09-03 05:11:49 +00:00
|
|
|
# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
2016-01-07 10:37:00 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
2017-08-31 18:24:54 +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-07 10:37:00 +00:00
|
|
|
# ################################################################
|
2016-01-10 11:20:52 +00:00
|
|
|
|
2018-12-24 14:18:26 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.9 FATAL_ERROR)
|
|
|
|
|
|
|
|
# As of 2018-12-26 ZSTD has been validated to build with cmake version 3.13.2 new policies.
|
|
|
|
# Set and use the newest cmake policies that are validated to work
|
|
|
|
set(ZSTD_MAX_VALIDATED_CMAKE_VERSION "3.13.2")
|
|
|
|
if("${CMAKE_MAJOR_VERSION}" LESS 3) # Cmake version 2 does not understand the VERSION_LESS_EQUAL operator
|
|
|
|
set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
|
|
|
|
else()
|
|
|
|
if("${CMAKE_VERSION}" VERSION_LESS_EQUAL "${ZSTD_MAX_VALIDATED_CMAKE_VERSION}")
|
|
|
|
set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
|
|
|
|
else()
|
|
|
|
set(ZSTD_CMAKE_POLICY_VERSION "${ZSTD_MAX_VALIDATED_CMAKE_VERSION}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
cmake_policy(VERSION ${ZSTD_CMAKE_POLICY_VERSION})
|
2018-11-06 20:24:29 +00:00
|
|
|
|
2018-12-24 14:18:26 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
2018-12-23 01:31:59 +00:00
|
|
|
set(ZSTD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
|
2018-12-24 14:18:26 +00:00
|
|
|
set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
|
|
|
|
# Parse version
|
|
|
|
include(GetZstdLibraryVersion)
|
|
|
|
GetZstdLibraryVersion(${LIBRARY_DIR}/zstd.h zstd_VERSION_MAJOR zstd_VERSION_MINOR zstd_VERSION_PATCH)
|
|
|
|
|
|
|
|
if( CMAKE_MAJOR_VERSION LESS 3 )
|
|
|
|
## Provide cmake 3+ behavior for older versions of cmake
|
|
|
|
project(zstd)
|
|
|
|
set(PROJECT_VERSION_MAJOR ${zstd_VERSION_MAJOR})
|
|
|
|
set(PROJECT_VERSION_MINOR ${zstd_VERSION_MINOR})
|
|
|
|
set(PROJECT_VERSION_PATCH ${zstd_VERSION_PATCH})
|
|
|
|
set(PROJECT_VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}")
|
|
|
|
enable_language(C) # Main library is in C
|
|
|
|
enable_language(CXX) # Testing contributed code also utilizes CXX
|
|
|
|
else()
|
|
|
|
project(zstd
|
|
|
|
VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}"
|
|
|
|
LANGUAGES C # Main library is in C
|
|
|
|
CXX # Testing contributed code also utilizes CXX
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
message(STATUS "ZSTD VERSION: ${zstd_VERSION}")
|
|
|
|
set(zstd_HOMEPAGE_URL "http://www.zstd.net")
|
|
|
|
set(zstd_DESCRIPTION "Zstandard is a real-time compression algorithm, providing high compression ratios.")
|
2018-08-14 00:28:52 +00:00
|
|
|
|
2018-12-24 14:48:04 +00:00
|
|
|
# Set a default build type if none was specified
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
|
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
|
|
|
# Set the possible values of build type for cmake-gui
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
2018-11-06 20:24:29 +00:00
|
|
|
endif()
|
2018-08-14 00:28:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
include(GNUInstallDirs)
|
2016-01-07 10:37:00 +00:00
|
|
|
|
2017-03-17 14:36:37 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Add extra compilation flags
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-12-23 01:31:59 +00:00
|
|
|
include(AddZstdCompilationFlags)
|
2017-04-20 22:46:44 +00:00
|
|
|
ADD_ZSTD_COMPILATION_FLAGS()
|
2017-03-17 14:36:37 +00:00
|
|
|
|
2017-05-24 08:48:10 +00:00
|
|
|
# Always hide XXHash symbols
|
2018-12-23 01:31:59 +00:00
|
|
|
add_definitions(-DXXH_NAMESPACE=ZSTD_)
|
2017-05-24 08:48:10 +00:00
|
|
|
|
2018-01-15 19:48:46 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Installation variables
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-12-23 01:31:59 +00:00
|
|
|
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
|
|
|
|
message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}")
|
2018-01-15 19:48:46 +00:00
|
|
|
|
2017-03-17 14:36:37 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Options
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-01-17 07:27:52 +00:00
|
|
|
|
|
|
|
# Legacy support
|
2018-12-23 01:31:59 +00:00
|
|
|
option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
|
2016-01-07 10:37:00 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_LEGACY_SUPPORT)
|
|
|
|
message(STATUS "ZSTD_LEGACY_SUPPORT defined!")
|
2018-12-26 19:17:31 +00:00
|
|
|
add_definitions(-DZSTD_LEGACY_SUPPORT=5)
|
2018-12-23 01:31:50 +00:00
|
|
|
else ()
|
2018-12-23 01:31:59 +00:00
|
|
|
message(STATUS "ZSTD_LEGACY_SUPPORT not defined!")
|
|
|
|
add_definitions(-DZSTD_LEGACY_SUPPORT=0)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-07 10:37:00 +00:00
|
|
|
|
2018-01-17 07:27:52 +00:00
|
|
|
# Multi-threading support
|
2018-12-23 01:31:59 +00:00
|
|
|
option(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" ON)
|
2018-01-17 07:27:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_MULTITHREAD_SUPPORT)
|
|
|
|
message(STATUS "ZSTD_MULTITHREAD_SUPPORT is enabled")
|
2018-12-23 01:31:50 +00:00
|
|
|
else ()
|
2018-12-23 01:31:59 +00:00
|
|
|
message(STATUS "ZSTD_MULTITHREAD_SUPPORT is disabled")
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2018-01-17 07:27:52 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" ON)
|
|
|
|
option(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF)
|
|
|
|
option(ZSTD_BUILD_TESTS "BUILD TESTS" OFF)
|
2018-01-17 07:27:52 +00:00
|
|
|
if (MSVC)
|
2018-12-23 01:31:59 +00:00
|
|
|
option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF)
|
2018-01-17 07:27:52 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# External dependencies
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_MULTITHREAD_SUPPORT AND UNIX)
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
if(CMAKE_USE_PTHREADS_INIT)
|
|
|
|
set(THREADS_LIBS "${CMAKE_THREAD_LIBS_INIT}")
|
|
|
|
else()
|
|
|
|
message(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads")
|
|
|
|
endif()
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2018-01-17 07:27:52 +00:00
|
|
|
|
2017-03-17 14:36:37 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Add source directories
|
|
|
|
#-----------------------------------------------------------------------------
|
2018-12-23 01:31:59 +00:00
|
|
|
add_subdirectory(lib)
|
2017-03-20 14:47:28 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
if (ZSTD_BUILD_PROGRAMS)
|
|
|
|
if (NOT ZSTD_BUILD_STATIC)
|
|
|
|
message(SEND_ERROR "You need to build static library to build zstd CLI")
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2017-05-24 08:48:10 +00:00
|
|
|
|
2018-12-23 01:31:59 +00:00
|
|
|
add_subdirectory(programs)
|
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 (ZSTD_BUILD_TESTS)
|
|
|
|
if (NOT ZSTD_BUILD_STATIC)
|
|
|
|
message(SEND_ERROR "You need to build static library to build tests")
|
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
|
|
|
add_subdirectory(tests)
|
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 (ZSTD_BUILD_CONTRIB)
|
|
|
|
add_subdirectory(contrib)
|
2018-12-23 01:31:50 +00:00
|
|
|
endif ()
|
2016-01-07 10:37:00 +00:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
2017-03-17 14:36:37 +00:00
|
|
|
# Add clean-all target
|
2016-01-07 10:37:00 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
2018-12-23 01:31:59 +00:00
|
|
|
add_custom_target(clean-all
|
2016-06-03 08:24:00 +00:00
|
|
|
COMMAND ${CMAKE_BUILD_TOOL} clean
|
|
|
|
COMMAND rm -rf ${CMAKE_BINARY_DIR}/
|
|
|
|
)
|