Skip to content

Commit

Permalink
Merge pull request #10 from JohanMabille/osx
Browse files Browse the repository at this point in the history
Added OSX to travisci
  • Loading branch information
JohanMabille committed Nov 10, 2020
2 parents c819c81 + 306d68f commit 3049b3a
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ matrix:
fast_finish: true
include:
- os: linux
#- os: osx
# osx_image: xcode9
# compiler: clang
- os: osx
osx_image: xcode9
compiler: clang
env:
global:
- MINCONDA_VERSION="latest"
Expand Down
67 changes: 47 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ message(STATUS "Building xtensor-zarr v${${PROJECT_NAME}_VERSION}")
# Dependencies
# ============

# Use development version of xtensor and xtensor-io for now
find_package(xtensor-io 0.10.1 REQUIRED)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")

find_package(nlohmann_json 3.2.0 REQUIRED)

find_package(xtensor-io 0.10.1 REQUIRED)
message(STATUS "Found xtensor: ${xtensor_INCLUDE_DIRS}/xtensor")

#Remove the following lines when xtensor-io is fixed
Expand All @@ -44,38 +45,64 @@ find_dependency(xtl REQUIRED)
# =====

set(XTENSOR_ZARR_HEADERS
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor-zarr.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_hierarchy.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_node.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_group.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_array.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_file_system_store.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_gcs_store.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_common.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_compressor.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_chunked_array.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor-zarr.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_hierarchy.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_node.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_group.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_array.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_file_system_store.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_gcs_store.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_common.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_compressor.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xzarr_chunked_array.hpp
${XTENSOR_ZARR_INCLUDE_DIR}/xtensor-zarr/xtensor_zarr_config.hpp
)

OPTION(BUILD_TESTS "xtensor-zarr test suite" OFF)
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
OPTION(DOWNLOAD_GBENCHMARK "download google benchmark and build from source" ON)

add_library(xtensor-zarr INTERFACE)

include_directories(${GTEST_INCLUDE_DIRS})
target_link_libraries(xtensor-zarr INTERFACE xtensor-io)

target_include_directories(xtensor-zarr
INTERFACE
$<BUILD_INTERFACE:${XTENSOR_ZARR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(xtensor-zarr
INTERFACE
xtensor-io
nlohmann_json::nlohmann_json
)
message(STATUS "Trying to find Blosc for Blosc file support")
find_package(Blosc)
if (${Blosc_FOUND})
message(STATUS "Blosc found, Blosc file support enabled")
include_directories(${Blosc_INCLUDE_DIRS})
target_include_directories(xtensor-zarr
INTERFACE
$<BUILD_INTERFACE:${Blosc_INCLUDE_DIRS}>
)
target_link_libraries(xtensor-zarr
INTERFACE
${Blosc_LIBRARIES}
)
else()
message(WARNING "Blosc not found - install blosc for Blosc file support")
endif()

find_package(storage_client)
message(STATUS "Trying to find Google Cloud Storage for GCS IO handler support")
if(${storage_client_FOUND})
message(STATUS "storage_client ${storage_client_VERSION} found, GCS IO handler support enabled")
target_include_directories(xtensor-zarr
INTERFACE
${storage_client_INCLUDE_DIRS}
)
target_link_libraries(xtensor-zarr
INTERFACE
storage_client
)
else()
message(WARNING "Google Cloud Storage not found - install google-cloud-cpp for GCS IO handler support")
endif()

if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
set(BUILD_TESTS ON)
Expand Down
251 changes: 251 additions & 0 deletions cmake/FindBlosc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# Copyright Contributors to the OpenVDB Project
# SPDX-License-Identifier: MPL-2.0
#
#[=======================================================================[.rst:

FindBlosc
---------

Find Blosc include dirs and libraries

Use this module by invoking find_package with the form::

find_package(Blosc
[version] [EXACT] # Minimum or EXACT version e.g. 1.5.0
[REQUIRED] # Fail with error if Blosc is not found
)

IMPORTED Targets
^^^^^^^^^^^^^^^^

``Blosc::blosc``
This module defines IMPORTED target Blosc::Blosc, if Blosc has been found.

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables:

``Blosc_FOUND``
True if the system has the Blosc library.
``Blosc_VERSION``
The version of the Blosc library which was found.
``Blosc_INCLUDE_DIRS``
Include directories needed to use Blosc.
``Blosc_LIBRARIES``
Libraries needed to link to Blosc.
``Blosc_LIBRARY_DIRS``
Blosc library directories.

Cache Variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``Blosc_INCLUDE_DIR``
The directory containing ``blosc.h``.
``Blosc_LIBRARY``
The path to the Blosc library.

Hints
^^^^^

Instead of explicitly setting the cache variables, the following variables
may be provided to tell this module where to look.

``Blosc_ROOT``
Preferred installation prefix.
``BLOSC_INCLUDEDIR``
Preferred include directory e.g. <prefix>/include
``BLOSC_LIBRARYDIR``
Preferred library directory e.g. <prefix>/lib
``SYSTEM_LIBRARY_PATHS``
Global list of library paths intended to be searched by and find_xxx call
``BLOSC_USE_STATIC_LIBS``
Only search for static blosc libraries
``BLOSC_USE_EXTERNAL_SOURCES``
Set to ON if Blosc has been built using external sources for LZ4, snappy,
zlib and zstd. Default is OFF.
``DISABLE_CMAKE_SEARCH_PATHS``
Disable CMakes default search paths for find_xxx calls in this module

#]=======================================================================]

cmake_minimum_required(VERSION 3.3)
include(GNUInstallDirs)

# Monitoring <PackageName>_ROOT variables
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()

mark_as_advanced(
Blosc_INCLUDE_DIR
Blosc_LIBRARY
)

set(_FIND_BLOSC_ADDITIONAL_OPTIONS "")
if(DISABLE_CMAKE_SEARCH_PATHS)
set(_FIND_BLOSC_ADDITIONAL_OPTIONS NO_DEFAULT_PATH)
endif()

# Set _BLOSC_ROOT based on a user provided root var. Xxx_ROOT and ENV{Xxx_ROOT}
# are prioritised over the legacy capitalized XXX_ROOT variables for matching
# CMake 3.12 behaviour
# @todo deprecate -D and ENV BLOSC_ROOT from CMake 3.12
if(Blosc_ROOT)
set(_BLOSC_ROOT ${Blosc_ROOT})
elseif(DEFINED ENV{Blosc_ROOT})
set(_BLOSC_ROOT $ENV{Blosc_ROOT})
elseif(BLOSC_ROOT)
set(_BLOSC_ROOT ${BLOSC_ROOT})
elseif(DEFINED ENV{BLOSC_ROOT})
set(_BLOSC_ROOT $ENV{BLOSC_ROOT})
endif()

# Additionally try and use pkconfig to find blosc
if(USE_PKGCONFIG)
if(NOT DEFINED PKG_CONFIG_FOUND)
find_package(PkgConfig)
endif()
pkg_check_modules(PC_Blosc QUIET blosc)
endif()

# ------------------------------------------------------------------------
# Search for blosc include DIR
# ------------------------------------------------------------------------

set(_BLOSC_INCLUDE_SEARCH_DIRS "")
list(APPEND _BLOSC_INCLUDE_SEARCH_DIRS
${BLOSC_INCLUDEDIR}
${_BLOSC_ROOT}
${PC_Blosc_INCLUDE_DIRS}
${SYSTEM_LIBRARY_PATHS}
)

# Look for a standard blosc header file.
find_path(Blosc_INCLUDE_DIR blosc.h
${_FIND_BLOSC_ADDITIONAL_OPTIONS}
PATHS ${_BLOSC_INCLUDE_SEARCH_DIRS}
PATH_SUFFIXES ${CMAKE_INSTALL_INCLUDEDIR} include
)

if(EXISTS "${Blosc_INCLUDE_DIR}/blosc.h")
file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h"
_blosc_version_major_string REGEX "#define BLOSC_VERSION_MAJOR +[0-9]+ "
)
string(REGEX REPLACE "#define BLOSC_VERSION_MAJOR +([0-9]+).*$" "\\1"
_blosc_version_major_string "${_blosc_version_major_string}"
)
string(STRIP "${_blosc_version_major_string}" Blosc_VERSION_MAJOR)

file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h"
_blosc_version_minor_string REGEX "#define BLOSC_VERSION_MINOR +[0-9]+ "
)
string(REGEX REPLACE "#define BLOSC_VERSION_MINOR +([0-9]+).*$" "\\1"
_blosc_version_minor_string "${_blosc_version_minor_string}"
)
string(STRIP "${_blosc_version_minor_string}" Blosc_VERSION_MINOR)

unset(_blosc_version_major_string)
unset(_blosc_version_minor_string)

set(Blosc_VERSION ${Blosc_VERSION_MAJOR}.${Blosc_VERSION_MINOR})
endif()

# ------------------------------------------------------------------------
# Search for blosc lib DIR
# ------------------------------------------------------------------------

set(_BLOSC_LIBRARYDIR_SEARCH_DIRS "")
list(APPEND _BLOSC_LIBRARYDIR_SEARCH_DIRS
${BLOSC_LIBRARYDIR}
${_BLOSC_ROOT}
${PC_Blosc_LIBRARY_DIRS}
${SYSTEM_LIBRARY_PATHS}
)

# Library suffix handling

set(_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})

if(WIN32)
if(BLOSC_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
endif()
else()
if(BLOSC_USE_STATIC_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
endif()

# libblosc is the name of the blosc static lib on windows

find_library(Blosc_LIBRARY blosc libblosc
${_FIND_BLOSC_ADDITIONAL_OPTIONS}
PATHS ${_BLOSC_LIBRARYDIR_SEARCH_DIRS}
PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} lib64 lib
)

# Reset library suffix

set(CMAKE_FIND_LIBRARY_SUFFIXES ${_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
unset(_BLOSC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)

# ------------------------------------------------------------------------
# Cache and set Blosc_FOUND
# ------------------------------------------------------------------------

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Blosc
FOUND_VAR Blosc_FOUND
REQUIRED_VARS
Blosc_LIBRARY
Blosc_INCLUDE_DIR
VERSION_VAR Blosc_VERSION
)

if(Blosc_FOUND)
# Configure lib type. If XXX_USE_STATIC_LIBS, we always assume a static
# lib is in use. If win32, we can't mark the import .libs as shared, so
# these are always marked as UNKNOWN. Otherwise, infer from extension.
set(BLOSC_LIB_TYPE UNKNOWN)
if(BLOSC_USE_STATIC_LIBS)
set(BLOSC_LIB_TYPE STATIC)
elseif(UNIX)
get_filename_component(_BLOSC_EXT ${Blosc_LIBRARY} EXT)
if(_BLOSC_EXT STREQUAL ".a")
set(BLOSC_LIB_TYPE STATIC)
elseif(_BLOSC_EXT STREQUAL ".so" OR
_BLOSC_EXT STREQUAL ".dylib")
set(BLOSC_LIB_TYPE SHARED)
endif()
endif()

set(Blosc_LIBRARIES ${Blosc_LIBRARY})
set(Blosc_INCLUDE_DIRS ${Blosc_INCLUDE_DIR})

get_filename_component(Blosc_LIBRARY_DIRS ${Blosc_LIBRARY} DIRECTORY)

if(NOT TARGET Blosc::blosc)
add_library(Blosc::blosc ${BLOSC_LIB_TYPE} IMPORTED)
set_target_properties(Blosc::blosc PROPERTIES
IMPORTED_LOCATION "${Blosc_LIBRARIES}"
INTERFACE_COMPILE_OPTIONS "${PC_Blosc_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Blosc_INCLUDE_DIRS}"
)

# Blosc may optionally be compiled with external sources for
# lz4, snappy, zlib and zstd. Add them as interface libs if
# requested (there doesn't seem to be a way to figure this
# out automatically).
if(BLOSC_USE_EXTERNAL_SOURCES)
set_target_properties(Blosc::blosc PROPERTIES
INTERFACE_LINK_DIRECTORIES "${Blosc_LIBRARY_DIRS}"
INTERFACE_LINK_LIBRARIES "lz4;snappy;zlib;zstd"
)
endif()
endif()
elseif(Blosc_FIND_REQUIRED)
message(FATAL_ERROR "Unable to find Blosc")
endif()

0 comments on commit 3049b3a

Please sign in to comment.