-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCMakeLists.txt
65 lines (59 loc) · 2.67 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
cmake_minimum_required(VERSION 3.15.0)
project(python-blosc2)
# Specifying Python version below is tricky, but if you don't specify the minimum version here,
# it would not consider python3 when looking for the executable. This is problematic since Fedora
# does not include a python symbolic link to python3.
# find_package(Python 3.12 COMPONENTS Interpreter NumPy Development.Module REQUIRED)
# IMO, this would need to be solved in Fedora, so we can just use the following line:
find_package(Python COMPONENTS Interpreter NumPy Development.Module REQUIRED)
# Add custom command to generate the version file
add_custom_command(
OUTPUT src/blosc2/version.py
COMMAND ${Python_EXECUTABLE} generate_version.py
DEPENDS generate_version.py pyproject.toml
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
# Compile the Cython extension manually...
add_custom_command(
OUTPUT blosc2_ext.c
COMMAND Python::Interpreter -m cython
"${CMAKE_CURRENT_SOURCE_DIR}/src/blosc2/blosc2_ext.pyx" --output-file blosc2_ext.c
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/blosc2/blosc2_ext.pyx"
VERBATIM)
# ...and add it to the target
Python_add_library(blosc2_ext MODULE blosc2_ext.c WITH_SOABI)
# We need to link against NumPy
target_link_libraries(blosc2_ext PRIVATE Python::NumPy)
if(DEFINED ENV{USE_SYSTEM_BLOSC2})
set(USE_SYSTEM_BLOSC2 ON)
endif()
if(USE_SYSTEM_BLOSC2)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
find_package(PkgConfig REQUIRED)
pkg_check_modules(Blosc2 REQUIRED IMPORTED_TARGET blosc2)
target_link_libraries(blosc2_ext PRIVATE PkgConfig::Blosc2)
else()
set(STATIC_LIB ON CACHE BOOL "Build a static version of the blosc library.")
set(SHARED_LIB ON CACHE BOOL "Build a shared library version of the blosc library.")
set(BUILD_TESTS OFF CACHE BOOL "Build C-Blosc2 tests")
set(BUILD_EXAMPLES OFF CACHE BOOL "Build C-Blosc2 examples")
set(BUILD_BENCHMARKS OFF CACHE BOOL "Build C-Blosc2 benchmarks")
set(BUILD_FUZZERS OFF CACHE BOOL "Build C-Blosc2 fuzzers")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# we want the binaries of the C-Blosc2 library to go into the wheels
set(BLOSC_INSTALL ON)
include(FetchContent)
FetchContent_Declare(blosc2
GIT_REPOSITORY https://github.com/Blosc/c-blosc2
GIT_TAG f1278b90056a99c35592e964f549f1f2ba13f05c
)
FetchContent_MakeAvailable(blosc2)
include_directories("${blosc2_SOURCE_DIR}/include")
target_link_libraries(blosc2_ext PRIVATE blosc2_static)
endif()
add_custom_command(
TARGET blosc2_ext POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:blosc2_ext> ${CMAKE_SOURCE_DIR}/blosc2
)
install(TARGETS blosc2_ext LIBRARY DESTINATION blosc2)