package(
    default_visibility = ["//visibility:public"],
)

licenses(["notice"])  # Apache 2.0

load(
    "//mace:mace.bzl",
    "if_android",
    "if_android_armv7",
    "if_apu_enabled",
    "if_hexagon_enabled",
    "if_hexagon_or_hta_enabled",
    "if_hta_enabled",
    "if_neon_enabled",
    "if_not_apu_enabled",
    "if_not_hexagon_enabled",
    "if_opencl_enabled",
    "if_openmp_enabled",
    "if_quantize_enabled",
    "if_rpcmem_enabled",
)

cc_library(
    name = "core",
    srcs = glob(
        [
            "*.cc",
            "runtime/cpu/*.cc",
        ],
    ) + if_opencl_enabled(glob(
        [
            "runtime/opencl/*.cc",
        ],
    )) + if_hexagon_enabled([
        "runtime/hexagon/hexagon_dsp_wrapper.cc",
    ]) + if_hta_enabled([
        "runtime/hexagon/hexagon_hta_wrapper.cc",
    ]) + if_apu_enabled(glob([
        "runtime/apu/*.cc",
    ])),
    hdrs = glob([
        "*.h",
        "runtime/cpu/*.h",
    ]) + if_opencl_enabled(glob([
        "runtime/opencl/*.h",
    ])) + if_hexagon_or_hta_enabled(glob([
        "runtime/hexagon/hexagon_control_wrapper.h",
        "runtime/hexagon/hexagon_device.h",
    ])) + if_hexagon_enabled(glob([
        "runtime/hexagon/*dsp*.h",
    ])) + if_hta_enabled(glob([
        "runtime/hexagon/*hta*.h",
    ])) + if_apu_enabled(glob([
        "runtime/apu/*.h"
    ])),
    copts = [
        "-Werror",
        "-Wextra",
        "-Wno-missing-field-initializers",
    ] + if_openmp_enabled([
        "-fopenmp",
        "-DMACE_ENABLE_OPENMP",
    ]) + if_opencl_enabled([
        "-DMACE_ENABLE_OPENCL",
    ]) + if_quantize_enabled([
        "-DMACE_ENABLE_QUANTIZE",
    ]) + if_hexagon_enabled([
        "-DMACE_ENABLE_HEXAGON",
    ]) + if_hta_enabled([
        "-DMACE_ENABLE_HTA",
    ]) + if_apu_enabled([
        "-DMACE_ENABLE_APU",
    ]) + if_neon_enabled([
        "-DMACE_ENABLE_NEON",
    ]) + if_android_armv7([
        "-mfpu=neon-fp16",
        "-mfloat-abi=softfp",
    ]) + if_rpcmem_enabled([
        "-DMACE_ENABLE_RPCMEM",
    ]),
    linkopts = ["-ldl"],
    deps = [
        "//mace/codegen:generated_version",
        "//mace/proto:mace_cc",
        "//mace/utils",
        "//mace/port",
        "@half//:half",
    ] + if_opencl_enabled([
        ":opencl_headers",
        "//mace/codegen:generated_opencl",
    ]) + if_quantize_enabled([
        "@gemmlowp",
    ]) + if_hexagon_enabled([
        "//third_party/nnlib:libhexagon",
    ]) + if_hta_enabled([
        "//third_party/hta",
    ]) + if_apu_enabled([
        "//third_party/apu:libapu-frontend",
    ]) + if_rpcmem_enabled([
        "//third_party/rpcmem",
    ]),
)

cc_library(
    name = "opencl_headers",
    hdrs = glob([
        "runtime/opencl/*.h",
    ]),
    copts = [
        "-Werror",
        "-Wextra",
        "-Wno-missing-field-initializers",
    ],
    deps = [
        "@opencl_clhpp",
        "@opencl_headers//:opencl20_headers",
    ],
)
