Compiler projects using llvm
import("//compiler-rt/target.gni")

scudo_cflags = [
  "-Werror=conversion",
  "-nostdinc++",
]

source_set("sources") {
  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
  configs += [ "//llvm/utils/gn/build:crt_code" ]
  cflags = scudo_cflags
  sources = [
    "allocator_config.h",
    "atomic_helpers.h",
    "bytemap.h",
    "checksum.cpp",
    "checksum.h",
    "chunk.h",
    "combined.h",
    "common.cpp",
    "common.h",
    "crc32_hw.cpp",
    "flags.cpp",
    "flags.h",
    "flags_parser.cpp",
    "flags_parser.h",
    "fuchsia.cpp",
    "fuchsia.h",
    "include/scudo/interface.h",
    "internal_defs.h",
    "linux.cpp",
    "linux.h",
    "list.h",
    "local_cache.h",
    "memtag.h",
    "mutex.h",
    "options.h",
    "platform.h",
    "primary32.h",
    "primary64.h",
    "quarantine.h",
    "release.cpp",
    "release.h",
    "report.cpp",
    "report.h",
    "secondary.h",
    "size_class_map.h",
    "stack_depot.h",
    "stats.h",
    "string_utils.cpp",
    "string_utils.h",
    "tsd.h",
    "tsd_exclusive.h",
    "tsd_shared.h",
    "vector.h",
    "wrappers_c.h",
    "wrappers_c_checks.h",
  ]

  if (current_cpu == "arm" || current_cpu == "arm64") {
    cflags += [ "-mcrc" ]
  }
  if (current_cpu == "x64") {
    cflags += [ "-msse4.2" ]
  }

  public_configs = [ ":scudo_config" ]
}

source_set("c_wrapper_sources") {
  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
  configs += [ "//llvm/utils/gn/build:crt_code" ]
  cflags = scudo_cflags
  sources = [ "wrappers_c.cpp" ]

  public_configs = [ ":scudo_config" ]
}

source_set("cxx_wrapper_sources") {
  configs -= [ "//llvm/utils/gn/build:llvm_code" ]
  configs += [ "//llvm/utils/gn/build:crt_code" ]
  cflags = scudo_cflags
  sources = [ "wrappers_cpp.cpp" ]

  public_configs = [ ":scudo_config" ]
}

config("scudo_config") {
  include_dirs = [
    ".",
    "include",
  ]
  if (current_os == "android") {
    cflags = [ "-fno-emulated-tls" ]
  }
}