python-blosc/use-system-blosc.patch

147 lines
6.5 KiB
Diff
Raw Normal View History

From ae63a9c222f95c898ca3fc0664254f655c5162eb Mon Sep 17 00:00:00 2001
From: Ben Greiner <code@bnavigator.de>
Date: Sat, 13 Feb 2021 18:58:31 +0100
Subject: [PATCH] Reenable possibility to use an already installed C-Blosc
library
---
README.rst | 14 ++++++--------
blosc/CMakeLists.txt | 33 +++++++++++++++++++--------------
cmake/FindBlosc.cmake | 12 ++++++++++++
setup.py | 23 +++++++++++++----------
4 files changed, 50 insertions(+), 32 deletions(-)
create mode 100644 cmake/FindBlosc.cmake
diff --git a/README.rst b/README.rst
index 3329a21..c0385e1 100644
--- a/README.rst
+++ b/README.rst
@@ -79,7 +79,7 @@ Installing via setuptools
.. code-block:: console
$ python -m pip install -r requirements-dev.txt
- $ python setup.py build_ext --inplace
+ $ python setup.py build --inplace
Any codec can be enabled (`=1`) or disabled (`=0`) on this build-path with the appropriate
OS environment variables `INCLUDE_LZ4`, `INCLUDE_SNAPPY`, `INCLUDE_ZLIB`, and
@@ -115,17 +115,15 @@ Using an environment variable:
.. code-block:: console
- $ BLOSC_DIR=/usr/local (or "set BLOSC_DIR=\blosc" on Win)
- $ export BLOSC_DIR (not needed on Win)
- $ python setup.py build_clib
- $ python setup.py build_ext --inplace
+ $ export USE_SYSTEM_BLOSC=1 # or "set USE_SYSTEM_BLOSC=1" on Windows
+ $ export Blosc_ROOT=/usr/local/customprefix # If you installed Blosc into a custom location
+ $ python setup.py build --inplace
-Using a flag:
+Using flags:
.. code-block:: console
- $ python setup.py build_clib
- $ python setup.py build_ext --inplace --blosc=/usr/local
+ $ python setup.py build --inplace -DUSE_SYSTEM_BLOSC:BOOL=YES -DBlosc_ROOT:PATH=/usr/local/customprefix
Testing
diff --git a/blosc/CMakeLists.txt b/blosc/CMakeLists.txt
index 7f06f28..f9a5214 100644
--- a/blosc/CMakeLists.txt
+++ b/blosc/CMakeLists.txt
@@ -1,19 +1,24 @@
-# Todo: c-blosc provides a CMake package configuration file that we can build
-# against if blosc is available on the system, etc.
-# find_package(blosc)
-# if(NOT blosc_FOUND)
-set(BUILD_STATIC ON CACHE BOOL "Build a static version of the blosc library.")
-set(BUILD_SHARED ON CACHE BOOL "Build a shared library version of the blosc library.")
-set(BUILD_TESTS OFF CACHE BOOL "Build test programs form the blosc compression library")
-set(BUILD_BENCHMARKS OFF CACHE BOOL "Build benchmark programs form the blosc compression library")
-set(BLOSC_IS_SUBPROJECT OFF CACHE BOOL "Blosc is subproject")
-set(CMAKE_POSITION_INDEPENDENT_CODE ON)
-add_subdirectory(c-blosc)
-include_directories("${CMAKE_CURRENT_SOURCE_DIR}/c-blosc/blosc")
+add_library(blosc_extension MODULE blosc_extension.c)
+
+if(USE_SYSTEM_BLOSC)
+ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
+ find_package(Blosc REQUIRED)
+ target_include_directories(blosc_extension PRIVATE ${Blosc_INCLUDE_DIRS})
+ target_link_libraries(blosc_extension ${Blosc_LIBRARIES})
+else()
+ set(BUILD_STATIC ON CACHE BOOL "Build a static version of the blosc library.")
+ set(BUILD_SHARED ON CACHE BOOL "Build a shared library version of the blosc library.")
+ set(BUILD_TESTS OFF CACHE BOOL "Build test programs form the blosc compression library")
+ set(BUILD_BENCHMARKS OFF CACHE BOOL "Build benchmark programs form the blosc compression library")
+ set(BLOSC_IS_SUBPROJECT OFF CACHE BOOL "Blosc is subproject")
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+ add_subdirectory(c-blosc)
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/c-blosc/blosc")
+ target_link_libraries(blosc_extension blosc_static)
+endif()
+
-add_library(blosc_extension MODULE blosc_extension.c)
-target_link_libraries(blosc_extension blosc_static)
python_extension_module(blosc_extension)
add_custom_command(
diff --git a/cmake/FindBlosc.cmake b/cmake/FindBlosc.cmake
new file mode 100644
index 0000000..02a039f
--- /dev/null
+++ b/cmake/FindBlosc.cmake
@@ -0,0 +1,12 @@
+find_path(Blosc_INCLUDE_DIR blosc.h)
+
+find_library(Blosc_LIBRARY NAMES blosc)
+
+if (Blosc_INCLUDE_DIR AND Blosc_LIBRARY)
+ set(Blosc_FOUND TRUE)
+ set(Blosc_INCLUDE_DIRS ${Blosc_INCLUDE_DIR})
+ set(Blosc_LIBRARIES ${Blosc_LIBRARY})
+ message(STATUS "Found Blosc library: ${Blosc_LIBRARIES}")
+else ()
+ message(STATUS "No Blosc library found. Using internal sources.")
+endif ()
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 2fd6619..37b5827 100644
--- a/setup.py
+++ b/setup.py
@@ -85,16 +85,19 @@ def cmake_bool(cond):
url = 'http://github.com/blosc/python-blosc',
license = 'https://opensource.org/licenses/BSD-3-Clause',
platforms = ['any'],
- cmake_args = [
- '-DBLOSC_DIR:PATH=%s' % os.environ.get('BLOSC_DIR', ''),
- '-DDEACTIVATE_SSE2:BOOL=%s' % cmake_bool(('DISABLE_BLOSC_SSE2' in os.environ) or (cpu_info is None) or ('sse2' not in cpu_info['flags'])),
- '-DDEACTIVATE_AVX2:BOOL=%s' % cmake_bool(('DISABLE_BLOSC_AVX2' in os.environ) or (cpu_info is None) or ('avx2' not in cpu_info['flags'])),
- '-DDEACTIVATE_LZ4:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_LZ4', '1'))),
- # Snappy is disabled by default
- '-DDEACTIVATE_SNAPPY:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_SNAPPY', '0'))),
- '-DDEACTIVATE_ZLIB:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_ZLIB', '1'))),
- '-DDEACTIVATE_ZSTD:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_ZSTD', '1'))),
- ],
+ cmake_args = (
+ ['-DUSE_SYSTEM_BLOSC:BOOL=ON'] if int(os.environ.get('USE_SYSTEM_BLOSC', '0'))
+ else
+ ['-DUSE_SYSTEM_BLOSC:BOOL=OFF',
+ '-DDEACTIVATE_SSE2:BOOL=%s' % cmake_bool(('DISABLE_BLOSC_SSE2' in os.environ) or (cpu_info is None) or ('sse2' not in cpu_info['flags'])),
+ '-DDEACTIVATE_AVX2:BOOL=%s' % cmake_bool(('DISABLE_BLOSC_AVX2' in os.environ) or (cpu_info is None) or ('avx2' not in cpu_info['flags'])),
+ '-DDEACTIVATE_LZ4:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_LZ4', '1'))),
+ # Snappy is disabled by default
+ '-DDEACTIVATE_SNAPPY:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_SNAPPY', '0'))),
+ '-DDEACTIVATE_ZLIB:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_ZLIB', '1'))),
+ '-DDEACTIVATE_ZSTD:BOOL=%s' % cmake_bool(not int(os.environ.get('INCLUDE_ZSTD', '1'))),
+ ]
+ ),
setup_requires=['scikit-build'],
tests_require=['numpy', 'psutil'],
packages = ['blosc'],