Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FetchContent for zlib-ng #544

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,20 @@ if(NOT DEACTIVATE_ZLIB)
endif()

if(NOT (ZLIB_NG_FOUND OR ZLIB_FOUND))
message(STATUS "Using ZLIB-NG internal sources for ZLIB support.")
set(HAVE_ZLIB_NG TRUE)
add_definitions(-DZLIB_COMPAT)
set(ZLIB_NG_DIR "zlib-ng-2.0.7") # update to the actual included version
set(ZLIB_COMPAT TRUE)
set(SKIP_INSTALL_ALL TRUE)
set(BUILD_SHARED_LIBS FALSE)
set(ZLIB_ENABLE_TESTS OFF)
add_subdirectory("internal-complibs/${ZLIB_NG_DIR}")

file(COPY
${CMAKE_CURRENT_BINARY_DIR}/internal-complibs/${ZLIB_NG_DIR}/zconf.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/internal-complibs/${ZLIB_NG_DIR}/)
message(STATUS "Using ZLIB-NG external sources for ZLIB support.")
include(FetchContent)
FetchContent_Declare(z-ng
GIT_REPOSITORY https://github.com/zlib-ng/zlib-ng
GIT_TAG 2.1.3
SOURCE_DIR ${PROJECT_BINARY_DIR}/blosc2-internal-complibs/zlib-ng
BUILD_IN_SOURCE 0
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(BUILD_SHARED_LIBS "" OFF)
option(ZLIB_COMPAT "" ON)
option(ZLIB_ENABLE_TESTS "" OFF)
option(ZLIBNG_ENABLE_TESTS "" OFF)
FetchContent_MakeAvailable(z-ng)
endif()
set(HAVE_ZLIB TRUE)
endif()
Expand Down Expand Up @@ -492,6 +493,18 @@ if(BLOSC_INSTALL)
if(BUILD_STATIC)
list(APPEND Blosc2_INSTALL_TARGET_NAMES blosc2_static)
endif()
# internal zlib-ng aka superbuild
# work-around: zlib-ng does not export its target to the build
# tree yet
if(NOT DEACTIVATE_ZLIB)
if(NOT ZLIB_NG_FOUND AND NOT ZLIB_FOUND)
if(TARGET zlib)
list(APPEND Blosc2_INSTALL_TARGET_NAMES zlib)
elseif(TARGET zlibstatic)
list(APPEND Blosc2_INSTALL_TARGET_NAMES zlibstatic)
endif()
endif()
endif()
configure_file(
${PROJECT_SOURCE_DIR}/Blosc2Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/Blosc2Config.cmake
Expand Down
53 changes: 19 additions & 34 deletions blosc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,37 +104,27 @@ endif()

if(NOT DEACTIVATE_ZLIB)
if(ZLIB_NG_FOUND)
if(BUILD_SHARED)
target_link_libraries(blosc2_shared PUBLIC ZLIB_NG::ZLIB_NG)
endif()
if(BUILD_STATIC)
target_link_libraries(blosc2_static PUBLIC ZLIB_NG::ZLIB_NG)
endif()
if(BUILD_TESTS)
target_link_libraries(blosc_testing PUBLIC ZLIB_NG::ZLIB_NG)
endif()
set(ZLIB_TARGET ZLIB_NG::ZLIB_NG)
elseif(ZLIB_FOUND)
if(BUILD_SHARED)
target_link_libraries(blosc2_shared PUBLIC ZLIB::ZLIB)
endif()
if(BUILD_STATIC)
target_link_libraries(blosc2_static PUBLIC ZLIB::ZLIB)
endif()
if(BUILD_TESTS)
target_link_libraries(blosc_testing PUBLIC ZLIB::ZLIB)
endif()
else()
set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR})
if(BUILD_SHARED)
target_include_directories(blosc2_shared PRIVATE ${ZLIB_LOCAL_DIR})
endif()
if(BUILD_STATIC)
target_include_directories(blosc2_static PRIVATE ${ZLIB_LOCAL_DIR})
endif()
if(BUILD_TESTS)
target_include_directories(blosc_testing PRIVATE ${ZLIB_LOCAL_DIR})
set(ZLIB_TARGET ZLIB::ZLIB)
else() # internal aka superbuild
if(TARGET zlib)
set(ZLIB_TARGET zlib)
elseif(TARGET zlibstatic)
set(ZLIB_TARGET zlibstatic)
else()
message(FATAL_ERROR "Internally-built zlib-ng library provided no targets.")
endif()
endif()
if(BUILD_SHARED)
target_link_libraries(blosc2_shared PUBLIC ${ZLIB_TARGET})
endif()
if(BUILD_STATIC)
target_link_libraries(blosc2_static PUBLIC ${ZLIB_TARGET})
endif()
if(BUILD_TESTS)
target_link_libraries(blosc_testing PUBLIC ${ZLIB_TARGET})
endif()
endif()

if(NOT DEACTIVATE_ZSTD)
Expand Down Expand Up @@ -203,11 +193,6 @@ if(NOT DEACTIVATE_ZLIB)
set(LIBS ${LIBS} ${ZLIB_NG_LIBRARY})
elseif(ZLIB_FOUND)
set(LIBS ${LIBS} ${ZLIB_LIBRARIES})
else()
set(ZLIB_LOCAL_DIR ${INTERNAL_LIBS}/${ZLIB_NG_DIR})
file(GLOB ZLIB_FILES ${ZLIB_LOCAL_DIR}/*.c)
list(APPEND SOURCES ${ZLIB_FILES})
source_group("Zlib" FILES ${ZLIB_FILES})
endif()
endif()

Expand Down Expand Up @@ -268,7 +253,7 @@ list(APPEND SOURCES
blosc/directories.c
blosc/blosc2-stdio.c
blosc/b2nd.c
blosc/b2nd_utils.c
blosc/b2nd_utils.c
)
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
if(COMPILER_SUPPORT_SSE2)
Expand Down
1 change: 0 additions & 1 deletion internal-complibs/zlib-ng-2.0.7/.shellcheckrc

This file was deleted.

Loading