|
| 1 | +############################################################################## |
| 2 | +# blosc2-openzl: OpenZL plugin for Blosc2 |
| 3 | +# |
| 4 | +# Copyright (c) 2026 The Blosc Development Team <blosc@blosc.org> |
| 5 | +# https://blosc.org |
| 6 | +# License: GNU Affero General Public License v3.0 (see LICENSE.txt) |
| 7 | +############################################################################## |
| 8 | + |
1 | 9 | cmake_minimum_required(VERSION 3.20) |
2 | | -project(blosc2_openzl LANGUAGES C) |
| 10 | +project(blosc2_openzl LANGUAGES C CXX) # enable CXX just to get openzl to compile |
| 11 | + |
| 12 | +# Build statically |
| 13 | +set(BUILD_SHARED_LIBS OFF) |
| 14 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 15 | +set(CMAKE_FIND_FRAMEWORK NEVER) |
3 | 16 |
|
4 | 17 | include(GNUInstallDirs) |
5 | 18 | include(FetchContent) |
6 | 19 |
|
| 20 | +message("Building Blosc2 plugin...") |
| 21 | + |
| 22 | +# Necessary when calling via cmake (to know which python to call) |
| 23 | +find_package(Python REQUIRED COMPONENTS Interpreter) |
| 24 | + |
| 25 | +# Propagate CMAKE_OSX_ARCHITECTURES env variable into CMAKE_SYSTEM_PROCESSOR |
| 26 | +if(DEFINED ENV{CMAKE_OSX_ARCHITECTURES}) |
| 27 | + if("$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64") |
| 28 | + set(CMAKE_SYSTEM_PROCESSOR arm64) |
| 29 | + endif() |
| 30 | +endif() |
| 31 | + |
7 | 32 | # ============================================================ |
8 | 33 | # Step 1: Find C-Blosc2 |
9 | 34 | # ============================================================ |
10 | | -# Find blosc2.h |
11 | | -find_package(Python COMPONENTS Interpreter NumPy Development.Module REQUIRED) |
12 | | -if (UNIX) |
13 | | - cmake_path(SET Python_ROOT NORMALIZE "${Python_NumPy_INCLUDE_DIRS}/../../..") |
14 | | -else() |
15 | | - cmake_path(SET Python_ROOT NORMALIZE "${Python_NumPy_INCLUDE_DIRS}/../../..") |
16 | | -endif() |
17 | | -cmake_path(SET Python_INCLUDE NORMALIZE "${Python_ROOT}/include") |
18 | | -message(STATUS "Found Python include: ${Python_ROOT}") |
19 | | -cmake_path(SET Python_LIB NORMALIZE "${Python_ROOT}/lib") |
20 | | -cmake_path(SET Python_LIB64 NORMALIZE "${Python_ROOT}/lib64") |
21 | | -cmake_path(SET Python_Blosc2_INCLUDE NORMALIZE "${Python_ROOT}/include/blosc2.h") |
22 | | -cmake_path(HAS_FILENAME Python_Blosc2_INCLUDE HAS_BLOSC2) |
23 | | -if(HAS_BLOSC2) |
24 | | - set(BLOSC2_INCLUDE_DIR ${Python_INCLUDE}) |
25 | | - message(STATUS "Found Blosc2 include: ${Python_Blosc2_INCLUDE}") |
| 35 | +# Find blosc2 package location using Python |
| 36 | +execute_process( |
| 37 | + COMMAND "${Python_EXECUTABLE}" -c "import blosc2, pathlib; print(pathlib.Path(blosc2.__file__).parent)" |
| 38 | + OUTPUT_VARIABLE BLOSC2_PACKAGE_DIR |
| 39 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 40 | + RESULT_VARIABLE BLOSC2_IMPORT_RESULT |
| 41 | +) |
| 42 | + |
| 43 | +# To compile blosc2_openzl, we only need the include files (although in the future may need to link with libblosc2) |
| 44 | +if(BLOSC2_IMPORT_RESULT EQUAL 0 AND EXISTS "${BLOSC2_PACKAGE_DIR}") |
| 45 | + message(STATUS "Found blosc2 package at: ${BLOSC2_PACKAGE_DIR}") |
| 46 | + |
| 47 | + # Try only PEP 427 compliant structure (blosc2/include/) |
| 48 | + set(BLOSC2_INCLUDE_DIR "${BLOSC2_PACKAGE_DIR}/include") |
| 49 | + if(NOT EXISTS "${BLOSC2_INCLUDE_DIR}/blosc2.h") |
| 50 | + message(FATAL_ERROR "blosc2 package found but blosc2.h not found. Tried:\n ${BLOSC2_PACKAGE_DIR}/include") |
| 51 | + else() |
| 52 | + message(STATUS "Found Blosc2 include: ${BLOSC2_INCLUDE_DIR}/blosc2.h") |
| 53 | + endif() |
26 | 54 | else() |
27 | | - message(FATAL_ERROR "No Blosc2 includes found. Aborting.") |
| 55 | + message(FATAL_ERROR "Could not import blosc2 package. Please install it first: pip install blosc2") |
28 | 56 | endif() |
29 | 57 |
|
30 | | -include_directories("${BLOSC2_INCLUDE_DIR}") |
31 | | -link_directories(${Python_LIB}) |
32 | | -if (UNIX AND NOT APPLE) |
33 | | - link_directories(${Python_LIB64}) |
34 | | -endif (UNIX AND NOT APPLE) |
35 | | - |
36 | | -# ============================================================ |
37 | | -# Step 2: Fetch OpenZL (C-only) |
38 | | -# ============================================================ |
39 | | -# Disable everything non-C |
40 | | -set(OPENZL_BUILD_PYTHON_EXT OFF CACHE BOOL "" FORCE) |
41 | | -set(OPENZL_BUILD_TESTS OFF CACHE BOOL "" FORCE) |
42 | | -set(OPENZL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
43 | | -set(OPENZL_INSTALL OFF CACHE BOOL "" FORCE) |
44 | | -set(OPENZL_BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) |
| 58 | +# For the test_openzl executable, we also need the actual blosc2 lib |
| 59 | +# Try only PEP 427 compliant structure (blosc2/lib/) |
| 60 | +set(BLOSC2_LIB_DIR "${BLOSC2_PACKAGE_DIR}/lib") |
| 61 | +if(NOT EXISTS "${BLOSC2_LIB_DIR}") |
| 62 | + message(FATAL_ERROR "blosc2 lib dir not found. Tried:\n ${BLOSC2_PACKAGE_DIR}/lib") |
| 63 | +endif() |
45 | 64 |
|
46 | | -FetchContent_Declare( |
47 | | - openzl |
48 | | - GIT_REPOSITORY https://github.com/facebook/openzl.git |
49 | | - GIT_TAG 4010c5f047441756092b039dcc8cfe7565a91d85 # pin exact version |
| 65 | +find_library(BLOSC2_LIBRARY |
| 66 | + NAMES blosc2 libblosc2 |
| 67 | + PATHS "${BLOSC2_LIB_DIR}" |
| 68 | + NO_DEFAULT_PATH |
50 | 69 | ) |
51 | | -FetchContent_MakeAvailable(openzl) |
52 | 70 |
|
53 | | -# OpenZL target resolution |
54 | | -if(TARGET OpenZL::openzl) |
55 | | - set(OPENZL_TARGET OpenZL::openzl) |
56 | | -elseif(TARGET openzl) |
57 | | - set(OPENZL_TARGET openzl) |
| 71 | +if(BLOSC2_LIBRARY) |
| 72 | + message(STATUS "Found Blosc2 library: ${BLOSC2_LIBRARY}") |
| 73 | + set(BLOSC2_LIBRARIES "${BLOSC2_LIBRARY}") |
| 74 | + get_filename_component(BLOSC2_LIBRARY_DIR_RESOLVED "${BLOSC2_LIBRARY}" DIRECTORY) |
58 | 75 | else() |
59 | | - message(FATAL_ERROR "OpenZL target not found") |
| 76 | + message(FATAL_ERROR "Blosc2 library not found in ${BLOSC2_LIB_DIR}. Please install the blosc2 Python package with bundled libraries.") |
60 | 77 | endif() |
61 | 78 |
|
62 | 79 | # ============================================================ |
63 | | -# Step 3: blosc2_openzl plugin |
| 80 | +# blosc2_openzl plugin source files |
64 | 81 | # ============================================================ |
65 | | - |
66 | 82 | add_subdirectory(src) |
0 commit comments