forked from Blosc/c-blosc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
374 lines (335 loc) · 14.7 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# CMake build system for Blosc
# ============================
#
# Available options:
#
# CBLOSC_BUILD_STATIC: default ON
# build the static version of the Blosc library
# CBLOSC_BUILD_SHARED: default ON
# build the shared library version of the Blosc library
# CBLOSC_BUILD_TESTS: default ON
# build test programs and generates the "test" target
# CBLOSC_BUILD_FUZZERS: default ON
# build fuzz test programs and generates the "test" target
# CBLOSC_BUILD_BENCHMARKS: default ON
# build the benchmark program
# CBLOSC_DEACTIVATE_SSE2: default OFF
# do not attempt to build with SSE2 instructions
# CBLOSC_DEACTIVATE_AVX2: default OFF
# do not attempt to build with AVX2 instructions
# CBLOSC_DEACTIVATE_LZ4: default OFF
# do not include support for the LZ4 library
# CBLOSC_DEACTIVATE_SNAPPY: default ON
# do not include support for the Snappy library
# CBLOSC_DEACTIVATE_ZLIB: default OFF
# do not include support for the Zlib library
# CBLOSC_DEACTIVATE_ZSTD: default OFF
# do not include support for the Zstd library
# CBLOSC_DEACTIVATE_SYMBOLS_CHECK: default ON
# do not check for symbols in shared or static libraries
# CBLOSC_PREFER_EXTERNAL_LZ4: default OFF
# when found, use the installed LZ4 libs instead of included
# sources
# CBLOSC_PREFER_EXTERNAL_ZLIB: default OFF
# when found, use the installed zlib libs instead of included
# sources
# CBLOSC_PREFER_EXTERNAL_ZSTD: default OFF
# when found, use the installed zstd libs instead of included
# sources
# CBLOSC_TEST_INCLUDE_BENCH_SHUFFLE_1: default ON
# add a test that runs the benchmark program passing "shuffle" with 1
# thread as second parameter
# CBLOSC_TEST_INCLUDE_BENCH_SHUFFLE_N: default ON
# add a test that runs the benchmark program passing "shuffle" with all
# threads as second parameter
# CBLOSC_TEST_INCLUDE_BENCH_BITSHUFFLE_1: default ON
# add a test that runs the benchmark program passing "bitshuffle" with 1
# thread as second parameter
# CBLOSC_TEST_INCLUDE_BENCH_BITSHUFFLE_N: default ON
# add a test that runs the benchmark program passing "bitshuffle" with
# all threads as second parameter
# CBLOSC_TEST_INCLUDE_BENCH_SUITE: default OFF
# add a test that runs the benchmark program passing "suite"
# as first parameter
# CBLOSC_TEST_INCLUDE_BENCH_SUITE_PARALLEL: default OFF
# add a test that runs the benchmark program passing "parallel"
# as first parameter
# CBLOSC_TEST_INCLUDE_BENCH_HARDSUITE: default OFF
# add a test that runs the benchmark program passing "hardsuite"
# as first parameter
# CBLOSC_TEST_INCLUDE_BENCH_EXTREMESUITE: default OFF
# add a test that runs the benchmark program passing "extremesuite"
# as first parameter
# CBLOSC_TEST_INCLUDE_BENCH_DEBUGSUITE: default OFF
# add a test that runs the benchmark program passing "debugsuite"
# as first parameter
#
# Components:
#
# LIB: includes blosc.so
# DEV: static includes blosc.a and blosc.h
cmake_minimum_required(VERSION 2.8.12)
if (NOT CMAKE_VERSION VERSION_LESS 3.3)
cmake_policy(SET CMP0063 NEW)
endif()
project(blosc C)
# parse the full version numbers from blosc.h
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/blosc/blosc.h _blosc_h_contents)
string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MAJOR[ \t]+([0-9]+).*"
"\\1" BLOSC_VERSION_MAJOR ${_blosc_h_contents})
string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_MINOR[ \t]+([0-9]+).*"
"\\1" BLOSC_VERSION_MINOR ${_blosc_h_contents})
string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_RELEASE[ \t]+([0-9]+).*"
"\\1" BLOSC_VERSION_PATCH ${_blosc_h_contents})
string(REGEX REPLACE ".*#define[ \t]+BLOSC_VERSION_STRING[ \t]+\"([-0-9A-Za-z.]+)\".*"
"\\1" BLOSC_VERSION_STRING ${_blosc_h_contents})
message("Configuring for Blosc version: " ${BLOSC_VERSION_STRING})
# options
option(CBLOSC_BUILD_STATIC
"Build a static version of the blosc library." ON)
option(CBLOSC_BUILD_SHARED
"Build a shared library version of the blosc library." ON)
option(CBLOSC_BUILD_TESTS
"Build test programs from the blosc compression library" ON)
option(CBLOSC_BUILD_FUZZERS
"Build fuzzer programs from the blosc compression library" ${CBLOSC_BUILD_STATIC})
option(CBLOSC_BUILD_BENCHMARKS
"Build benchmark programs from the blosc compression library" ON)
option(CBLOSC_DEACTIVATE_SSE2
"Do not attempt to build with SSE2 instructions" OFF)
option(CBLOSC_DEACTIVATE_AVX2
"Do not attempt to build with AVX2 instructions" OFF)
option(CBLOSC_DEACTIVATE_LZ4
"Do not include support for the LZ4 library." OFF)
option(CBLOSC_DEACTIVATE_SNAPPY
"Do not include support for the Snappy library." ON)
option(CBLOSC_DEACTIVATE_ZLIB
"Do not include support for the Zlib library." OFF)
option(CBLOSC_DEACTIVATE_ZSTD
"Do not include support for the Zstd library." OFF)
option(CBLOSC_DEACTIVATE_SYMBOLS_CHECK
"Do not check for symbols in shared or static libraries." ON)
option(CBLOSC_PREFER_EXTERNAL_LZ4
"Find and use external LZ4 library instead of included sources." OFF)
option(CBLOSC_PREFER_EXTERNAL_ZLIB
"Find and use external Zlib library instead of included sources." OFF)
option(CBLOSC_PREFER_EXTERNAL_ZSTD
"Find and use external Zstd library instead of included sources." OFF)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if(NOT CBLOSC_DEACTIVATE_LZ4)
if(CBLOSC_PREFER_EXTERNAL_LZ4)
find_package(LZ4)
else()
message(STATUS "Using LZ4 internal sources.")
endif(CBLOSC_PREFER_EXTERNAL_LZ4)
# HAVE_LZ4 will be set to true because even if the library is
# not found, we will use the included sources for it
set(HAVE_LZ4 TRUE)
endif(NOT CBLOSC_DEACTIVATE_LZ4)
if(NOT CBLOSC_DEACTIVATE_SNAPPY)
find_package(Snappy)
if(SNAPPY_FOUND)
message(STATUS "Activating support for SNAPPY.")
set(HAVE_SNAPPY TRUE)
else()
message(STATUS "SNAPPY *not* found. De-activating support for it.")
endif()
endif(NOT CBLOSC_DEACTIVATE_SNAPPY)
if(NOT CBLOSC_DEACTIVATE_ZLIB)
# import the ZLIB_ROOT environment variable to help finding the zlib library
if(CBLOSC_PREFER_EXTERNAL_ZLIB)
set(ZLIB_ROOT $ENV{ZLIB_ROOT})
find_package(ZLIB)
if (NOT ZLIB_FOUND )
message(STATUS "No zlib found. Using internal sources.")
endif (NOT ZLIB_FOUND )
else()
message(STATUS "Using zlib internal sources.")
endif(CBLOSC_PREFER_EXTERNAL_ZLIB)
# HAVE_ZLIB will be set to true because even if the library is not found,
# we will use the included sources for it
set(HAVE_ZLIB TRUE)
endif(NOT CBLOSC_DEACTIVATE_ZLIB)
if (NOT CBLOSC_DEACTIVATE_ZSTD)
if (CBLOSC_PREFER_EXTERNAL_ZSTD)
find_package(Zstd)
else ()
message(STATUS "Using ZSTD internal sources.")
endif (CBLOSC_PREFER_EXTERNAL_ZSTD)
# HAVE_ZSTD will be set to true because even if the library is
# not found, we will use the included sources for it
set(HAVE_ZSTD TRUE)
endif (NOT CBLOSC_DEACTIVATE_ZSTD)
# create the config.h file
configure_file ("blosc/config.h.in" "blosc/config.h" )
# now make sure that you set the build directory on your "Include" path when compiling
include_directories("${PROJECT_BINARY_DIR}/blosc/")
# If the build type is not set, default to Release.
set(BLOSC_DEFAULT_BUILD_TYPE Release)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified. Defaulting to '${BLOSC_DEFAULT_BUILD_TYPE}'.")
set(CMAKE_BUILD_TYPE ${BLOSC_DEFAULT_BUILD_TYPE} 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()
if(APPLE)
# enable @rpath in the install name for any shared library being built. See #175.
set(CMAKE_MACOSX_RPATH TRUE)
endif()
# Based on the target system's processor and the compiler being used,
# set build variables indicating which hardware features can be targeted
# by the compiler. Note we DO NOT check which hardware features are supported
# by this (the host) system, because we want to be able to support compiling
# for newer hardware on older machines as well as cross-compilation.
message(STATUS "Building for system processor ${CMAKE_SYSTEM_PROCESSOR}")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL i386 OR
CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR
CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR
CMAKE_SYSTEM_PROCESSOR STREQUAL amd64 OR
CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)
if(CMAKE_C_COMPILER_ID STREQUAL GNU)
# We need C99 (GNU99 more exactly)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(COMPILER_SUPPORT_SSE2 TRUE)
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.7 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.7)
set(COMPILER_SUPPORT_AVX2 TRUE)
else()
set(COMPILER_SUPPORT_AVX2 FALSE)
endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL Clang)
set(COMPILER_SUPPORT_SSE2 TRUE)
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.2 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.2)
set(COMPILER_SUPPORT_AVX2 TRUE)
else()
set(COMPILER_SUPPORT_AVX2 FALSE)
endif()
elseif(CMAKE_C_COMPILER_ID STREQUAL Intel)
set(COMPILER_SUPPORT_SSE2 TRUE)
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0)
set(COMPILER_SUPPORT_AVX2 TRUE)
else()
set(COMPILER_SUPPORT_AVX2 FALSE)
endif()
elseif(MSVC)
set(COMPILER_SUPPORT_SSE2 TRUE)
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 18.00.30501 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 18.00.30501)
set(COMPILER_SUPPORT_AVX2 TRUE)
else()
set(COMPILER_SUPPORT_AVX2 FALSE)
endif()
else()
set(COMPILER_SUPPORT_SSE2 FALSE)
set(COMPILER_SUPPORT_AVX2 FALSE)
# Unrecognized compiler. Emit a warning message to let the user know hardware-acceleration won't be available.
message(WARNING "Unable to determine which ${CMAKE_SYSTEM_PROCESSOR} hardware features are supported by the C compiler (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}).")
endif()
else()
# If the target system processor isn't recognized, emit a warning message to alert the user
# that hardware-acceleration support won't be available but allow configuration to proceed.
message(WARNING "Unrecognized system processor ${CMAKE_SYSTEM_PROCESSOR}. Cannot determine which hardware features (${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}) supports, so hardware-accelerated implementations will not be available.")
endif()
# disable SSE2 if specified (useful for cross-compiling, see #236)
if(CBLOSC_DEACTIVATE_SSE2)
set(COMPILER_SUPPORT_SSE2 FALSE)
endif()
# disable AVX2 if specified or if SSE is deactivated
if(CBLOSC_DEACTIVATE_AVX2 OR CBLOSC_DEACTIVATE_SSE2)
set(COMPILER_SUPPORT_AVX2 FALSE)
endif()
# flags
# Set -Wall and other useful warning flags.
if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
add_compile_options(-Wall -Wwrite-strings -Wno-unused-function)
endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
# @NOTE: -O3 is enabled in Release mode (CMAKE_BUILD_TYPE="Release")
# Set the "-msse2" build flag if supported.
if(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
if(COMPILER_SUPPORT_SSE2)
add_compile_options(-msse2)
endif(COMPILER_SUPPORT_SSE2)
endif(CMAKE_C_COMPILER_ID STREQUAL GNU OR CMAKE_C_COMPILER_ID STREQUAL Clang OR CMAKE_C_COMPILER_ID STREQUAL Intel)
if(MSVC)
if(NOT CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "/Ox" CACHE STRING "C flags." FORCE)
endif(NOT CMAKE_C_FLAGS)
# Turn off misguided "secure CRT" warnings in MSVC.
# Microsoft wants people to use the MS-specific <function>_s
# versions of certain C functions but this is difficult to do
# in platform-independent code.
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
endif(MSVC)
if(WIN32)
# For some supporting headers
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/blosc")
endif(WIN32)
if(HAIKU)
# Haiku have posix_memalign, required by test_common.h
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=200112L")
endif(HAIKU)
if (NOT DEFINED BLOSC_IS_SUBPROJECT)
if ("^${CMAKE_SOURCE_DIR}$" STREQUAL "^${PROJECT_SOURCE_DIR}$")
set (BLOSC_IS_SUBPROJECT FALSE)
else ()
set (BLOSC_IS_SUBPROJECT TRUE)
message(STATUS "Detected that BLOSC is used a subproject.")
endif ()
endif ()
if (NOT DEFINED BLOSC_INSTALL)
if (BLOSC_IS_SUBPROJECT)
set(BLOSC_INSTALL FALSE)
else()
set(BLOSC_INSTALL TRUE)
endif()
endif()
# subdirectories
add_subdirectory(blosc)
if(CBLOSC_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
add_subdirectory(compat)
endif(CBLOSC_BUILD_TESTS)
if(CBLOSC_BUILD_FUZZERS)
if(NOT CBLOSC_BUILD_STATIC)
message(FATAL_ERROR "CBLOSC_BUILD_FUZZERS requires CBLOSC_BUILD_STATIC to be enabled.")
endif()
enable_testing()
add_subdirectory(tests/fuzz)
endif(CBLOSC_BUILD_FUZZERS)
if(CBLOSC_BUILD_BENCHMARKS)
add_subdirectory(bench)
endif(CBLOSC_BUILD_BENCHMARKS)
# uninstall target
if (BLOSC_INSTALL)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/blosc.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/blosc.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/blosc.pc"
DESTINATION lib/pkgconfig COMPONENT DEV)
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()
# packaging
if (NOT BLOSC_IS_SUBPROJECT)
include(InstallRequiredSystemLibraries)
set(CPACK_GENERATOR TGZ ZIP)
set(CPACK_SOURCE_GENERATOR TGZ ZIP)
set(CPACK_PACKAGE_VERSION_MAJOR ${BLOSC_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${BLOSC_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${BLOSC_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${BLOSC_STRING_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"A blocking, shuffling and lossless compression library")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSES/BLOSC.txt")
set(CPACK_SOURCE_IGNORE_FILES "/build.*;.*~;\\\\.git.*;\\\\.DS_Store")
set(CPACK_STRIP_FILES TRUE)
set(CPACK_SOURCE_STRIP_FILES TRUE)
include(CPack)
endif()