# Copyright (c) 2026 Masashi Takamoto
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

# Vendored yespower 1.0.1. See README.md for provenance and the (five)
# local patches.
#
# Compiled as C, not C++: upstream uses C99 array parameters of the form
# `uint32_t state[static restrict 8]`, which C++ has no equivalent for. The C
# language is already enabled for this project by cmake/secp256k1.cmake, so
# this costs nothing.
#
# yespower-platform.c is #included by yespower-opt.c and must NOT be listed as
# a source of its own; likewise yespower-opt.c #includes itself for its second
# preprocessing pass.
add_library(bitcoin_yespower STATIC EXCLUDE_FROM_ALL
  yespower-opt.c
  sha256.c
)

set_target_properties(bitcoin_yespower PROPERTIES
  # `[static restrict N]` and `static inline` need C99 at minimum; ask for C11
  # so that MSVC is driven out of its pre-standard default mode.
  C_STANDARD 11
  C_STANDARD_REQUIRED ON
  # Extensions ON, i.e. -std=gnu11 rather than -std=c11. Not for the language:
  # it is glibc. Under -std=c11 glibc sees __STRICT_ANSI__ and hides MAP_ANON,
  # which silently drops yespower-platform.c onto its malloc fallback instead
  # of the mmap path upstream's own test runs use. The computed hash is the
  # same either way, but there is no reason to build a different branch than
  # the one with the known-answer evidence behind it. No effect on MSVC.
  C_EXTENSIONS ON
  POSITION_INDEPENDENT_CODE ON
)

target_include_directories(bitcoin_yespower
  INTERFACE
    ${PROJECT_SOURCE_DIR}/src
)

# Deliberately NOT linked against core_interface/warn_interface: this is
# third-party code kept diffable against upstream, and its warnings are not
# ours to fix. It needs no Bitcoin headers and defines no Bitcoin symbols.
