distributable:
  url: https://github.com/uclouvain/openjpeg/archive/v2.5.0.tar.gz
  strip-components: 1

versions:
  github: uclouvain/openjpeg/tags

dependencies:
  libpng.org: ^1
  simplesystems.org/libtiff: ^4

build:
  dependencies:
    cmake.org: ^3
  working-directory: build
  script: |
    cmake .. -DCMAKE_INSTALL_PREFIX={{prefix}} -DCMAKE_BUILD_TYPE=Release
    make --jobs {{ hw.concurrency }} install

    # fix unecessary prefixification of headers
    cd {{prefix}}/include
    mv openjpeg-{{version.marketing}}/* .
    rmdir openjpeg-{{version.marketing}}
    # keep unecessary prefixification for tools that expect it for some reason
    ln -s . openjpeg-{{version.marketing}}

provides:
  - bin/opj_compress
  - bin/opj_decompress
  - bin/opj_dump

test:
  script: |
    mv $FIXTURE test.c
    cc test.c -lopenjp2
    ./a.out
  fixture: |
    #include <openjpeg.h>
    int main () {
      opj_image_cmptparm_t cmptparm;
      const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
      opj_image_t *image;
      image = opj_image_create(1, &cmptparm, color_space);
      opj_image_destroy(image);
      return 0;
    }
