{% set version = "0.5.5" %}

# This package builds 2 outputs
#    zfp     --- C headers
#    zfpy    --- Python package
#
# The build procedure actually rebuilds zfp when zfpy is being built
# during the install phase, conda will simply ignore all the files
# that are being copied related to zfp since they already exist in the prefix

package:
  name: zfp
  version: {{ version }}

source:
  url: https://github.com/LLNL/zfp/archive/{{ version }}.tar.gz
  sha256: 6a7f4934489087d9c117a4af327fd6495ea757924f4df467b9c537abf8bd86c4
  patches:
    # https://github.com/scikit-build/scikit-build/issues/506
    - 100-update-cmake.patch
    # https://github.com/LLNL/zfp/pull/109
    # This patch just isn't working. we do it manually in the build script
    # It is a pretty easy fix, so hopefully upstream will accept it soon
    # - 109-avoid-importing-cpython-array.patch

build:
  number: 5
  script: source ${RECIPE_DIR}/build_zfp.sh  # [unix]
  script: {{ RECIPE_DIR }}\bld_zfp.bat       # [win]
  run_exports:
    # No real information, for now, let keep the defaults
    - {{ pin_subpackage('zfp') }}
  rpaths:
    - lib/  # [unix]

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - cmake
    - make     # [unix]
    - ninja    # [win]
    - libgomp  # [linux]
    - llvm-openmp  # [osx]

test:
  commands:
    - test -f $PREFIX/include/zfp.h                # [unix]
    - test -f ${PREFIX}/lib/cmake/zfp/zfp-config.cmake  # [unix]
    - if not exist %LIBRARY_INC%\zfp.h exit 1      # [win]
    - test -f $PREFIX/lib/libzfp.so.{{ version }}  # [linux]
    - test -f $PREFIX/lib/libzfp${SHLIB_EXT}       # [unix]
    - if not exist %LIBRARY_BIN%\zfp.dll exit 1    # [win]
    - if not exist %LIBRARY_LIB%\zfp.lib exit 1    # [win]
    - if not exist %LIBRARY_PREFIX%\lib\cmake\zfp\zfp-config.cmake exit 1  # [win]
    # Command always returns 1
    - which zfp  # [unix]
    - where zfp  # [win]

outputs:
  - name: zfp
  - name: zfpy
    build:
      script: source ${RECIPE_DIR}/build_zfpy.sh  # [unix]
      script: {{ RECIPE_DIR }}\bld_zfpy.bat       # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - cmake
        - make     # [unix]
        - ninja    # [win]
        - python                                 # [build_platform != target_platform]
        - cross-python_{{ target_platform }}     # [build_platform != target_platform]
        - cython                                 # [build_platform != target_platform]
        - numpy                                  # [build_platform != target_platform]
      host:
        - python
        - numpy
        - cython
        - {{ pin_subpackage('zfp', exact=True) }}
      run:
        - python
        - {{ pin_compatible('numpy') }}
        # I don't think run exports work with pin exact subpackage
        - {{ pin_subpackage('zfp', exact=True) }}
    test:
      imports:
        - zfpy

about:
  home: https://computation.llnl.gov/projects/floating-point-compression
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE
  summary: 'Library for compressed numerical arrays that support high throughput read and write random access'
  description: |
    zfp is an open source C/C++ library for compressed numerical arrays
    that support high throughput read and write random access. zfp also
    supports streaming compression of integer and floating-point data,
    e.g., for applications that read and write large data sets to and
    from disk. zfp is primarily written in C and C++ but also includes
    Python and Fortran bindings.
  doc_url: http://zfp.readthedocs.io/en/release0.5.5/
  dev_url: https://github.com/LLNL/zfp

extra:
  recipe-maintainers:
    - kmpaul
    - ToreAad
    - lindstro
    - GarrettDMorrison
    - hmaarrfk
