{% set version = "3.20.3" %}

{% set libraries = ["libprotoc", "libprotobuf", "libprotobuf-lite"] %}

package:
  name: libprotobuf-split
  version: {{ version }}

source:
  - url: https://github.com/protocolbuffers/protobuf/archive/v{{ version }}/libprotobuf-v{{ version }}.tar.gz
    sha256: 9c0fd39c7a08dff543c643f0f4baf081988129a411b977a07c46221793605638
    patches:
      - patches/0001-remove-Werror-from-test-flags.patch  # [ppc64le or aarch64]
      - patches/0002-use-consistent-cmake-location.patch
      - patches/0003-set-static-lib-extension-on-windows.patch
      # This issue gets fixed and then reintroduced often
      # https://github.com/protocolbuffers/protobuf/issues/7567
      # - patches/issue-7567.patch
  # these are git submodules from the 3.10.1 release
  # https://github.com/protocolbuffers/protobuf/tree/v3.10.1/third_party
  - url: https://github.com/google/benchmark/archive/5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8.tar.gz
    sha256: 5dc92703f811f94e2aa63bdab07ab749f28a094befa6cdfd5fe177f947590a48
    folder: third_party/benchmark
  - url: https://github.com/google/googletest/archive/5ec7f0c4a113e2f18ac2c6cc7df51ad6afc24081.tar.gz
    sha256: 0e2f36e8e403c125fd0ab02171bdb786d3b6b3875b6ccf3b2eb7969be8faecd0
    folder: third_party/googletest

build:
  number: 0

outputs:
  - name: libprotobuf
    script: build-shared.sh  # [unix]
    # cmake script currently disabled due to compatibility issues with
    # existing builds; see #49 for potential solution, or switch with 3.22
    # script: build-lib.sh   # [unix]
    script: build-lib.bat  # [win]
    build:
      run_exports:
        # breaks backwards compatibility and new SONAME each minor release
        # https://abi-laboratory.pro/tracker/timeline/protobuf/
        # One exception was that 3.6.1 was incompatible with 3.6.0
        - {{ pin_subpackage('libprotobuf', max_pin='x.x') }}
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - cmake       # [win]
        - ninja       # [win]
        - autoconf    # [not win]
        - automake    # [not win]
        - libtool     # [not win]
        - pkg-config  # [not win]
        - unzip       # [not win]
        - make        # [not win]
      host:
        - zlib
      run:
        - ucrt  # [win]
    test:
      requires:
        # cmake needs compiler to be able to run package detection, see
        # https://discourse.cmake.org/t/questions-about-find-package-cli-msvc/6194
        - {{ compiler('cxx') }}  # [win]
        - cmake                  # [win]
      files:
        - cmake_test/
      commands:
        {% for each_lib in libraries %}
        # shared libraries
        - test -f ${PREFIX}/lib/{{ each_lib }}.so                      # [linux]
        - test -f ${PREFIX}/lib/{{ each_lib }}.dylib                   # [osx]
        - if not exist %LIBRARY_BIN%\{{ each_lib }}.dll exit 1         # [win]
        - if not exist %LIBRARY_LIB%\{{ each_lib }}.lib exit 1         # [win]

        # absence of static libraries
        - test ! -f ${PREFIX}/lib/{{ each_lib }}.a                     # [unix]
        - if exist %LIBRARY_LIB%\{{ each_lib }}-static.lib exit 1      # [win]
        {% endfor %}

        # cmake (disabled on unix currently)
        # - test -f ${PREFIX}/lib/cmake/protobuf/protobuf-config.cmake              # [unix]
        - if not exist %LIBRARY_LIB%\cmake\protobuf\protobuf-config.cmake exit 1  # [win]

        # pkgconfig
        - test -f ${PREFIX}/lib/pkgconfig/protobuf.pc                   # [unix]
        - test -f ${PREFIX}/lib/pkgconfig/protobuf-lite.pc              # [unix]
        - if not exist %LIBRARY_LIB%\pkgconfig\protobuf.pc exit 1       # [win]
        - if not exist %LIBRARY_LIB%\pkgconfig\protobuf-lite.pc exit 1  # [win]

        # binary
        - protoc --help

        # more CMake integration (CMake uses its own FindProtobuf)
        - cd cmake_test         # [win]
        - cmake %CMAKE_ARGS% .  # [win]

  - name: libprotobuf-static
    script: build-static.sh  # [unix]
    # cmake script currently disabled due to compatibility issues with
    # existing builds; see #49 for potential solution, or switch with 3.22
    # script: build-lib.sh   # [unix]
    script: build-lib.bat  # [win]
    requirements:
      build:
        - {{ compiler('c') }}
        - {{ compiler('cxx') }}
        - cmake  # [win]
        - ninja  # [win]
      host:
        - zlib
        - {{ pin_subpackage('libprotobuf', exact=True) }}
      run:
        - {{ pin_subpackage('libprotobuf', exact=True) }}
    test:
      requires:
        # cmake needs compiler to be able to run package detection, see
        # https://discourse.cmake.org/t/questions-about-find-package-cli-msvc/6194
        - {{ compiler('cxx') }}  # [win]
        - cmake                  # [win]
      files:
        - cmake_test/
      commands:
        {% for each_lib in libraries %}
        # static libraries
        - test -f ${PREFIX}/lib/{{ each_lib }}.a                       # [unix]
        - if not exist %LIBRARY_LIB%\{{ each_lib }}.lib exit 1         # [win]
        {% endfor %}

        # more CMake integration (CMake uses its own FindProtobuf)
        - cd cmake_test         # [win]
        - cmake %CMAKE_ARGS% .  # [win]

about:
  home: https://developers.google.com/protocol-buffers/
  license: BSD-3-Clause
  license_family: BSD
  license_file: LICENSE
  summary: Protocol Buffers - Google's data interchange format. C++ Libraries and protoc, the protobuf compiler.
  description: |
    Protocol buffers are Google's language-neutral,
    platform-neutral, extensible mechanism for serializing structured data-
    think XML, but smaller, faster, and simpler.
  dev_url: https://github.com/protocolbuffers/protobuf
  doc_url: https://developers.google.com/protocol-buffers/
  doc_source_url: https://github.com/protocolbuffers/protobuf/releases

extra:
  recipe-maintainers:
    - dopplershift
    - jakirkham
    - ocefpaf
    - wesm
    - hajapy
    - xhochy
    - h-vetinari
  feedstock-name: libprotobuf
