{% set name = "abseil-cpp" %}
{% set version = "20230802.0" %}
{% set v_major = version.split(".")[0] %}

package:
  name: {{ name|lower }}
  version: {{ version }}

source:
  url: https://github.com/abseil/{{ name }}/archive/{{ version }}.tar.gz
  sha256: 59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5
  patches:
    - clang4_osx_fix.diff  # [osx]

build:
  number: 2
  run_exports:
    - {{ pin_subpackage("abseil-cpp", max_pin="x.x") }}
  missing_dso_whitelist:  # [s390x]
    - '$RPATH/ld64.so.1'  # [s390x]

requirements:
  build:
    - {{ compiler('c') }}
    - {{ compiler('cxx') }}
    - patch  # [osx]
    - cmake
    - ninja
  host:
    - gtest 1.14.0
    - gmock 1.14.0

# shared builds for flags_* libraries are not supported on windows, see
# https://github.com/abseil/abseil-cpp/pull/1115
{% set absl_libs_always_static_on_win = [
    "flags", "flags_commandlineflag", "flags_config", "flags_marshalling", "flags_parse",
    "flags_private_handle_accessor", "flags_program_name", "flags_reflection", "flags_usage"
] %}

# Testing section taken from Conda-Forge
{% set absl_libs = absl_libs_always_static_on_win + [
    "base", "civil_time", "cord", "cordz_functions", "cordz_handle", "cordz_info",
    "cordz_sample_token", "examine_stack", "exponential_biased", "failure_signal_handler",
    "flags", "flags_commandlineflag", "flags_config", "flags_marshalling", "flags_parse",
    "flags_private_handle_accessor", "flags_program_name", "flags_reflection", "flags_usage",
    "hash", "hashtablez_sampler", "int128", "log_severity", "log_initialize", "low_level_hash", "periodic_sampler",
    "random_distributions", "random_seed_gen_exception", "random_seed_sequences", "raw_hash_set",
    "scoped_set_env", "spinlock_wait", "stacktrace", "status", "statusor", "strerror", "strings",
    "symbolize", "synchronization", "time", "time_zone"
] %}
test:
  requires:
    - pkg-config
  commands:
    # windows-only (almost-)all-in-one DLL + import library
    - if not exist %LIBRARY_BIN%\\abseil_dll.dll exit 1           # [win]
    - if not exist %LIBRARY_LIB%\\abseil_dll.lib exit 1           # [win]

    # absl_* libraries
    {% for each_lib in absl_libs %}
    # presence of shared libs
    - test -f $PREFIX/lib/libabsl_{{ each_lib }}${SHLIB_EXT}      # [unix]
    # absence of static libs
    - test ! -f $PREFIX/lib/libabsl_{{ each_lib }}.a              # [unix]

    # some static libs remain on windows even for shared builds, see above
    {% if each_lib in absl_libs_always_static_on_win %}
    - if not exist %LIBRARY_LIB%\\absl_{{ each_lib }}.lib exit 1  # [win]
    {% else %}
    - if exist %LIBRARY_LIB%\\absl_{{ each_lib }}.lib exit 1      # [win]
    {% endif %}

    # pkg-config (should point to abseil_dll on shared windows builds)
    - pkg-config --print-errors --exact-version "{{ v_major }}" absl_{{ each_lib }}
    {% endfor %}

    # pkg-config (abseil_dll)
    - pkg-config --print-errors --exact-version "{{ v_major }}" abseil_dll  # [win]

about:
  home: https://github.com/abseil/abseil-cpp
  license: Apache-2.0
  license_family: Apache
  license_file: LICENSE
  summary: Abseil Common Libraries (C++)
  description: |
    Abseil is an open-source collection of C++ code (compliant to C++11)
    designed to augment the C++ standard library.
  doc_url: https://github.com/abseil/abseil-cpp
  dev_url: https://github.com/abseil/abseil-cpp

extra:
  recipe-maintainers:
    - njzjz
    - bluescarni
    - xhochy
