# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")
import("//third_party/boringssl/BUILD.generated.gni")
import("$dir_pw_build/target_types.gni")

config("external_config") {
  include_dirs = [ "src/include" ]
  cflags = [ "-Wno-cast-qual" ]
  cflags_c = [ "-std=c17" ]
}

config("internal_config") {
  visibility = [ ":*" ]  # Only targets in this file can depend on this.
  defines = [
    "BORINGSSL_ALLOW_CXX_RUNTIME",
    "BORINGSSL_IMPLEMENTATION",
    "BORINGSSL_NO_STATIC_INITIALIZER",
    "OPENSSL_SMALL",
    "OPENSSL_NO_ASM",
    "OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED",
  ]
  cflags_c = [
    "-Wno-unused-parameter",
    "-no-pedantic",
  ]
}

config("no_cast_function_type_warnings") {
  cflags = [
    # Disable "-Wcast-fuction-type-strict"
    # and "-Wcast-function-type-mismatch"  which enforce an exact type match
    # between a function pointer and the target function.
    "-Wno-cast-function-type-strict",
    "-Wno-cast-function-type-mismatch",
    "-Wno-unknown-warning-option",
  ]
}

pw_static_library("crypto") {
  sources = crypto_sources
  public = crypto_headers
  public_configs = [ ":external_config" ]
  configs = [
    ":internal_config",
    ":no_cast_function_type_warnings",
  ]
}
