summaryrefslogtreecommitdiffstats
path: root/src/zstd/build/cmake
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/zstd/build/cmake/.gitignore10
-rw-r--r--src/zstd/build/cmake/CMakeLists.txt203
-rw-r--r--src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake79
-rw-r--r--src/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake49
-rw-r--r--src/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake10
-rw-r--r--src/zstd/build/cmake/README.md104
-rw-r--r--src/zstd/build/cmake/contrib/CMakeLists.txt13
-rw-r--r--src/zstd/build/cmake/contrib/gen_html/CMakeLists.txt30
-rw-r--r--src/zstd/build/cmake/contrib/pzstd/CMakeLists.txt32
-rw-r--r--src/zstd/build/cmake/lib/.gitignore2
-rw-r--r--src/zstd/build/cmake/lib/CMakeLists.txt177
-rw-r--r--src/zstd/build/cmake/lib/cmake_uninstall.cmake.in22
-rw-r--r--src/zstd/build/cmake/lib/pkgconfig.cmake1
-rw-r--r--src/zstd/build/cmake/programs/.gitignore5
-rw-r--r--src/zstd/build/cmake/programs/CMakeLists.txt135
-rw-r--r--src/zstd/build/cmake/tests/.gitignore7
-rw-r--r--src/zstd/build/cmake/tests/CMakeLists.txt106
-rw-r--r--src/zstd/build/cmake/zstdConfig.cmake1
18 files changed, 986 insertions, 0 deletions
diff --git a/src/zstd/build/cmake/.gitignore b/src/zstd/build/cmake/.gitignore
new file mode 100644
index 000000000..2e51e8954
--- /dev/null
+++ b/src/zstd/build/cmake/.gitignore
@@ -0,0 +1,10 @@
+# cmake working directory
+cmakeBuild
+
+# cmake artefacts
+CMakeCache.txt
+CMakeFiles
+Makefile
+cmake_install.cmake
+cmake_uninstall.cmake
+*.1
diff --git a/src/zstd/build/cmake/CMakeLists.txt b/src/zstd/build/cmake/CMakeLists.txt
new file mode 100644
index 000000000..9b5d7efb8
--- /dev/null
+++ b/src/zstd/build/cmake/CMakeLists.txt
@@ -0,0 +1,203 @@
+# ################################################################
+# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+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_MAJOR_VERSION "3")
+set(ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION "13") #Policies never changed at PATCH level
+if("${CMAKE_MAJOR_VERSION}" LESS 3)
+ set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
+elseif( "${ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION}" EQUAL "${CMAKE_MAJOR_VERSION}" AND
+ "${ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION}" GREATER "${CMAKE_MINOR_VERSION}")
+ set(ZSTD_CMAKE_POLICY_VERSION "${CMAKE_VERSION}")
+else()
+ set(ZSTD_CMAKE_POLICY_VERSION "${ZSTD_MAX_VALIDATED_CMAKE_MAJOR_VERSION}.${ZSTD_MAX_VALIDATED_CMAKE_MINOR_VERSION}.0")
+endif()
+cmake_policy(VERSION ${ZSTD_CMAKE_POLICY_VERSION})
+
+set(CMAKE_BUILD_WITH_INSTALL_RPATH on)
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
+set(ZSTD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
+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.")
+
+# 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")
+endif()
+
+include(GNUInstallDirs)
+
+#-----------------------------------------------------------------------------
+# Add extra compilation flags
+#-----------------------------------------------------------------------------
+include(AddZstdCompilationFlags)
+ADD_ZSTD_COMPILATION_FLAGS()
+
+# Always hide XXHash symbols
+add_definitions(-DXXH_NAMESPACE=ZSTD_)
+
+#-----------------------------------------------------------------------------
+# Installation variables
+#-----------------------------------------------------------------------------
+message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
+message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}")
+
+#-----------------------------------------------------------------------------
+# Options
+#-----------------------------------------------------------------------------
+
+# Legacy support
+option(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
+
+if (ZSTD_LEGACY_SUPPORT)
+ message(STATUS "ZSTD_LEGACY_SUPPORT defined!")
+ add_definitions(-DZSTD_LEGACY_SUPPORT=5)
+else ()
+ message(STATUS "ZSTD_LEGACY_SUPPORT not defined!")
+ add_definitions(-DZSTD_LEGACY_SUPPORT=0)
+endif ()
+
+# Multi-threading support
+option(ZSTD_MULTITHREAD_SUPPORT "MULTITHREADING SUPPORT" ON)
+
+if (ZSTD_MULTITHREAD_SUPPORT)
+ message(STATUS "ZSTD_MULTITHREAD_SUPPORT is enabled")
+else ()
+ message(STATUS "ZSTD_MULTITHREAD_SUPPORT is disabled")
+endif ()
+
+option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" ON)
+option(ZSTD_BUILD_CONTRIB "BUILD CONTRIB" OFF)
+
+# Respect the conventional CMake option for enabling tests if it was specified on the first configure
+if (BUILD_TESTING)
+ set(ZSTD_BUILD_TESTS_default ON)
+else()
+ set(ZSTD_BUILD_TESTS_default OFF)
+endif()
+option(ZSTD_BUILD_TESTS "BUILD TESTS" ${ZSTD_BUILD_TESTS_default})
+if (MSVC)
+ option(ZSTD_USE_STATIC_RUNTIME "LINK TO STATIC RUN-TIME LIBRARIES" OFF)
+endif ()
+
+#-----------------------------------------------------------------------------
+# External dependencies
+#-----------------------------------------------------------------------------
+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()
+endif ()
+
+#-----------------------------------------------------------------------------
+# Add source directories
+#-----------------------------------------------------------------------------
+add_subdirectory(lib)
+
+option(ZSTD_PROGRAMS_LINK_SHARED "PROGRAMS LINK SHARED" OFF)
+
+if (ZSTD_BUILD_PROGRAMS)
+ if (NOT ZSTD_BUILD_STATIC AND NOT ZSTD_PROGRAMS_LINK_SHARED)
+ message(SEND_ERROR "You need to build static library to build zstd CLI")
+ elseif(NOT ZSTD_BUILD_SHARED AND ZSTD_PROGRAMS_LINK_SHARED)
+ message(SEND_ERROR "You need to build shared library to build zstd CLI")
+ endif ()
+
+ add_subdirectory(programs)
+endif ()
+
+if (ZSTD_BUILD_TESTS)
+ enable_testing()
+ if (NOT ZSTD_BUILD_STATIC)
+ message(SEND_ERROR "You need to build static library to build tests")
+ endif ()
+
+ add_subdirectory(tests)
+endif ()
+
+if (ZSTD_BUILD_CONTRIB)
+ add_subdirectory(contrib)
+endif ()
+
+#-----------------------------------------------------------------------------
+# Add clean-all target
+#-----------------------------------------------------------------------------
+add_custom_target(clean-all
+ COMMAND ${CMAKE_BUILD_TOOL} clean
+ COMMAND rm -rf ${CMAKE_BINARY_DIR}/
+)
+
+#-----------------------------------------------------------------------------
+# Generate Package Config files
+#
+# This section is based on the boiler plate code from:
+# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages
+#-----------------------------------------------------------------------------
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
+ VERSION ${zstd_VERSION}
+ COMPATIBILITY SameMajorVersion
+ )
+
+# A Package Config file that works from the build directory
+export(EXPORT zstdExports
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets.cmake"
+ NAMESPACE zstd::
+ )
+configure_file(zstdConfig.cmake
+ "${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
+ COPYONLY
+ )
+
+# A Package Config file that works from the installation directory
+set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/zstd)
+install(EXPORT zstdExports
+ FILE zstdTargets.cmake
+ NAMESPACE zstd::
+ DESTINATION ${ConfigPackageLocation}
+ )
+install(FILES
+ zstdConfig.cmake
+ "${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
+ DESTINATION ${ConfigPackageLocation}
+ )
diff --git a/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake b/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
new file mode 100644
index 000000000..186819885
--- /dev/null
+++ b/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
@@ -0,0 +1,79 @@
+include(CheckCXXCompilerFlag)
+include(CheckCCompilerFlag)
+
+function(EnableCompilerFlag _flag _C _CXX)
+ string(REGEX REPLACE "\\+" "PLUS" varname "${_flag}")
+ string(REGEX REPLACE "[^A-Za-z0-9]+" "_" varname "${varname}")
+ string(REGEX REPLACE "^_+" "" varname "${varname}")
+ string(TOUPPER "${varname}" varname)
+ if (_C)
+ CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
+ if (C_FLAG_${varname})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
+ endif ()
+ endif ()
+ if (_CXX)
+ CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
+ if (CXX_FLAG_${varname})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
+ endif ()
+ endif ()
+endfunction()
+
+macro(ADD_ZSTD_COMPILATION_FLAGS)
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" OR MINGW) #Not only UNIX but also WIN32 for MinGW
+ #Set c++11 by default
+ EnableCompilerFlag("-std=c++11" false true)
+ #Set c99 by default
+ EnableCompilerFlag("-std=c99" true false)
+ EnableCompilerFlag("-Wall" true true)
+ EnableCompilerFlag("-Wextra" true true)
+ EnableCompilerFlag("-Wundef" true true)
+ EnableCompilerFlag("-Wshadow" true true)
+ EnableCompilerFlag("-Wcast-align" true true)
+ EnableCompilerFlag("-Wcast-qual" true true)
+ EnableCompilerFlag("-Wstrict-prototypes" true false)
+ # Enable asserts in Debug mode
+ if (CMAKE_BUILD_TYPE MATCHES "Debug")
+ EnableCompilerFlag("-DDEBUGLEVEL=1" true true)
+ endif ()
+ elseif (MSVC) # Add specific compilation flags for Windows Visual
+
+ set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
+ if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION)
+ EnableCompilerFlag("/MP" true true)
+ endif ()
+
+ # UNICODE SUPPORT
+ EnableCompilerFlag("/D_UNICODE" true true)
+ EnableCompilerFlag("/DUNICODE" true true)
+ # Enable asserts in Debug mode
+ if (CMAKE_BUILD_TYPE MATCHES "Debug")
+ EnableCompilerFlag("/DDEBUGLEVEL=1" true true)
+ endif ()
+ endif ()
+
+ # Remove duplicates compilation flags
+ foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if( ${flag_var} )
+ separate_arguments(${flag_var})
+ list(REMOVE_DUPLICATES ${flag_var})
+ string(REPLACE ";" " " ${flag_var} "${${flag_var}}")
+ endif()
+ endforeach ()
+
+ if (MSVC AND ZSTD_USE_STATIC_RUNTIME)
+ foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if ( ${flag_var} )
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+ endif()
+ endforeach ()
+ endif ()
+
+endmacro()
diff --git a/src/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake b/src/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake
new file mode 100644
index 000000000..d0fac06da
--- /dev/null
+++ b/src/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake
@@ -0,0 +1,49 @@
+# Find LibLZ4
+#
+# Find LibLZ4 headers and library
+#
+# Result Variables
+#
+# LIBLZ4_FOUND - True if lz4 is found
+# LIBLZ4_INCLUDE_DIRS - lz4 headers directories
+# LIBLZ4_LIBRARIES - lz4 libraries
+# LIBLZ4_VERSION_MAJOR - The major version of lz4
+# LIBLZ4_VERSION_MINOR - The minor version of lz4
+# LIBLZ4_VERSION_RELEASE - The release version of lz4
+# LIBLZ4_VERSION_STRING - version number string (e.g. 1.8.3)
+#
+# Hints
+#
+# Set ``LZ4_ROOT_DIR`` to the directory of lz4.h and lz4 library
+
+set(_LIBLZ4_ROOT_HINTS
+ ENV LZ4_ROOT_DIR)
+
+find_path( LIBLZ4_INCLUDE_DIR lz4.h
+ HINTS ${_LIBLZ4_ROOT_HINTS})
+find_library( LIBLZ4_LIBRARY NAMES lz4 liblz4 liblz4_static
+ HINTS ${_LIBLZ4_ROOT_HINTS})
+
+if(LIBLZ4_INCLUDE_DIR)
+ file(STRINGS "${LIBLZ4_INCLUDE_DIR}/lz4.h" LIBLZ4_HEADER_CONTENT REGEX "#define LZ4_VERSION_[A-Z]+ +[0-9]+")
+
+ string(REGEX REPLACE ".*#define LZ4_VERSION_MAJOR +([0-9]+).*" "\\1" LIBLZ4_VERSION_MAJOR "${LIBLZ4_HEADER_CONTENT}")
+ string(REGEX REPLACE ".*#define LZ4_VERSION_MINOR +([0-9]+).*" "\\1" LIBLZ4_VERSION_MINOR "${LIBLZ4_HEADER_CONTENT}")
+ string(REGEX REPLACE ".*#define LZ4_VERSION_RELEASE +([0-9]+).*" "\\1" LIBLZ4_VERSION_RELEASE "${LIBLZ4_HEADER_CONTENT}")
+
+ set(LIBLZ4_VERSION_STRING "${LIBLZ4_VERSION_MAJOR}.${LIBLZ4_VERSION_MINOR}.${LIBLZ4_VERSION_RELEASE}")
+ unset(LIBLZ4_HEADER_CONTENT)
+endif()
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibLZ4 REQUIRED_VARS LIBLZ4_INCLUDE_DIR
+ LIBLZ4_LIBRARY
+ VERSION_VAR LIBLZ4_VERSION_STRING
+ FAIL_MESSAGE "Could NOT find LZ4, try to set the paths to lz4.h and lz4 library in environment variable LZ4_ROOT_DIR")
+
+if (LIBLZ4_FOUND)
+ set(LIBLZ4_LIBRARIES ${LIBLZ4_LIBRARY})
+ set(LIBLZ4_INCLUDE_DIRS ${LIBLZ4_INCLUDE_DIR})
+endif ()
+
+mark_as_advanced( LIBLZ4_INCLUDE_DIR LIBLZ4_LIBRARY )
diff --git a/src/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake b/src/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake
new file mode 100644
index 000000000..e8ed6064c
--- /dev/null
+++ b/src/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake
@@ -0,0 +1,10 @@
+function(GetZstdLibraryVersion _header _major _minor _patch)
+ # Read file content
+ file(READ ${_header} CONTENT)
+
+ string(REGEX MATCH ".*define ZSTD_VERSION_MAJOR *([0-9]+).*define ZSTD_VERSION_MINOR *([0-9]+).*define ZSTD_VERSION_RELEASE *([0-9]+)" VERSION_REGEX "${CONTENT}")
+ set(${_major} ${CMAKE_MATCH_1} PARENT_SCOPE)
+ set(${_minor} ${CMAKE_MATCH_2} PARENT_SCOPE)
+ set(${_patch} ${CMAKE_MATCH_3} PARENT_SCOPE)
+endfunction()
+
diff --git a/src/zstd/build/cmake/README.md b/src/zstd/build/cmake/README.md
new file mode 100644
index 000000000..73b30dc77
--- /dev/null
+++ b/src/zstd/build/cmake/README.md
@@ -0,0 +1,104 @@
+# Cmake contributions
+
+Contributions to the cmake build configurations are welcome. Please
+use case sensitivity that matches modern (ie. cmake version 2.6 and above)
+conventions of using lower-case for commands, and upper-case for
+variables.
+
+## How to build
+
+As cmake doesn't support command like `cmake clean`, it's recommended to perform a "out of source build".
+To do this, you can create a new directory and build in it:
+```sh
+cd build/cmake
+mkdir builddir
+cd builddir
+cmake ..
+make
+```
+Then you can clean all cmake caches by simply delete the new directory:
+```sh
+rm -rf build/cmake/builddir
+```
+
+And of course, you can directly build in build/cmake:
+```sh
+cd build/cmake
+cmake
+make
+```
+
+To show cmake build options, you can:
+```sh
+cd build/cmake/builddir
+cmake -LH ..
+```
+
+Bool options can be set to `ON/OFF` with `-D[option]=[ON/OFF]`. You can configure cmake options like this:
+```sh
+cd build/cmake/builddir
+cmake -DZSTD_BUILD_TESTS=ON -DZSTD_LEGACY_SUPPORT=ON ..
+make
+```
+
+### referring
+[Looking for a 'cmake clean' command to clear up CMake output](https://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output)
+
+## CMake Style Recommendations
+
+### Indent all code correctly, i.e. the body of
+
+ * if/else/endif
+ * foreach/endforeach
+ * while/endwhile
+ * macro/endmacro
+ * function/endfunction
+
+Use spaces for indenting, 2, 3 or 4 spaces preferably. Use the same amount of
+spaces for indenting as is used in the rest of the file. Do not use tabs.
+
+### Upper/lower casing
+
+Most important: use consistent upper- or lowercasing within one file !
+
+In general, the all-lowercase style is preferred.
+
+So, this is recommended:
+
+```
+add_executable(foo foo.c)
+```
+
+These forms are discouraged
+
+```
+ADD_EXECUTABLE(bar bar.c)
+Add_Executable(hello hello.c)
+aDd_ExEcUtAbLe(blub blub.c)
+```
+
+### End commands
+To make the code easier to read, use empty commands for endforeach(), endif(),
+endfunction(), endmacro() and endwhile(). Also, use empty else() commands.
+
+For example, do this:
+
+```
+if(FOOVAR)
+ some_command(...)
+else()
+ another_command(...)
+endif()
+```
+
+and not this:
+
+```
+if(BARVAR)
+ some_other_command(...)
+endif(BARVAR)
+```
+
+### Other resources for best practices
+
+https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#modules
diff --git a/src/zstd/build/cmake/contrib/CMakeLists.txt b/src/zstd/build/cmake/contrib/CMakeLists.txt
new file mode 100644
index 000000000..f7631d08c
--- /dev/null
+++ b/src/zstd/build/cmake/contrib/CMakeLists.txt
@@ -0,0 +1,13 @@
+# ################################################################
+# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+project(contrib)
+
+add_subdirectory(pzstd)
+add_subdirectory(gen_html)
diff --git a/src/zstd/build/cmake/contrib/gen_html/CMakeLists.txt b/src/zstd/build/cmake/contrib/gen_html/CMakeLists.txt
new file mode 100644
index 000000000..8fdd61131
--- /dev/null
+++ b/src/zstd/build/cmake/contrib/gen_html/CMakeLists.txt
@@ -0,0 +1,30 @@
+# ################################################################
+# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+project(gen_html)
+include(GetZstdLibraryVersion)
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+
+# Define programs directory, where sources and header files are located
+set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
+set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
+set(GENHTML_DIR ${ZSTD_SOURCE_DIR}/contrib/gen_html)
+set(GENHTML_BINARY ${PROJECT_BINARY_DIR}/gen_html${CMAKE_EXECUTABLE_SUFFIX})
+include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${GENHTML_DIR})
+
+add_executable(gen_html ${GENHTML_DIR}/gen_html.cpp)
+
+GetZstdLibraryVersion(${LIBRARY_DIR}/zstd.h VMAJOR VMINOR VRELEASE)
+set(LIBVERSION "${VMAJOR}.${VMINOR}.${VRELEASE}")
+add_custom_target(zstd_manual.html ALL
+ ${GENHTML_BINARY} "${LIBVERSION}" "${LIBRARY_DIR}/zstd.h" "${PROJECT_BINARY_DIR}/zstd_manual.html"
+ DEPENDS gen_html COMMENT "Update zstd manual")
+
+install(FILES "${PROJECT_BINARY_DIR}/zstd_manual.html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
diff --git a/src/zstd/build/cmake/contrib/pzstd/CMakeLists.txt b/src/zstd/build/cmake/contrib/pzstd/CMakeLists.txt
new file mode 100644
index 000000000..5c30a91b1
--- /dev/null
+++ b/src/zstd/build/cmake/contrib/pzstd/CMakeLists.txt
@@ -0,0 +1,32 @@
+# ################################################################
+# Copyright (c) 2016-present, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+project(pzstd)
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+
+# Define programs directory, where sources and header files are located
+set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
+set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
+set(PZSTD_DIR ${ZSTD_SOURCE_DIR}/contrib/pzstd)
+include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${PZSTD_DIR})
+
+add_executable(pzstd ${PROGRAMS_DIR}/util.c ${PZSTD_DIR}/main.cpp ${PZSTD_DIR}/Options.cpp ${PZSTD_DIR}/Pzstd.cpp ${PZSTD_DIR}/SkippableFrame.cpp)
+set_property(TARGET pzstd APPEND PROPERTY COMPILE_DEFINITIONS "NDEBUG")
+set_property(TARGET pzstd APPEND PROPERTY COMPILE_OPTIONS "-Wno-shadow")
+
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+if (CMAKE_USE_PTHREADS_INIT)
+ target_link_libraries(pzstd libzstd_shared ${CMAKE_THREAD_LIBS_INIT})
+else()
+ message(SEND_ERROR "ZSTD currently does not support thread libraries other than pthreads")
+endif()
+
+install(TARGETS pzstd RUNTIME DESTINATION "bin")
diff --git a/src/zstd/build/cmake/lib/.gitignore b/src/zstd/build/cmake/lib/.gitignore
new file mode 100644
index 000000000..a4444c8d3
--- /dev/null
+++ b/src/zstd/build/cmake/lib/.gitignore
@@ -0,0 +1,2 @@
+# cmake build artefact
+libzstd.pc
diff --git a/src/zstd/build/cmake/lib/CMakeLists.txt b/src/zstd/build/cmake/lib/CMakeLists.txt
new file mode 100644
index 000000000..666da60c1
--- /dev/null
+++ b/src/zstd/build/cmake/lib/CMakeLists.txt
@@ -0,0 +1,177 @@
+# ################################################################
+# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+project(libzstd)
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
+option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" ON)
+
+if(NOT ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC)
+ message(SEND_ERROR "You need to build at least one flavor of libzstd")
+endif()
+
+# Define library directory, where sources and header files are located
+include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
+
+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)
+
+set(Sources
+ ${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)
+
+set(Headers
+ ${LIBRARY_DIR}/zstd.h
+ ${CommonHeaders}
+ ${CompressHeaders}
+ ${DecompressHeaders}
+ ${DictBuilderHeaders}
+ ${DeprecatedHeaders})
+
+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
+ ${LIBRARY_LEGACY_DIR}/zstd_v03.c
+ ${LIBRARY_LEGACY_DIR}/zstd_v04.c
+ ${LIBRARY_LEGACY_DIR}/zstd_v05.c
+ ${LIBRARY_LEGACY_DIR}/zstd_v06.c
+ ${LIBRARY_LEGACY_DIR}/zstd_v07.c)
+
+ set(Headers ${Headers}
+ ${LIBRARY_LEGACY_DIR}/zstd_legacy.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v01.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v02.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v03.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v04.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v05.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v06.h
+ ${LIBRARY_LEGACY_DIR}/zstd_v07.h)
+endif ()
+
+if (MSVC)
+ set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/libzstd-dll)
+ set(PlatformDependResources ${MSVC_RESOURCE_DIR}/libzstd-dll.rc)
+endif ()
+
+# Split project to static and shared libraries build
+set(library_targets)
+if (ZSTD_BUILD_SHARED)
+ add_library(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources})
+ list(APPEND library_targets libzstd_shared)
+ 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()
+endif ()
+if (ZSTD_BUILD_STATIC)
+ add_library(libzstd_static STATIC ${Sources} ${Headers})
+ list(APPEND library_targets libzstd_static)
+ 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 ()
+endif ()
+
+# Add specific compile definitions for MSVC project
+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")
+ endif ()
+ if (ZSTD_BUILD_STATIC)
+ set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS")
+ endif ()
+endif ()
+
+# With MSVC static library needs to be renamed to avoid conflict with import library
+if (MSVC)
+ set(STATIC_LIBRARY_BASE_NAME zstd_static)
+else ()
+ set(STATIC_LIBRARY_BASE_NAME zstd)
+endif ()
+
+# Define static and shared library names
+if (ZSTD_BUILD_SHARED)
+ set_target_properties(
+ libzstd_shared
+ PROPERTIES
+ OUTPUT_NAME zstd
+ VERSION ${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}
+ SOVERSION ${zstd_VERSION_MAJOR})
+endif ()
+
+if (ZSTD_BUILD_STATIC)
+ set_target_properties(
+ libzstd_static
+ PROPERTIES
+ POSITION_INDEPENDENT_CODE On
+ OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME})
+endif ()
+
+if (UNIX)
+ # pkg-config
+ set(PREFIX "${CMAKE_INSTALL_PREFIX}")
+ set(LIBDIR "${CMAKE_INSTALL_LIBDIR}")
+ set(INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
+ set(VERSION "${zstd_VERSION}")
+ add_custom_target(libzstd.pc ALL
+ ${CMAKE_COMMAND} -DIN="${LIBRARY_DIR}/libzstd.pc.in" -DOUT="libzstd.pc"
+ -DPREFIX="${PREFIX}" -DLIBDIR="${LIBDIR}" -DINCLUDEDIR="${INCLUDEDIR}" -DVERSION="${VERSION}"
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.cmake"
+ COMMENT "Creating pkg-config file")
+
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+endif ()
+
+# install target
+install(FILES
+ "${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"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
+
+install(TARGETS ${library_targets}
+ EXPORT zstdExports
+ INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ )
+
+# uninstall target
+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 ()
diff --git a/src/zstd/build/cmake/lib/cmake_uninstall.cmake.in b/src/zstd/build/cmake/lib/cmake_uninstall.cmake.in
new file mode 100644
index 000000000..9f1d045dd
--- /dev/null
+++ b/src/zstd/build/cmake/lib/cmake_uninstall.cmake.in
@@ -0,0 +1,22 @@
+
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+ message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif()
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+ message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+ if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+ exec_program(
+ "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+ OUTPUT_VARIABLE rm_out
+ RETURN_VALUE rm_retval
+ )
+ if(NOT "${rm_retval}" STREQUAL 0)
+ message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+ endif()
+ else()
+ message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+ endif()
+endforeach()
diff --git a/src/zstd/build/cmake/lib/pkgconfig.cmake b/src/zstd/build/cmake/lib/pkgconfig.cmake
new file mode 100644
index 000000000..8f805a197
--- /dev/null
+++ b/src/zstd/build/cmake/lib/pkgconfig.cmake
@@ -0,0 +1 @@
+configure_file("${IN}" "${OUT}" @ONLY)
diff --git a/src/zstd/build/cmake/programs/.gitignore b/src/zstd/build/cmake/programs/.gitignore
new file mode 100644
index 000000000..ae3a8a356
--- /dev/null
+++ b/src/zstd/build/cmake/programs/.gitignore
@@ -0,0 +1,5 @@
+# produced by make
+zstd
+zstd-frugal
+unzstd
+zstdcat
diff --git a/src/zstd/build/cmake/programs/CMakeLists.txt b/src/zstd/build/cmake/programs/CMakeLists.txt
new file mode 100644
index 000000000..b26e97d0d
--- /dev/null
+++ b/src/zstd/build/cmake/programs/CMakeLists.txt
@@ -0,0 +1,135 @@
+# ################################################################
+# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
+# All rights reserved.
+#
+# 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).
+# ################################################################
+
+project(programs)
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+
+# Define programs directory, where sources and header files are located
+set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
+set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
+include_directories(${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)
+
+if (ZSTD_LEGACY_SUPPORT)
+ set(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy)
+ include_directories(${PROGRAMS_LEGACY_DIR} ${LIBRARY_DIR}/legacy)
+endif ()
+
+if (ZSTD_PROGRAMS_LINK_SHARED)
+ set(PROGRAMS_ZSTD_LINK_TARGET libzstd_shared)
+else ()
+ set(PROGRAMS_ZSTD_LINK_TARGET libzstd_static)
+endif ()
+
+if (MSVC)
+ set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/zstd)
+ set(PlatformDependResources ${MSVC_RESOURCE_DIR}/zstd.rc)
+endif ()
+
+add_executable(zstd ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/dibio.c ${PlatformDependResources})
+target_link_libraries(zstd ${PROGRAMS_ZSTD_LINK_TARGET})
+if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+ target_link_libraries(zstd rt)
+endif ()
+install(TARGETS zstd RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+
+if (UNIX)
+ add_custom_target(zstdcat ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdcat DEPENDS zstd COMMENT "Creating zstdcat symlink")
+ add_custom_target(unzstd ALL ${CMAKE_COMMAND} -E create_symlink zstd unzstd DEPENDS zstd COMMENT "Creating unzstd symlink")
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdcat DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/unzstd DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ install(PROGRAMS ${PROGRAMS_DIR}/zstdgrep DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ install(PROGRAMS ${PROGRAMS_DIR}/zstdless DESTINATION "${CMAKE_INSTALL_BINDIR}")
+
+ add_custom_target(zstd.1 ALL
+ ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstd.1 .
+ COMMENT "Copying manpage zstd.1")
+ add_custom_target(zstdgrep.1 ALL
+ ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdgrep.1 .
+ COMMENT "Copying manpage zstdgrep.1")
+ add_custom_target(zstdless.1 ALL
+ ${CMAKE_COMMAND} -E copy ${PROGRAMS_DIR}/zstdless.1 .
+ COMMENT "Copying manpage zstdless.1")
+ add_custom_target(zstdcat.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 zstdcat.1 DEPENDS zstd.1 COMMENT "Creating zstdcat.1 symlink")
+ add_custom_target(unzstd.1 ALL ${CMAKE_COMMAND} -E create_symlink zstd.1 unzstd.1 DEPENDS zstd.1 COMMENT "Creating unzstd.1 symlink")
+
+ # Define MAN_INSTALL_DIR if necessary
+ if (MAN_INSTALL_DIR)
+ else ()
+ set(MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
+ endif ()
+
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/zstd.1
+ ${CMAKE_CURRENT_BINARY_DIR}/zstdcat.1
+ ${CMAKE_CURRENT_BINARY_DIR}/unzstd.1
+ ${CMAKE_CURRENT_BINARY_DIR}/zstdgrep.1
+ ${CMAKE_CURRENT_BINARY_DIR}/zstdless.1
+ DESTINATION "${MAN_INSTALL_DIR}")
+
+ add_executable(zstd-frugal ${PROGRAMS_DIR}/zstdcli.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/fileio.c)
+ target_link_libraries(zstd-frugal ${PROGRAMS_ZSTD_LINK_TARGET})
+ set_property(TARGET zstd-frugal APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_NOBENCH;ZSTD_NODICT")
+endif ()
+
+# Add multi-threading support definitions
+
+if (ZSTD_MULTITHREAD_SUPPORT)
+ set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD")
+
+ if (UNIX)
+ target_link_libraries(zstd ${THREADS_LIBS})
+
+ add_custom_target(zstdmt ALL ${CMAKE_COMMAND} -E create_symlink zstd zstdmt DEPENDS zstd COMMENT "Creating zstdmt symlink")
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zstdmt DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ endif ()
+endif ()
+
+option(ZSTD_ZLIB_SUPPORT "ZLIB SUPPORT" OFF)
+option(ZSTD_LZMA_SUPPORT "LZMA SUPPORT" OFF)
+option(ZSTD_LZ4_SUPPORT "LZ4 SUPPORT" OFF)
+
+# Add gzip support
+if (ZSTD_ZLIB_SUPPORT)
+ find_package(ZLIB REQUIRED)
+
+ if (ZLIB_FOUND)
+ include_directories(${ZLIB_INCLUDE_DIRS})
+ target_link_libraries(zstd ${ZLIB_LIBRARIES})
+ set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_GZCOMPRESS;ZSTD_GZDECOMPRESS")
+ else ()
+ message(SEND_ERROR "zlib library is missing")
+ endif ()
+endif ()
+
+# Add lzma support
+if (ZSTD_LZMA_SUPPORT)
+ find_package(LibLZMA REQUIRED)
+
+ if (LIBLZMA_FOUND)
+ include_directories(${LIBLZMA_INCLUDE_DIRS})
+ target_link_libraries(zstd ${LIBLZMA_LIBRARIES})
+ set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZMACOMPRESS;ZSTD_LZMADECOMPRESS")
+ else ()
+ message(SEND_ERROR "lzma library is missing")
+ endif ()
+endif ()
+
+# Add lz4 support
+if (ZSTD_LZ4_SUPPORT)
+ find_package(LibLZ4 REQUIRED)
+
+ if (LIBLZ4_FOUND)
+ include_directories(${LIBLZ4_INCLUDE_DIRS})
+ target_link_libraries(zstd ${LIBLZ4_LIBRARIES})
+ set_property(TARGET zstd APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_LZ4COMPRESS;ZSTD_LZ4DECOMPRESS")
+ else ()
+ message(SEND_ERROR "lz4 library is missing")
+ endif ()
+endif ()
diff --git a/src/zstd/build/cmake/tests/.gitignore b/src/zstd/build/cmake/tests/.gitignore
new file mode 100644
index 000000000..2ab62a3e1
--- /dev/null
+++ b/src/zstd/build/cmake/tests/.gitignore
@@ -0,0 +1,7 @@
+# produced by make
+datagen
+fullbench
+fuzzer
+paramgrill
+zbufftest
+
diff --git a/src/zstd/build/cmake/tests/CMakeLists.txt b/src/zstd/build/cmake/tests/CMakeLists.txt
new file mode 100644
index 000000000..95d60f5f3
--- /dev/null
+++ b/src/zstd/build/cmake/tests/CMakeLists.txt
@@ -0,0 +1,106 @@
+# ################################################################
+# zstd - Makefile
+# Copyright (C) Yann Collet 2014-present
+# All rights reserved.
+#
+# BSD license
+#
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+#
+# * 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.
+#
+# 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.
+#
+# You can contact the author at :
+# - zstd homepage : http://www.zstd.net/
+# ################################################################
+
+project(tests)
+
+# name: Cache variable name. The value is expected to be a semicolon-separated
+# list of command line flags
+# default_value: Value to initialize the option with. Can be space separated.
+function(AddTestFlagsOption name default_value doc)
+ string(STRIP "${default_value}" default_value)
+ string(REGEX REPLACE " +" ";" default_value "${default_value}")
+ set(${name} ${default_value} CACHE STRING "${doc}")
+ mark_as_advanced(${name})
+endfunction()
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+
+# Define programs directory, where sources and header files are located
+set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
+set(PROGRAMS_DIR ${ZSTD_SOURCE_DIR}/programs)
+set(TESTS_DIR ${ZSTD_SOURCE_DIR}/tests)
+include_directories(${TESTS_DIR} ${PROGRAMS_DIR} ${LIBRARY_DIR} ${LIBRARY_DIR}/common ${LIBRARY_DIR}/compress ${LIBRARY_DIR}/dictBuilder)
+
+add_executable(datagen ${PROGRAMS_DIR}/datagen.c ${TESTS_DIR}/datagencli.c)
+target_link_libraries(datagen libzstd_static)
+
+#
+# fullbench
+#
+add_executable(fullbench ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${TESTS_DIR}/fullbench.c)
+target_link_libraries(fullbench libzstd_static)
+add_test(NAME fullbench COMMAND fullbench)
+
+#
+# fuzzer
+#
+add_executable(fuzzer ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/fuzzer.c)
+target_link_libraries(fuzzer libzstd_static)
+AddTestFlagsOption(ZSTD_FUZZER_FLAGS "$ENV{FUZZERTEST} $ENV{FUZZER_FLAGS}"
+ "Semicolon-separated list of flags to pass to the fuzzer test (see `fuzzer -h` for usage)")
+add_test(NAME fuzzer COMMAND fuzzer ${ZSTD_FUZZER_FLAGS})
+# Disable the timeout since the run time is too long for the default timeout of
+# 1500 seconds and varies considerably between low-end and high-end CPUs.
+# set_tests_properties(fuzzer PROPERTIES TIMEOUT 0)
+
+#
+# zstreamtest
+#
+add_executable(zstreamtest ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/seqgen.c ${TESTS_DIR}/zstreamtest.c)
+target_link_libraries(zstreamtest libzstd_static)
+AddTestFlagsOption(ZSTD_ZSTREAM_FLAGS "$ENV{ZSTREAM_TESTTIME} $ENV{FUZZER_FLAGS}"
+ "Semicolon-separated list of flags to pass to the zstreamtest test (see `zstreamtest -h` for usage)")
+add_test(NAME zstreamtest COMMAND zstreamtest ${ZSTD_ZSTREAM_FLAGS})
+
+#
+# playTests.sh
+#
+AddTestFlagsOption(ZSTD_PLAYTESTS_FLAGS "--test-large-data"
+ "Semicolon-separated list of flags to pass to the playTests.sh test")
+add_test(NAME playTests COMMAND sh -c "${TESTS_DIR}/playTests.sh" ${ZSTD_PLAYTESTS_FLAGS})
+if (ZSTD_BUILD_PROGRAMS)
+ set_property(TEST playTests APPEND PROPERTY ENVIRONMENT
+ "ZSTD_BIN=$<TARGET_FILE:zstd>"
+ "DATAGEN_BIN=$<TARGET_FILE:datagen>"
+ )
+else()
+ message(STATUS "Disabling playTests.sh test because ZSTD_BUILD_PROGRAMS is not enabled")
+ set_tests_properties(playTests PROPERTIES DISABLED YES)
+endif()
+
+# Label the "Medium" set of tests (see TESTING.md)
+set_property(TEST fuzzer zstreamtest playTests APPEND PROPERTY LABELS Medium)
+
+if (UNIX)
+ add_executable(paramgrill ${PROGRAMS_DIR}/benchfn.c ${PROGRAMS_DIR}/benchzstd.c ${PROGRAMS_DIR}/datagen.c ${PROGRAMS_DIR}/util.c ${PROGRAMS_DIR}/timefn.c ${TESTS_DIR}/paramgrill.c)
+ target_link_libraries(paramgrill libzstd_static m) #m is math library
+endif ()
diff --git a/src/zstd/build/cmake/zstdConfig.cmake b/src/zstd/build/cmake/zstdConfig.cmake
new file mode 100644
index 000000000..ebbfcc38f
--- /dev/null
+++ b/src/zstd/build/cmake/zstdConfig.cmake
@@ -0,0 +1 @@
+include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake")