# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//testing/libfuzzer/fuzzer_test.gni")

declare_args() {
  # Flip to true to build sfntly sample programs.
  build_sfntly_samples = false
}

config("sfntly_public_config") {
  include_dirs = [ "src/cpp/src" ]
}

config("sfntly_common_config") {
  defines = [ "SFNTLY_NO_EXCEPTION" ]
  include_dirs = [ "src/cpp/src" ]
}

source_set("sfntly_chromium") {
  sources = [
    "src/cpp/src/sample/chromium/font_subsetter.cc",
    "src/cpp/src/sample/chromium/font_subsetter.h",
    "src/cpp/src/sample/chromium/subsetter_impl.cc",
    "src/cpp/src/sample/chromium/subsetter_impl.h",
  ]

  # This is the equivalent to the following in sfntly.gyp.
  # 'msvs_disabled_warnings': [ 4267 ],
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]

  configs += [ ":sfntly_common_config" ]
  deps = [
    "//third_party/icu:icuuc",
  ]
}

static_library("sfntly") {
  sources = [
    "src/cpp/src/sfntly/data/byte_array.cc",
    "src/cpp/src/sfntly/data/byte_array.h",
    "src/cpp/src/sfntly/data/font_data.cc",
    "src/cpp/src/sfntly/data/font_data.h",
    "src/cpp/src/sfntly/data/font_input_stream.cc",
    "src/cpp/src/sfntly/data/font_input_stream.h",
    "src/cpp/src/sfntly/data/font_output_stream.cc",
    "src/cpp/src/sfntly/data/font_output_stream.h",
    "src/cpp/src/sfntly/data/growable_memory_byte_array.cc",
    "src/cpp/src/sfntly/data/growable_memory_byte_array.h",
    "src/cpp/src/sfntly/data/memory_byte_array.cc",
    "src/cpp/src/sfntly/data/memory_byte_array.h",
    "src/cpp/src/sfntly/data/readable_font_data.cc",
    "src/cpp/src/sfntly/data/readable_font_data.h",
    "src/cpp/src/sfntly/data/writable_font_data.cc",
    "src/cpp/src/sfntly/data/writable_font_data.h",
    "src/cpp/src/sfntly/font.cc",
    "src/cpp/src/sfntly/font.h",
    "src/cpp/src/sfntly/font_factory.cc",
    "src/cpp/src/sfntly/font_factory.h",
    "src/cpp/src/sfntly/math/fixed1616.h",
    "src/cpp/src/sfntly/math/font_math.h",
    "src/cpp/src/sfntly/port/atomic.h",
    "src/cpp/src/sfntly/port/config.h",
    "src/cpp/src/sfntly/port/endian.h",
    "src/cpp/src/sfntly/port/exception_type.h",
    "src/cpp/src/sfntly/port/file_input_stream.cc",
    "src/cpp/src/sfntly/port/file_input_stream.h",
    "src/cpp/src/sfntly/port/input_stream.h",
    "src/cpp/src/sfntly/port/java_iterator.h",
    "src/cpp/src/sfntly/port/lock.cc",
    "src/cpp/src/sfntly/port/lock.h",
    "src/cpp/src/sfntly/port/logging.h",
    "src/cpp/src/sfntly/port/memory_input_stream.cc",
    "src/cpp/src/sfntly/port/memory_input_stream.h",
    "src/cpp/src/sfntly/port/memory_output_stream.cc",
    "src/cpp/src/sfntly/port/memory_output_stream.h",
    "src/cpp/src/sfntly/port/output_stream.h",
    "src/cpp/src/sfntly/port/refcount.h",
    "src/cpp/src/sfntly/port/type.h",
    "src/cpp/src/sfntly/table/bitmap/big_glyph_metrics.cc",
    "src/cpp/src/sfntly/table/bitmap/big_glyph_metrics.h",
    "src/cpp/src/sfntly/table/bitmap/bitmap_glyph.cc",
    "src/cpp/src/sfntly/table/bitmap/bitmap_glyph.h",
    "src/cpp/src/sfntly/table/bitmap/bitmap_glyph_info.cc",
    "src/cpp/src/sfntly/table/bitmap/bitmap_glyph_info.h",
    "src/cpp/src/sfntly/table/bitmap/bitmap_size_table.cc",
    "src/cpp/src/sfntly/table/bitmap/bitmap_size_table.h",
    "src/cpp/src/sfntly/table/bitmap/composite_bitmap_glyph.cc",
    "src/cpp/src/sfntly/table/bitmap/composite_bitmap_glyph.h",
    "src/cpp/src/sfntly/table/bitmap/ebdt_table.cc",
    "src/cpp/src/sfntly/table/bitmap/ebdt_table.h",
    "src/cpp/src/sfntly/table/bitmap/eblc_table.cc",
    "src/cpp/src/sfntly/table/bitmap/eblc_table.h",
    "src/cpp/src/sfntly/table/bitmap/ebsc_table.cc",
    "src/cpp/src/sfntly/table/bitmap/ebsc_table.h",
    "src/cpp/src/sfntly/table/bitmap/glyph_metrics.cc",
    "src/cpp/src/sfntly/table/bitmap/glyph_metrics.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format1.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format1.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format2.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format2.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format3.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format3.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format4.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format4.h",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format5.cc",
    "src/cpp/src/sfntly/table/bitmap/index_sub_table_format5.h",
    "src/cpp/src/sfntly/table/bitmap/simple_bitmap_glyph.cc",
    "src/cpp/src/sfntly/table/bitmap/simple_bitmap_glyph.h",
    "src/cpp/src/sfntly/table/bitmap/small_glyph_metrics.cc",
    "src/cpp/src/sfntly/table/bitmap/small_glyph_metrics.h",
    "src/cpp/src/sfntly/table/byte_array_table_builder.cc",
    "src/cpp/src/sfntly/table/byte_array_table_builder.h",
    "src/cpp/src/sfntly/table/core/cmap_table.cc",
    "src/cpp/src/sfntly/table/core/cmap_table.h",
    "src/cpp/src/sfntly/table/core/font_header_table.cc",
    "src/cpp/src/sfntly/table/core/font_header_table.h",
    "src/cpp/src/sfntly/table/core/horizontal_device_metrics_table.cc",
    "src/cpp/src/sfntly/table/core/horizontal_device_metrics_table.h",
    "src/cpp/src/sfntly/table/core/horizontal_header_table.cc",
    "src/cpp/src/sfntly/table/core/horizontal_header_table.h",
    "src/cpp/src/sfntly/table/core/horizontal_metrics_table.cc",
    "src/cpp/src/sfntly/table/core/horizontal_metrics_table.h",
    "src/cpp/src/sfntly/table/core/maximum_profile_table.cc",
    "src/cpp/src/sfntly/table/core/maximum_profile_table.h",
    "src/cpp/src/sfntly/table/core/name_table.cc",
    "src/cpp/src/sfntly/table/core/name_table.h",
    "src/cpp/src/sfntly/table/core/os2_table.cc",
    "src/cpp/src/sfntly/table/core/os2_table.h",
    "src/cpp/src/sfntly/table/font_data_table.cc",
    "src/cpp/src/sfntly/table/font_data_table.h",
    "src/cpp/src/sfntly/table/generic_table_builder.cc",
    "src/cpp/src/sfntly/table/generic_table_builder.h",
    "src/cpp/src/sfntly/table/header.cc",
    "src/cpp/src/sfntly/table/header.h",
    "src/cpp/src/sfntly/table/subtable.cc",
    "src/cpp/src/sfntly/table/subtable.h",
    "src/cpp/src/sfntly/table/subtable_container_table.h",
    "src/cpp/src/sfntly/table/table.cc",
    "src/cpp/src/sfntly/table/table.h",
    "src/cpp/src/sfntly/table/table_based_table_builder.cc",
    "src/cpp/src/sfntly/table/table_based_table_builder.h",
    "src/cpp/src/sfntly/table/truetype/glyph_table.cc",
    "src/cpp/src/sfntly/table/truetype/glyph_table.h",
    "src/cpp/src/sfntly/table/truetype/loca_table.cc",
    "src/cpp/src/sfntly/table/truetype/loca_table.h",
    "src/cpp/src/sfntly/tag.cc",
    "src/cpp/src/sfntly/tag.h",
  ]

  # This is the equivalent to the following in sfntly.gyp.
  # 'msvs_disabled_warnings': [ 4267 ],
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]

  configs += [ ":sfntly_common_config" ]
  public_configs = [ ":sfntly_public_config" ]
  deps = [
    ":sfntly_chromium",
    "//third_party/icu:icuuc",
  ]
}

fuzzer_test("sfntly_fuzzer") {
  sources = [
    "fuzzers/subset_font_fuzzer.cc",
  ]
  deps = [
    ":sfntly",
    "//base/test:test_support",
  ]
  seed_corpus = "fuzzers/corpora/sfntly_fuzzer"
}

if (build_sfntly_samples) {
  source_set("sfntly_subtly") {
    sources = [
      "src/cpp/src/sample/subtly/character_predicate.cc",
      "src/cpp/src/sample/subtly/character_predicate.h",
      "src/cpp/src/sample/subtly/font_assembler.cc",
      "src/cpp/src/sample/subtly/font_assembler.h",
      "src/cpp/src/sample/subtly/font_info.cc",
      "src/cpp/src/sample/subtly/font_info.h",
      "src/cpp/src/sample/subtly/merger.cc",
      "src/cpp/src/sample/subtly/merger.h",
      "src/cpp/src/sample/subtly/stats.cc",
      "src/cpp/src/sample/subtly/stats.h",
      "src/cpp/src/sample/subtly/subsetter.cc",
      "src/cpp/src/sample/subtly/subsetter.h",
      "src/cpp/src/sample/subtly/utils.cc",
      "src/cpp/src/sample/subtly/utils.h",
    ]

    configs += [ ":sfntly_common_config" ]
    include_dirs = [ "src/cpp/src/sample" ]
  }

  source_set("sfntly_tools") {
    sources = [
      "src/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.cc",
      "src/cpp/src/sfntly/tools/subsetter/glyph_table_subsetter.h",
      "src/cpp/src/sfntly/tools/subsetter/subsetter.cc",
      "src/cpp/src/sfntly/tools/subsetter/subsetter.h",
      "src/cpp/src/sfntly/tools/subsetter/table_subsetter.h",
      "src/cpp/src/sfntly/tools/subsetter/table_subsetter_impl.cc",
      "src/cpp/src/sfntly/tools/subsetter/table_subsetter_impl.h",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      "//third_party/icu:icuuc",
    ]
  }

  executable("sfntly_chrome_subsetter") {
    sources = [
      "src/cpp/src/sample/chromium/chrome_subsetter.cc",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
    ]
  }

  executable("sfntly_subsetter") {
    sources = [
      "src/cpp/src/sample/subsetter/main.cc",
      "src/cpp/src/sample/subsetter/subset_util.cc",
      "src/cpp/src/sample/subsetter/subset_util.h",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
      ":sfntly_subtly",
      ":sfntly_tools",
    ]
  }

  executable("sfntly_subtly_debug") {
    sources = [
      "src/cpp/src/sample/subtly/debug_main.cc",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
      ":sfntly_subtly",
    ]
    include_dirs = [ "src/cpp/src/sample" ]
  }

  executable("sfntly_subtly_merger") {
    sources = [
      "src/cpp/src/sample/subtly/merger_main.cc",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
      ":sfntly_subtly",
    ]
    include_dirs = [ "src/cpp/src/sample" ]
  }

  executable("sfntly_subtly_subsetter") {
    sources = [
      "src/cpp/src/sample/subtly/subsetter_main.cc",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
      ":sfntly_subtly",
    ]
    include_dirs = [ "src/cpp/src/sample" ]
  }

  executable("sfntly_unittest") {
    sources = [
      "src/cpp/src/test/autogenerated/cmap_basic_test.cc",
      "src/cpp/src/test/autogenerated/cmap_test_data.h",
      "src/cpp/src/test/bitmap_table_test.cc",
      "src/cpp/src/test/byte_array_test.cc",
      "src/cpp/src/test/chrome_subsetter.cc",
      "src/cpp/src/test/cmap_editing_test.cc",
      "src/cpp/src/test/cmap_iterator_test.cc",
      "src/cpp/src/test/cmap_test.cc",
      "src/cpp/src/test/endian_test.cc",
      "src/cpp/src/test/file_io_test.cc",
      "src/cpp/src/test/font_data_test.cc",
      "src/cpp/src/test/font_parsing_test.cc",
      "src/cpp/src/test/hdmx_test.cc",
      "src/cpp/src/test/lock_test.cc",
      "src/cpp/src/test/memory_io_test.cc",
      "src/cpp/src/test/name_editing_test.cc",
      "src/cpp/src/test/open_type_data_test.cc",
      "src/cpp/src/test/otf_basic_editing_test.cc",
      "src/cpp/src/test/platform_thread.cc",
      "src/cpp/src/test/platform_thread.h",
      "src/cpp/src/test/serialization_test.cc",
      "src/cpp/src/test/serialization_test.h",
      "src/cpp/src/test/smart_pointer_test.cc",
      "src/cpp/src/test/test_data.cc",
      "src/cpp/src/test/test_data.h",
      "src/cpp/src/test/test_font_utils.cc",
      "src/cpp/src/test/test_font_utils.h",
      "src/cpp/src/test/test_utils.cc",
      "src/cpp/src/test/test_utils.h",
      "src/cpp/src/test/test_utils_test.cc",
      "src/cpp/src/test/test_xml_utils.cc",
      "src/cpp/src/test/test_xml_utils.h",
      "src/cpp/src/test/tinyxml/tinystr.cpp",
      "src/cpp/src/test/tinyxml/tinystr.h",
      "src/cpp/src/test/tinyxml/tinyxml.cpp",
      "src/cpp/src/test/tinyxml/tinyxml.h",
      "src/cpp/src/test/tinyxml/tinyxmlerror.cpp",
      "src/cpp/src/test/tinyxml/tinyxmlparser.cpp",
      "src/cpp/src/test/verify_glyf.cc",
      "src/cpp/src/test/verify_hhea.cc",
      "src/cpp/src/test/verify_hmtx.cc",
      "src/cpp/src/test/verify_loca.cc",
      "src/cpp/src/test/verify_maxp.cc",
      "src/cpp/src/test/verify_name.cc",
      "src/cpp/src/test/verify_os2.cc",
    ]

    configs += [ ":sfntly_common_config" ]
    deps = [
      ":sfntly",
      "//testing/gtest",
      "//testing/gtest:gtest_main",
      "//third_party/icu:icuuc",
    ]
    defines = [ "TIXML_USE_STL" ]
    testonly = true
  }
}