]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/build/cmake/lib/CMakeLists.txt
import 15.2.0 Octopus source
[ceph.git] / ceph / src / zstd / build / cmake / lib / CMakeLists.txt
1 # ################################################################
2 # Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
3 # All rights reserved.
4 #
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).
8 # ################################################################
9
10 project(libzstd)
11
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)
15
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()
19
20 # Define library directory, where sources and header files are located
21 include_directories(${LIBRARY_DIR} ${LIBRARY_DIR}/common)
22
23 set(Sources
24 ${LIBRARY_DIR}/common/entropy_common.c
25 ${LIBRARY_DIR}/common/fse_decompress.c
26 ${LIBRARY_DIR}/common/threading.c
27 ${LIBRARY_DIR}/common/pool.c
28 ${LIBRARY_DIR}/common/zstd_common.c
29 ${LIBRARY_DIR}/common/error_private.c
30 ${LIBRARY_DIR}/common/xxhash.c
31 ${LIBRARY_DIR}/compress/hist.c
32 ${LIBRARY_DIR}/compress/fse_compress.c
33 ${LIBRARY_DIR}/compress/huf_compress.c
34 ${LIBRARY_DIR}/compress/zstd_compress.c
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
41 ${LIBRARY_DIR}/decompress/huf_decompress.c
42 ${LIBRARY_DIR}/decompress/zstd_decompress.c
43 ${LIBRARY_DIR}/decompress/zstd_decompress_block.c
44 ${LIBRARY_DIR}/decompress/zstd_ddict.c
45 ${LIBRARY_DIR}/dictBuilder/cover.c
46 ${LIBRARY_DIR}/dictBuilder/fastcover.c
47 ${LIBRARY_DIR}/dictBuilder/divsufsort.c
48 ${LIBRARY_DIR}/dictBuilder/zdict.c
49 ${LIBRARY_DIR}/deprecated/zbuff_common.c
50 ${LIBRARY_DIR}/deprecated/zbuff_compress.c
51 ${LIBRARY_DIR}/deprecated/zbuff_decompress.c)
52
53 set(Headers
54 ${LIBRARY_DIR}/zstd.h
55 ${LIBRARY_DIR}/common/debug.h
56 ${LIBRARY_DIR}/common/pool.h
57 ${LIBRARY_DIR}/common/threading.h
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
65 ${LIBRARY_DIR}/compress/hist.h
66 ${LIBRARY_DIR}/compress/zstd_compress_internal.h
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
73 ${LIBRARY_DIR}/decompress/zstd_decompress_internal.h
74 ${LIBRARY_DIR}/decompress/zstd_decompress_block.h
75 ${LIBRARY_DIR}/decompress/zstd_ddict.h
76 ${LIBRARY_DIR}/dictBuilder/zdict.h
77 ${LIBRARY_DIR}/dictBuilder/cover.h
78 ${LIBRARY_DIR}/deprecated/zbuff.h)
79
80 if (ZSTD_LEGACY_SUPPORT)
81 set(LIBRARY_LEGACY_DIR ${LIBRARY_DIR}/legacy)
82 include_directories(${LIBRARY_LEGACY_DIR})
83
84 set(Sources ${Sources}
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
93 set(Headers ${Headers}
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)
102 endif ()
103
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 ()
108
109 # Split project to static and shared libraries build
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 ()
128
129 # Add specific compile definitions for MSVC project
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 ()
138
139 # With MSVC static library needs to be renamed to avoid conflict with import library
140 if (MSVC)
141 set(STATIC_LIBRARY_BASE_NAME zstd_static)
142 else ()
143 set(STATIC_LIBRARY_BASE_NAME zstd)
144 endif ()
145
146 # Define static and shared library names
147 if (ZSTD_BUILD_SHARED)
148 set_target_properties(
149 libzstd_shared
150 PROPERTIES
151 OUTPUT_NAME zstd
152 VERSION ${zstd_VERSION_MAJOR}.${zstd_VERSION_MINOR}.${zstd_VERSION_PATCH}
153 SOVERSION ${zstd_VERSION_MAJOR})
154 endif ()
155
156 if (ZSTD_BUILD_STATIC)
157 set_target_properties(
158 libzstd_static
159 PROPERTIES
160 OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME})
161 endif ()
162
163 if (UNIX)
164 # pkg-config
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
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
175 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libzstd.pc" DESTINATION "${LIBDIR}/pkgconfig")
176 endif ()
177
178 # install target
179 install(FILES
180 ${LIBRARY_DIR}/zstd.h
181 ${LIBRARY_DIR}/deprecated/zbuff.h
182 ${LIBRARY_DIR}/dictBuilder/zdict.h
183 ${LIBRARY_DIR}/dictBuilder/cover.h
184 ${LIBRARY_DIR}/common/zstd_errors.h
185 DESTINATION "include")
186
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 ()
195
196 # uninstall target
197 configure_file(
198 "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
199 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
200 IMMEDIATE @ONLY)
201
202 add_custom_target(uninstall
203 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)