]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | # ################################################################ |
11fdf7f2 | 2 | # Copyright (c) 2015-present, Yann Collet, Facebook, Inc. |
7c673cae FG |
3 | # All rights reserved. |
4 | # | |
11fdf7f2 TL |
5 | # This source code is licensed under both the BSD-style license (found in the |
6 | # LICENSE file in the root directory of this source tree) and the GPLv2 (found | |
7 | # in the COPYING file in the root directory of this source tree). | |
7c673cae FG |
8 | # ################################################################ |
9 | ||
9f95a23c | 10 | project(libzstd) |
7c673cae | 11 | |
9f95a23c TL |
12 | set(CMAKE_INCLUDE_CURRENT_DIR TRUE) |
13 | option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON) | |
14 | option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" ON) | |
7c673cae | 15 | |
9f95a23c TL |
16 | if(NOT ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC) |
17 | message(SEND_ERROR "You need to build at least one flavor of libzstd") | |
18 | endif() | |
7c673cae FG |
19 | |
20 | # Define library directory, where sources and header files are located | |
9f95a23c | 21 | include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common) |
7c673cae | 22 | |
9f95a23c | 23 | set(Sources |
7c673cae | 24 | ${LIBRARY_DIR}/common/entropy_common.c |
11fdf7f2 TL |
25 | ${LIBRARY_DIR}/common/fse_decompress.c |
26 | ${LIBRARY_DIR}/common/threading.c | |
27 | ${LIBRARY_DIR}/common/pool.c | |
7c673cae FG |
28 | ${LIBRARY_DIR}/common/zstd_common.c |
29 | ${LIBRARY_DIR}/common/error_private.c | |
30 | ${LIBRARY_DIR}/common/xxhash.c | |
9f95a23c | 31 | ${LIBRARY_DIR}/compress/hist.c |
7c673cae FG |
32 | ${LIBRARY_DIR}/compress/fse_compress.c |
33 | ${LIBRARY_DIR}/compress/huf_compress.c | |
34 | ${LIBRARY_DIR}/compress/zstd_compress.c | |
11fdf7f2 TL |
35 | ${LIBRARY_DIR}/compress/zstdmt_compress.c |
36 | ${LIBRARY_DIR}/compress/zstd_fast.c | |
37 | ${LIBRARY_DIR}/compress/zstd_double_fast.c | |
38 | ${LIBRARY_DIR}/compress/zstd_lazy.c | |
39 | ${LIBRARY_DIR}/compress/zstd_opt.c | |
40 | ${LIBRARY_DIR}/compress/zstd_ldm.c | |
7c673cae FG |
41 | ${LIBRARY_DIR}/decompress/huf_decompress.c |
42 | ${LIBRARY_DIR}/decompress/zstd_decompress.c | |
9f95a23c TL |
43 | ${LIBRARY_DIR}/decompress/zstd_decompress_block.c |
44 | ${LIBRARY_DIR}/decompress/zstd_ddict.c | |
11fdf7f2 | 45 | ${LIBRARY_DIR}/dictBuilder/cover.c |
9f95a23c | 46 | ${LIBRARY_DIR}/dictBuilder/fastcover.c |
7c673cae FG |
47 | ${LIBRARY_DIR}/dictBuilder/divsufsort.c |
48 | ${LIBRARY_DIR}/dictBuilder/zdict.c | |
11fdf7f2 | 49 | ${LIBRARY_DIR}/deprecated/zbuff_common.c |
7c673cae FG |
50 | ${LIBRARY_DIR}/deprecated/zbuff_compress.c |
51 | ${LIBRARY_DIR}/deprecated/zbuff_decompress.c) | |
52 | ||
9f95a23c | 53 | set(Headers |
7c673cae | 54 | ${LIBRARY_DIR}/zstd.h |
9f95a23c | 55 | ${LIBRARY_DIR}/common/debug.h |
11fdf7f2 TL |
56 | ${LIBRARY_DIR}/common/pool.h |
57 | ${LIBRARY_DIR}/common/threading.h | |
7c673cae FG |
58 | ${LIBRARY_DIR}/common/bitstream.h |
59 | ${LIBRARY_DIR}/common/error_private.h | |
60 | ${LIBRARY_DIR}/common/zstd_errors.h | |
61 | ${LIBRARY_DIR}/common/fse.h | |
62 | ${LIBRARY_DIR}/common/huf.h | |
63 | ${LIBRARY_DIR}/common/mem.h | |
64 | ${LIBRARY_DIR}/common/zstd_internal.h | |
9f95a23c TL |
65 | ${LIBRARY_DIR}/compress/hist.h |
66 | ${LIBRARY_DIR}/compress/zstd_compress_internal.h | |
11fdf7f2 TL |
67 | ${LIBRARY_DIR}/compress/zstd_fast.h |
68 | ${LIBRARY_DIR}/compress/zstd_double_fast.h | |
69 | ${LIBRARY_DIR}/compress/zstd_lazy.h | |
70 | ${LIBRARY_DIR}/compress/zstd_opt.h | |
71 | ${LIBRARY_DIR}/compress/zstd_ldm.h | |
72 | ${LIBRARY_DIR}/compress/zstdmt_compress.h | |
9f95a23c TL |
73 | ${LIBRARY_DIR}/decompress/zstd_decompress_internal.h |
74 | ${LIBRARY_DIR}/decompress/zstd_decompress_block.h | |
75 | ${LIBRARY_DIR}/decompress/zstd_ddict.h | |
7c673cae | 76 | ${LIBRARY_DIR}/dictBuilder/zdict.h |
9f95a23c | 77 | ${LIBRARY_DIR}/dictBuilder/cover.h |
7c673cae FG |
78 | ${LIBRARY_DIR}/deprecated/zbuff.h) |
79 | ||
9f95a23c TL |
80 | if (ZSTD_LEGACY_SUPPORT) |
81 | set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy) | |
82 | include_directories(${LIBRARY_LEGACY_DIR}) | |
7c673cae | 83 | |
9f95a23c | 84 | set(Sources ${Sources} |
7c673cae FG |
85 | ${LIBRARY_LEGACY_DIR}/zstd_v01.c |
86 | ${LIBRARY_LEGACY_DIR}/zstd_v02.c | |
87 | ${LIBRARY_LEGACY_DIR}/zstd_v03.c | |
88 | ${LIBRARY_LEGACY_DIR}/zstd_v04.c | |
89 | ${LIBRARY_LEGACY_DIR}/zstd_v05.c | |
90 | ${LIBRARY_LEGACY_DIR}/zstd_v06.c | |
91 | ${LIBRARY_LEGACY_DIR}/zstd_v07.c) | |
92 | ||
9f95a23c | 93 | set(Headers ${Headers} |
7c673cae FG |
94 | ${LIBRARY_LEGACY_DIR}/zstd_legacy.h |
95 | ${LIBRARY_LEGACY_DIR}/zstd_v01.h | |
96 | ${LIBRARY_LEGACY_DIR}/zstd_v02.h | |
97 | ${LIBRARY_LEGACY_DIR}/zstd_v03.h | |
98 | ${LIBRARY_LEGACY_DIR}/zstd_v04.h | |
99 | ${LIBRARY_LEGACY_DIR}/zstd_v05.h | |
100 | ${LIBRARY_LEGACY_DIR}/zstd_v06.h | |
101 | ${LIBRARY_LEGACY_DIR}/zstd_v07.h) | |
9f95a23c | 102 | endif () |
7c673cae | 103 | |
9f95a23c TL |
104 | if (MSVC) |
105 | set(MSVC_RESOURCE_DIR ${ZSTD_SOURCE_DIR}/build/VS2010/libzstd-dll) | |
106 | set(PlatformDependResources ${MSVC_RESOURCE_DIR}/libzstd-dll.rc) | |
107 | endif () | |
7c673cae FG |
108 | |
109 | # Split project to static and shared libraries build | |
9f95a23c TL |
110 | if (ZSTD_BUILD_SHARED) |
111 | add_library(libzstd_shared SHARED ${Sources} ${Headers} ${PlatformDependResources}) | |
112 | if (ZSTD_MULTITHREAD_SUPPORT) | |
113 | set_property(TARGET libzstd_shared APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD") | |
114 | if (UNIX) | |
115 | target_link_libraries(libzstd_shared ${THREADS_LIBS}) | |
116 | endif () | |
117 | endif() | |
118 | endif () | |
119 | if (ZSTD_BUILD_STATIC) | |
120 | add_library(libzstd_static STATIC ${Sources} ${Headers}) | |
121 | if (ZSTD_MULTITHREAD_SUPPORT) | |
122 | set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_MULTITHREAD") | |
123 | if (UNIX) | |
124 | target_link_libraries(libzstd_static ${THREADS_LIBS}) | |
125 | endif () | |
126 | endif () | |
127 | endif () | |
7c673cae FG |
128 | |
129 | # Add specific compile definitions for MSVC project | |
9f95a23c TL |
130 | if (MSVC) |
131 | if (ZSTD_BUILD_SHARED) | |
132 | set_property(TARGET libzstd_shared APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_DLL_EXPORT=1;ZSTD_HEAPMODE=0;_CONSOLE;_CRT_SECURE_NO_WARNINGS") | |
133 | endif () | |
134 | if (ZSTD_BUILD_STATIC) | |
135 | set_property(TARGET libzstd_static APPEND PROPERTY COMPILE_DEFINITIONS "ZSTD_HEAPMODE=0;_CRT_SECURE_NO_WARNINGS") | |
136 | endif () | |
137 | endif () | |
7c673cae | 138 | |
11fdf7f2 | 139 | # With MSVC static library needs to be renamed to avoid conflict with import library |
9f95a23c TL |
140 | if (MSVC) |
141 | set(STATIC_LIBRARY_BASE_NAME zstd_static) | |
142 | else () | |
143 | set(STATIC_LIBRARY_BASE_NAME zstd) | |
144 | endif () | |
7c673cae FG |
145 | |
146 | # Define static and shared library names | |
9f95a23c TL |
147 | if (ZSTD_BUILD_SHARED) |
148 | set_target_properties( | |
11fdf7f2 TL |
149 | libzstd_shared |
150 | PROPERTIES | |
151 | OUTPUT_NAME zstd | |
9f95a23c TL |
152 | VERSION ${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH} |
153 | SOVERSION ${zstd_VERSION_MAJOR}) | |
154 | endif () | |
11fdf7f2 | 155 | |
9f95a23c TL |
156 | if (ZSTD_BUILD_STATIC) |
157 | set_target_properties( | |
11fdf7f2 TL |
158 | libzstd_static |
159 | PROPERTIES | |
160 | OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME}) | |
9f95a23c | 161 | endif () |
7c673cae | 162 | |
9f95a23c | 163 | if (UNIX) |
11fdf7f2 | 164 | # pkg-config |
9f95a23c TL |
165 | set(PREFIX "${CMAKE_INSTALL_PREFIX}") |
166 | set(LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") | |
167 | set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include") | |
168 | set(VERSION "${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}") | |
169 | add_custom_target(libzstd.pc ALL | |
11fdf7f2 TL |
170 | ${CMAKE_COMMAND} -DIN="${LIBRARY_DIR}/libzstd.pc.in" -DOUT="libzstd.pc" |
171 | -DPREFIX="${PREFIX}" -DLIBDIR="${LIBDIR}" -DINCLUDEDIR="${INCLUDEDIR}" -DVERSION="${VERSION}" | |
172 | -P "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.cmake" | |
173 | COMMENT "Creating pkg-config file") | |
174 | ||
9f95a23c TL |
175 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${LIBDIR}/pkgconfig") |
176 | endif () | |
11fdf7f2 TL |
177 | |
178 | # install target | |
9f95a23c | 179 | install(FILES |
11fdf7f2 TL |
180 | ${LIBRARY_DIR}/zstd.h |
181 | ${LIBRARY_DIR}/deprecated/zbuff.h | |
182 | ${LIBRARY_DIR}/dictBuilder/zdict.h | |
9f95a23c | 183 | ${LIBRARY_DIR}/dictBuilder/cover.h |
11fdf7f2 TL |
184 | ${LIBRARY_DIR}/common/zstd_errors.h |
185 | DESTINATION "include") | |
186 | ||
9f95a23c TL |
187 | if (ZSTD_BUILD_SHARED) |
188 | install(TARGETS libzstd_shared RUNTIME DESTINATION "bin" | |
189 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" | |
190 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") | |
191 | endif() | |
192 | if (ZSTD_BUILD_STATIC) | |
193 | install(TARGETS libzstd_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") | |
194 | endif () | |
11fdf7f2 TL |
195 | |
196 | # uninstall target | |
9f95a23c | 197 | configure_file( |
11fdf7f2 TL |
198 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" |
199 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | |
200 | IMMEDIATE @ONLY) | |
201 | ||
9f95a23c | 202 | add_custom_target(uninstall |
11fdf7f2 | 203 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) |