Debian Codegraph @

src/c-blosc2/blosc/CMakeLists.txt

raw
1 # Blosc - Blocked Shuffling and Compression Library
2 #
3 # Copyright (c) 2021 Blosc Development Team <[email protected]>
4 # https://blosc.org
5 # License: BSD 3-Clause (see LICENSE.txt)
6 #
7 # See LICENSE.txt for details about copyright and rights to use.
8
9 # A simple way to detect that we are using CMAKE
10 add_definitions(-DUSING_CMAKE)
11
12 set(version_string ${BLOSC2_VERSION_MAJOR}.${BLOSC2_VERSION_MINOR}.${BLOSC2_VERSION_PATCH})
13
14 # targets
15 if(BUILD_SHARED)
16 add_library(blosc2_shared SHARED)
17 # ALIAS for superbuilds that use Blosc2 as sub-project
18 # must be the same as the NAMESPACE in Blosc2Targets
19 add_library(Blosc2::blosc2_shared ALIAS blosc2_shared)
20 set_target_properties(blosc2_shared PROPERTIES
21 OUTPUT_NAME blosc2
22 # Hide symbols by default unless they're specifically exported.
23 # This makes it easier to keep the set of exported symbols the
24 # same across all compilers/platforms.
25 C_VISIBILITY_PRESET hidden
26 )
27 if(MSVC OR MINGW)
28 set_target_properties(blosc2_shared PROPERTIES PREFIX lib)
29 endif()
30 set_target_properties(blosc2_shared PROPERTIES
31 VERSION ${version_string}
32 SOVERSION 4 # Change this when an ABI change happens
33 )
34 target_compile_definitions(blosc2_shared PUBLIC BLOSC_SHARED_LIBRARY)
35 target_include_directories(blosc2_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
36 target_include_directories(blosc2_shared PUBLIC
37 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
38 $<INSTALL_INTERFACE:include>)
39 endif()
40 if(BUILD_STATIC)
41 add_compile_definitions(BUILD_STATIC)
42 add_library(blosc2_static STATIC)
43 # ALIAS for superbuilds that use Blosc2 as sub-project
44 # must be the same as the NAMESPACE in Blosc2Targets
45 add_library(Blosc2::blosc2_static ALIAS blosc2_static)
46 set_target_properties(blosc2_static PROPERTIES
47 OUTPUT_NAME blosc2
48 POSITION_INDEPENDENT_CODE ON
49 # Hide symbols by default unless they're specifically exported.
50 # This makes it easier to keep the set of exported symbols the
51 # same across all compilers/platforms.
52 C_VISIBILITY_PRESET hidden
53 )
54 if(MSVC OR MINGW)
55 set_target_properties(blosc2_static PROPERTIES PREFIX lib)
56 endif()
57 target_include_directories(blosc2_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
58 target_include_directories(blosc2_static PUBLIC
59 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
60 $<INSTALL_INTERFACE:include>)
61 endif()
62 # When the option has been selected to compile the test suite,
63 # compile an additional version of blosc2_static which exports
64 # some normally-hidden symbols (to facilitate unit testing).
65 if(BUILD_TESTS)
66 add_library(blosc_testing STATIC)
67 set_target_properties(blosc_testing PROPERTIES OUTPUT_NAME blosc_testing)
68 if(MSVC OR MINGW)
69 set_target_properties(blosc_testing PROPERTIES PREFIX lib)
70 endif()
71 target_compile_definitions(blosc_testing PUBLIC
72 BLOSC_TESTING
73 BLOSC_SHARED_LIBRARY # for EXPORT macro
74 )
75 target_include_directories(blosc_testing PUBLIC
76 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
77 $<INSTALL_INTERFACE:include>)
78 endif()
79
80 set(INTERNAL_LIBS ${PROJECT_SOURCE_DIR}/internal-complibs)
81
82 # link dependencies
83 # "link" dependent targets via target_link_libraries (preferred) and
84 # manually add includes / libs for others
85 if(LZ4_FOUND)
86 if(BUILD_SHARED)
87 target_include_directories(blosc2_shared PUBLIC ${LZ4_INCLUDE_DIR})
88 endif()
89 if(BUILD_STATIC)
90 target_include_directories(blosc2_static PUBLIC ${LZ4_INCLUDE_DIR})
91 endif()
92 if(BUILD_TESTS)
93 target_include_directories(blosc_testing PUBLIC ${LZ4_INCLUDE_DIR})
94 endif()
95 else()
96 set(LZ4_LOCAL_DIR ${INTERNAL_LIBS}/lz4-1.10.0)
97 if(BUILD_SHARED)
98 target_include_directories(blosc2_shared PRIVATE ${LZ4_LOCAL_DIR})
99 endif()
100 if(BUILD_STATIC)
101 target_include_directories(blosc2_static PRIVATE ${LZ4_LOCAL_DIR})
102 endif()
103 if(BUILD_TESTS)
104 target_include_directories(blosc_testing PRIVATE ${LZ4_LOCAL_DIR})
105 endif()
106 endif()
107
108 if(NOT DEACTIVATE_ZLIB)
109 if(ZLIB_NG_FOUND)
110 if(BUILD_SHARED)
111 target_link_libraries(blosc2_shared PUBLIC ZLIB_NG::ZLIB_NG)
112 endif()
113 if(BUILD_STATIC)
114 target_link_libraries(blosc2_static PUBLIC ZLIB_NG::ZLIB_NG)
115 endif()
116 if(BUILD_TESTS)
117 target_link_libraries(blosc_testing PUBLIC ZLIB_NG::ZLIB_NG)
118 endif()
119 elseif(ZLIB_FOUND)
120 if(BUILD_SHARED)
121 target_link_libraries(blosc2_shared PUBLIC ZLIB::ZLIB)
122 endif()
123 if(BUILD_STATIC)
124 target_link_libraries(blosc2_static PUBLIC ZLIB::ZLIB)
125 endif()
126 if(BUILD_TESTS)
127 target_link_libraries(blosc_testing PUBLIC ZLIB::ZLIB)
128 endif()
129 else()
130 set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR})
131 if(BUILD_SHARED)
132 target_include_directories(blosc2_shared PRIVATE ${ZLIB_LOCAL_DIR})
133 endif()
134 if(BUILD_STATIC)
135 target_include_directories(blosc2_static PRIVATE ${ZLIB_LOCAL_DIR})
136 endif()
137 if(BUILD_TESTS)
138 target_include_directories(blosc_testing PRIVATE ${ZLIB_LOCAL_DIR})
139 endif()
140 endif()
141 endif()
142
143 if(NOT DEACTIVATE_ZSTD)
144 if(ZSTD_FOUND)
145 if(BUILD_SHARED)
146 target_include_directories(blosc2_shared PUBLIC ${ZSTD_INCLUDE_DIR})
147 target_link_libraries(blosc2_shared PUBLIC ${ZSTD_LIBRARY})
148 endif()
149 if(BUILD_STATIC)
150 target_include_directories(blosc2_static PUBLIC ${ZSTD_INCLUDE_DIR})
151 target_link_libraries(blosc2_static PUBLIC ${ZSTD_LIBRARY})
152 endif()
153 if(BUILD_TESTS)
154 target_include_directories(blosc_testing PUBLIC ${ZSTD_INCLUDE_DIR})
155 target_link_libraries(blosc_testing PUBLIC ${ZSTD_LIBRARY})
156 endif()
157 else()
158 set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.5.7)
159 if(BUILD_SHARED)
160 target_include_directories(blosc2_shared PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
161 endif()
162 if(BUILD_STATIC)
163 target_include_directories(blosc2_static PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
164 endif()
165 if(BUILD_TESTS)
166 target_include_directories(blosc_testing PRIVATE ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
167 endif()
168 endif()
169 endif()
170
171 # Threads
172 if(HAVE_THREADS)
173 if(CMAKE_VERSION VERSION_LESS 3.1)
174 set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
175 else()
176 set(LIBS ${LIBS} Threads::Threads)
177 endif()
178 elseif(WIN32)
179 message(STATUS "using the internal pthread library for win32 systems.")
180 list(APPEND SOURCES blosc/win32/pthread.c)
181 else()
182 message(FATAL_ERROR "Threads required but not found.")
183 endif()
184
185 # dlopen/dlclose
186 if(NOT WIN32)
187 set(LIBS ${LIBS} ${CMAKE_DL_LIBS})
188 endif()
189
190 if(LZ4_FOUND)
191 set(LIBS ${LIBS} ${LZ4_LIBRARY})
192 else()
193 file(GLOB LZ4_FILES ${LZ4_LOCAL_DIR}/*.c)
194 list(APPEND SOURCES ${LZ4_FILES})
195 source_group("LZ4" FILES ${LZ4_FILES})
196 endif()
197
198 if(NOT DEACTIVATE_ZLIB)
199 if(ZLIB_NG_FOUND)
200 set(LIBS ${LIBS} ${ZLIB_NG_LIBRARY})
201 elseif(ZLIB_FOUND)
202 set(LIBS ${LIBS} ${ZLIB_LIBRARIES})
203 else()
204 set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR})
205 file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c)
206 list(APPEND SOURCES ${ZLIB_FILES})
207 source_group("Zlib" FILES ${ZLIB_FILES})
208 endif()
209 endif()
210
211 if(NOT DEACTIVATE_ZSTD)
212 if(ZSTD_FOUND)
213 set(LIBS ${LIBS} ${ZSTD_LIBRARY})
214 else()
215 # Enable assembly code only when not using MSVC *and* x86 is there
216 if((NOT MSVC) AND COMPILER_SUPPORT_SSE2) # if SSE2 is here, this is an x86 platform
217 message(STATUS "Adding support for assembly sources in ZSTD")
218 file(GLOB ZSTD_DECOMPRESS_FILES ${ZSTD_LOCAL_DIR}/decompress/*.S)
219 else()
220 message(STATUS "Disabling support for assembly sources in ZSTD")
221 add_compile_definitions("ZSTD_DISABLE_ASM")
222 endif()
223 file(GLOB ZSTD_DECOMPRESS_FILES ${ZSTD_DECOMPRESS_FILES}
224 ${ZSTD_LOCAL_DIR}/decompress/*.c)
225 file(GLOB ZSTD_COMMON_FILES ${ZSTD_LOCAL_DIR}/common/*.c)
226 file(GLOB ZSTD_COMPRESS_FILES ${ZSTD_LOCAL_DIR}/compress/*.c)
227 file(GLOB ZSTD_DICT_FILES ${ZSTD_LOCAL_DIR}/dictBuilder/*.c)
228 set(ZSTD_FILES ${ZSTD_COMMON_FILES} ${ZSTD_COMPRESS_FILES}
229 ${ZSTD_DECOMPRESS_FILES} ${ZSTD_DICT_FILES})
230 list(APPEND SOURCES ${ZSTD_FILES})
231 source_group("Zstd" FILES ${ZSTD_FILES})
232 endif()
233 endif()
234
235 if(HAVE_IPP)
236 set(LIBS ${LIBS} "${IPP_LIBRARIES}")
237 endif()
238
239 if(UNIX AND NOT APPLE)
240 set(LIBS ${LIBS} "rt")
241 set(LIBS ${LIBS} "m")
242 # set(LIBS ${LIBS} "profiler")
243 endif()
244
245
246 # Blosc2 library source files
247 list(APPEND SOURCES
248 blosc/blosc2.c
249 blosc/blosclz.c
250 blosc/fastcopy.c
251 blosc/fastcopy.h
252 blosc/schunk.c
253 blosc/frame.c
254 blosc/stune.c
255 blosc/stune.h
256 blosc/context.h
257 blosc/delta.c
258 blosc/delta.h
259 blosc/shuffle-generic.c
260 blosc/bitshuffle-generic.c
261 blosc/trunc-prec.c
262 blosc/trunc-prec.h
263 blosc/timestamp.c
264 blosc/sframe.c
265 blosc/directories.c
266 blosc/blosc2-stdio.c
267 blosc/b2nd.c
268 blosc/b2nd_utils.c
269 )
270 if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
271 if(COMPILER_SUPPORT_SSE2)
272 message(STATUS "Adding run-time support for SSE2")
273 list(APPEND SOURCES blosc/shuffle-sse2.c blosc/bitshuffle-sse2.c)
274 endif()
275 if(COMPILER_SUPPORT_AVX2)
276 message(STATUS "Adding run-time support for AVX2")
277 list(APPEND SOURCES blosc/shuffle-avx2.c blosc/bitshuffle-avx2.c)
278 endif()
279 if(COMPILER_SUPPORT_AVX512)
280 message(STATUS "Adding run-time support for AVX512")
281 list(APPEND SOURCES blosc/bitshuffle-avx512.c)
282 endif()
283 endif()
284 if(COMPILER_SUPPORT_NEON)
285 message(STATUS "Adding run-time support for NEON")
286 # bitshuffle-neon.c does not offer better speed than generic on arm64 (Mac M1).
287 # Besides, it does not compile on raspberry pi (armv7l), so disable it.
288 list(APPEND SOURCES blosc/shuffle-neon.c) # blosc/bitshuffle-neon.c)
289 endif()
290 if(COMPILER_SUPPORT_ALTIVEC)
291 message(STATUS "Adding run-time support for ALTIVEC")
292 list(APPEND SOURCES blosc/shuffle-altivec.c blosc/bitshuffle-altivec.c)
293 endif()
294 list(APPEND SOURCES blosc/shuffle.c)
295
296 # Based on the target architecture and hardware features supported
297 # by the C compiler, set hardware architecture optimization flags
298 # for specific shuffle implementations.
299 if(COMPILER_SUPPORT_SSE2)
300 if(MSVC)
301 # MSVC targets SSE2 by default on 64-bit configurations, but not 32-bit configurations.
302 if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
303 set_source_files_properties(
304 shuffle-sse2.c bitshuffle-sse2.c blosclz.c fastcopy.c
305 PROPERTIES COMPILE_OPTIONS "/arch:SSE2")
306 endif()
307 else()
308 set_source_files_properties(
309 shuffle-sse2.c bitshuffle-sse2.c blosclz.c fastcopy.c
310 PROPERTIES COMPILE_OPTIONS -msse2)
311 # Add SIMD flags for the bytedelta filter and Intel (it seems that ARM64 does not need these)
312 set_source_files_properties(
313 ${PROJECT_SOURCE_DIR}/plugins/filters/bytedelta/bytedelta.c
314 PROPERTIES COMPILE_OPTIONS "-mssse3")
315 endif()
316
317 # Define a symbol for the shuffle-dispatch implementation
318 # so it knows SSE2 is supported even though that file is
319 # compiled without SSE2 support (for portability).
320 set_property(
321 SOURCE shuffle.c
322 APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_SSE2_ENABLED)
323
324 endif()
325 if(COMPILER_SUPPORT_AVX2)
326 if(MSVC)
327 set_source_files_properties(
328 shuffle-avx2.c bitshuffle-avx2.c
329 PROPERTIES COMPILE_OPTIONS "/arch:AVX2")
330 else()
331 set_source_files_properties(
332 shuffle-avx2.c bitshuffle-avx2.c
333 PROPERTIES COMPILE_OPTIONS -mavx2)
334 endif()
335
336 # Define a symbol for the shuffle-dispatch implementation
337 # so it knows AVX2 is supported even though that file is
338 # compiled without AVX2 support (for portability).
339 set_property(
340 SOURCE shuffle.c
341 APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_AVX2_ENABLED)
342 endif()
343 if(COMPILER_SUPPORT_AVX512)
344 if(MSVC)
345 set_source_files_properties(
346 bitshuffle-avx512.c
347 PROPERTIES COMPILE_OPTIONS "/arch:AVX512")
348 else()
349 set_source_files_properties(
350 bitshuffle-avx512.c
351 PROPERTIES COMPILE_OPTIONS "-mavx512f;-mavx512bw")
352 endif()
353
354 # Define a symbol for the shuffle-dispatch implementation
355 # so it knows AVX512 is supported even though that file is
356 # compiled without AVX512 support (for portability).
357 set_property(
358 SOURCE shuffle.c
359 APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_AVX512_ENABLED)
360 endif()
361 if(COMPILER_SUPPORT_NEON)
362 set_source_files_properties(
363 shuffle-neon.c bitshuffle-neon.c
364 PROPERTIES COMPILE_OPTIONS "-flax-vector-conversions")
365 if(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
366 # Only armv7l needs special -mfpu=neon flag; aarch64 doesn't.
367 set_source_files_properties(
368 shuffle-neon.c bitshuffle-neon.c
369 PROPERTIES COMPILE_OPTIONS "-mfpu=neon;-flax-vector-conversions")
370 endif()
371 # Define a symbol for the shuffle-dispatch implementation
372 # so it knows NEON is supported even though that file is
373 # compiled without NEON support (for portability).
374 set_property(
375 SOURCE shuffle.c
376 APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_NEON_ENABLED)
377 endif()
378 if(COMPILER_SUPPORT_ALTIVEC)
379 set_source_files_properties(
380 shuffle-altivec.c bitshuffle-altivec.c
381 PROPERTIES COMPILE_OPTIONS -DNO_WARN_X86_INTRINSICS)
382 set_property(
383 SOURCE shuffle.c
384 APPEND PROPERTY COMPILE_OPTIONS -DNO_WARN_X86_INTRINSICS)
385
386 # Define a symbol for the shuffle-dispatch implementation
387 # so it knows ALTIVEC is supported even though that file is
388 # compiled without ALTIVEC support (for portability).
389 set_property(
390 SOURCE shuffle.c
391 APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_ALTIVEC_ENABLED)
392 endif()
393
394 # add libraries for dependencies that are not CMake targets
395 if(BUILD_SHARED)
396 target_link_libraries(blosc2_shared PUBLIC ${LIBS})
397 target_include_directories(blosc2_shared PUBLIC ${BLOSC_INCLUDE_DIRS})
398 endif()
399
400 if(BUILD_STATIC)
401 target_link_libraries(blosc2_static PUBLIC ${LIBS})
402 target_include_directories(blosc2_static PUBLIC ${BLOSC_INCLUDE_DIRS})
403 endif()
404
405 if(BUILD_TESTS)
406 target_link_libraries(blosc_testing PUBLIC ${LIBS})
407 target_include_directories(blosc_testing PUBLIC ${BLOSC_INCLUDE_DIRS})
408 endif()
409
410 # we use this variable in the CMake file one directory above ours
411 set(SOURCES ${SOURCES} PARENT_SCOPE)