Skip to content

Commit

Permalink
Merge pull request #933 from SpaceIm/add-c-blosc-1.17.1
Browse files Browse the repository at this point in the history
add c-blosc/1.17.1
  • Loading branch information
danimtb authored Mar 2, 2020
2 parents 536cbe6 + 3abb616 commit 57f0405
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/c-blosc/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1.2)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory("source_subfolder")
8 changes: 8 additions & 0 deletions recipes/c-blosc/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"1.17.1":
url: "https://github.com/Blosc/c-blosc/archive/v1.17.1.tar.gz"
sha256: "19a6948b579c27e8ac440b4f077f99fc90e7292b1d9cb896bec0fd781d68fba2"
patches:
"1.17.1":
- patch_file: "patches/cmake-dependencies_and_cxx_linker.patch"
base_path: "source_subfolder"
108 changes: 108 additions & 0 deletions recipes/c-blosc/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import os

from conans import ConanFile, CMake, tools

class CbloscConan(ConanFile):
name = "c-blosc"
description = "An extremely fast, multi-threaded, meta-compressor library."
license = "BSD-3-Clause"
topics = ("conan", "c-blosc", "blosc", "compression")
homepage = "https://github.com/Blosc/c-blosc"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_lz4": [True, False],
"with_snappy": [True, False],
"with_zlib": [True, False],
"with_zstd": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_lz4": True,
"with_snappy": True,
"with_zlib": True,
"with_zstd": True
}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
del self.settings.compiler.cppstd
# Snappy is a C++ library with C API. C-Blosc only uses the C API of
# Snappy, but if C-Blosc is shared (and snappy static), we have to use
# C++ linker.
if not (self.options.with_snappy and self.options.shared):
del self.settings.compiler.libcxx

def requirements(self):
if self.options.with_lz4:
self.requires.add("lz4/1.9.2")
if self.options.with_snappy:
self.requires.add("snappy/1.1.7")
if self.options.with_zlib:
self.requires.add("zlib/1.2.11")
if self.options.with_zstd:
self.requires.add("zstd/1.4.4")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename(self.name + "-" + self.version, self._source_subfolder)

def build(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BLOSC_INSTALL"] = True
self._cmake.definitions["BUILD_STATIC"] = not self.options.shared
self._cmake.definitions["BUILD_SHARED"] = self.options.shared
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_BENCHMARKS"] = False
self._cmake.definitions["DEACTIVATE_SSE2"] = False
self._cmake.definitions["DEACTIVATE_AVX2"] = False
self._cmake.definitions["DEACTIVATE_LZ4"] = not self.options.with_lz4
self._cmake.definitions["DEACTIVATE_SNAPPY"] = not self.options.with_snappy
self._cmake.definitions["DEACTIVATE_ZLIB"] = not self.options.with_zlib
self._cmake.definitions["DEACTIVATE_ZSTD"] = not self.options.with_zstd
self._cmake.definitions["DEACTIVATE_SYMBOLS_CHECK"] = True
self._cmake.definitions["PREFER_EXTERNAL_LZ4"] = True
self._cmake.definitions["PREFER_EXTERNAL_SNAPPY"] = True
self._cmake.definitions["PREFER_EXTERNAL_ZLIB"] = True
self._cmake.definitions["PREFER_EXTERNAL_ZSTD"] = True
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
licenses = ["BLOSC.txt", "BITSHUFFLE.txt", "FASTLZ.txt"]
for license_file in licenses:
self.copy(license_file, dst="licenses", src=os.path.join(self._source_subfolder, "LICENSES"))
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("pthread")
155 changes: 155 additions & 0 deletions recipes/c-blosc/all/patches/cmake-dependencies_and_cxx_linker.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -126,51 +126,18 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")


if(NOT DEACTIVATE_LZ4)
- if(PREFER_EXTERNAL_LZ4)
- find_package(LZ4)
- else()
- message(STATUS "Using LZ4 internal sources.")
- endif(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 DEACTIVATE_LZ4)

if(NOT DEACTIVATE_SNAPPY)
- if(PREFER_EXTERNAL_SNAPPY)
- find_package(Snappy)
- else()
- message(STATUS "Using Snappy internal sources.")
- endif(PREFER_EXTERNAL_SNAPPY)
- # HAVE_SNAPPY will be set to true because even if the library is not found,
- # we will use the included sources for it
set(HAVE_SNAPPY TRUE)
endif(NOT DEACTIVATE_SNAPPY)

if(NOT DEACTIVATE_ZLIB)
- # import the ZLIB_ROOT environment variable to help finding the zlib library
- if(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(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 DEACTIVATE_ZLIB)

if (NOT DEACTIVATE_ZSTD)
- if (PREFER_EXTERNAL_ZSTD)
- find_package(Zstd)
- else ()
- message(STATUS "Using ZSTD internal sources.")
- endif (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 DEACTIVATE_ZSTD)

--- a/blosc/CMakeLists.txt
+++ b/blosc/CMakeLists.txt
@@ -10,41 +10,6 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)

# includes
set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
-if(NOT DEACTIVATE_LZ4)
- if (LZ4_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_INCLUDE_DIR})
- else(LZ4_FOUND)
- set(LZ4_LOCAL_DIR ${INTERNAL_LIBS}/lz4-1.9.2)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${LZ4_LOCAL_DIR})
- endif(LZ4_FOUND)
-endif(NOT DEACTIVATE_LZ4)
-
-if(NOT DEACTIVATE_SNAPPY)
- if (SNAPPY_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_INCLUDE_DIR})
- else(SNAPPY_FOUND)
- set(SNAPPY_LOCAL_DIR ${INTERNAL_LIBS}/snappy-1.1.1)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${SNAPPY_LOCAL_DIR})
- endif(SNAPPY_FOUND)
-endif(NOT DEACTIVATE_SNAPPY)
-
-if(NOT DEACTIVATE_ZLIB)
- if (ZLIB_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR})
- else(ZLIB_FOUND)
- set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/zlib-1.2.8)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZLIB_LOCAL_DIR})
- endif(ZLIB_FOUND)
-endif(NOT DEACTIVATE_ZLIB)
-
-if (NOT DEACTIVATE_ZSTD)
- if (ZSTD_FOUND)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIR})
- else (ZSTD_FOUND)
- set(ZSTD_LOCAL_DIR ${INTERNAL_LIBS}/zstd-1.4.4)
- set(BLOSC_INCLUDE_DIRS ${BLOSC_INCLUDE_DIRS} ${ZSTD_LOCAL_DIR} ${ZSTD_LOCAL_DIR}/common)
- endif (ZSTD_FOUND)
-endif (NOT DEACTIVATE_ZSTD)

include_directories(${BLOSC_INCLUDE_DIRS})

@@ -81,42 +46,19 @@ else(WIN32)
endif(WIN32)

if(NOT DEACTIVATE_LZ4)
- if(LZ4_FOUND)
- set(LIBS ${LIBS} ${LZ4_LIBRARY})
- else(LZ4_FOUND)
- file(GLOB LZ4_FILES ${LZ4_LOCAL_DIR}/*.c)
- set(SOURCES ${SOURCES} ${LZ4_FILES})
- endif(LZ4_FOUND)
+ set(LIBS ${LIBS} "CONAN_PKG::lz4")
endif(NOT DEACTIVATE_LZ4)

if(NOT DEACTIVATE_SNAPPY)
- if(SNAPPY_FOUND)
- set(LIBS ${LIBS} ${SNAPPY_LIBRARY})
- else(SNAPPY_FOUND)
- file(GLOB SNAPPY_FILES ${SNAPPY_LOCAL_DIR}/*.cc)
- set(SOURCES ${SOURCES} ${SNAPPY_FILES})
- endif(SNAPPY_FOUND)
+ set(LIBS ${LIBS} "CONAN_PKG::snappy")
endif(NOT DEACTIVATE_SNAPPY)

if(NOT DEACTIVATE_ZLIB)
- if(ZLIB_FOUND)
- set(LIBS ${LIBS} ${ZLIB_LIBRARY})
- else(ZLIB_FOUND)
- file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c)
- set(SOURCES ${SOURCES} ${ZLIB_FILES})
- endif(ZLIB_FOUND)
+ set(LIBS ${LIBS} "CONAN_PKG::zlib")
endif(NOT DEACTIVATE_ZLIB)

if (NOT DEACTIVATE_ZSTD)
- if (ZSTD_FOUND)
- set(LIBS ${LIBS} ${ZSTD_LIBRARY})
- else (ZSTD_FOUND)
- file(GLOB ZSTD_FILES
- ${ZSTD_LOCAL_DIR}/common/*.c
- ${ZSTD_LOCAL_DIR}/compress/*.c
- ${ZSTD_LOCAL_DIR}/decompress/*.c)
- set(SOURCES ${SOURCES} ${ZSTD_FILES})
- endif (ZSTD_FOUND)
+ set(LIBS ${LIBS} "CONAN_PKG::zstd")
endif (NOT DEACTIVATE_ZSTD)


@@ -193,6 +135,9 @@ endif()

if (BUILD_SHARED)
target_link_libraries(blosc_shared ${LIBS})
+ if(NOT DEACTIVATE_SNAPPY)
+ set_target_properties(blosc_shared PROPERTIES LINKER_LANGUAGE CXX)
+ endif()
target_include_directories(blosc_shared PUBLIC ${BLOSC_INCLUDE_DIRS})
endif()

9 changes: 9 additions & 0 deletions recipes/c-blosc/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.0.2)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) # only required if both Blosc and Snappy are static
17 changes: 17 additions & 0 deletions recipes/c-blosc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
79 changes: 79 additions & 0 deletions recipes/c-blosc/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright (C) 2014 Francesc Alted
http://blosc.org
License: MIT (see LICENSE.txt)
Example program demonstrating use of the Blosc filter from C code.
To compile this program:
$ gcc simple.c -o simple -lblosc
or, if you don't have the blosc library installed:
$ gcc -O3 -msse2 simple.c -I../blosc -o simple -L../build/blosc
Using MSVC on Windows:
$ cl /arch:SSE2 /Ox /Fesimple.exe /Iblosc examples\simple.c blosc\blosc.c blosc\blosclz.c blosc\shuffle.c blosc\shuffle-sse2.c blosc\shuffle-generic.c blosc\bitshuffle-generic.c blosc\bitshuffle-sse2.c
To run:
$ ./simple
Blosc version info: 1.4.2.dev ($Date:: 2014-07-08 #$)
Compression: 4000000 -> 158494 (25.2x)
Decompression succesful!
Succesful roundtrip!
*/

#include <blosc.h>

#include <stdio.h>

#define SIZE 100*100*100

int main(){
static float data[SIZE];
static float data_out[SIZE];
static float data_dest[SIZE];
int isize = SIZE*sizeof(float), osize = SIZE*sizeof(float);
int dsize = SIZE*sizeof(float), csize;
int i;

for(i=0; i<SIZE; i++){
data[i] = i;
}

/* Register the filter with the library */
printf("Blosc version info: %s (%s)\n",
BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);

/* Initialize the Blosc compressor */
blosc_init();

/* Compress with clevel=5 and shuffle active */
csize = blosc_compress(5, 1, sizeof(float), isize, data, data_out, osize);
if (csize == 0) {
printf("Buffer is uncompressible. Giving up.\n");
return 1;
}
else if (csize < 0) {
printf("Compression error. Error code: %d\n", csize);
return csize;
}

printf("Compression: %d -> %d (%.1fx)\n", isize, csize, (1.*isize) / csize);

/* Decompress */
dsize = blosc_decompress(data_out, data_dest, dsize);
if (dsize < 0) {
printf("Decompression error. Error code: %d\n", dsize);
return dsize;
}

printf("Decompression succesful!\n");

/* After using it, destroy the Blosc environment */
blosc_destroy();

for(i=0;i<SIZE;i++){
if(data[i] != data_dest[i]) {
printf("Decompressed data differs from original!\n");
return -1;
}
}

printf("Succesful roundtrip!\n");
return 0;
}
3 changes: 3 additions & 0 deletions recipes/c-blosc/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.17.1":
folder: all

0 comments on commit 57f0405

Please sign in to comment.