# Copyright 2014 PDFium 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("../pdfium.gni")

group("third_party") {
  deps = [
    ":bigint",
    ":fx_freetype",
    ":pdfium_base",
  ]
}

config("pdfium_third_party_config") {
  configs = [ "..:pdfium_common_config" ]
}

source_set("bigint") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",
  ]
  sources = [
    "bigint/BigInteger.cc",
    "bigint/BigInteger.hh",
    "bigint/BigIntegerLibrary.hh",
    "bigint/BigIntegerUtils.cc",
    "bigint/BigIntegerUtils.hh",
    "bigint/BigUnsigned.cc",
    "bigint/BigUnsigned.hh",
    "bigint/BigUnsignedInABase.cc",
    "bigint/BigUnsignedInABase.hh",
    "bigint/NumberlikeArray.hh",
  ]
}

config("fx_freetype_warnings") {
  visibility = [ ":*" ]
  if (is_clang) {
    # open_face_PS_from_sfnt_stream() and open_face_from_buffer() in
    # ftbase.h are unused.
    cflags = [ "-Wno-unused-function" ]
  }
}

# Tests may link against this even if the production library doesn't,
# so it needs to be separate from it.
static_library("fx_freetype") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",

    # Must be after no_chromium_code for warning flags to be ordered correctly.
    ":fx_freetype_warnings",
  ]
  defines = [ "FT2_BUILD_LIBRARY" ]
  sources = [
    "freetype/include/freetype/freetype.h",
    "freetype/include/freetype/ftmm.h",
    "freetype/include/freetype/ftotval.h",
    "freetype/include/freetype/ftoutln.h",
    "freetype/include/freetype/internal/ftobjs.h",
    "freetype/include/freetype/internal/ftstream.h",
    "freetype/include/freetype/internal/tttypes.h",
    "freetype/include/freetype/tttables.h",
    "freetype/include/ft2build.h",
    "freetype/src/base/ftbase.c",
    "freetype/src/base/ftbase.h",
    "freetype/src/base/ftbitmap.c",
    "freetype/src/base/ftglyph.c",
    "freetype/src/base/ftinit.c",
    "freetype/src/base/ftlcdfil.c",
    "freetype/src/base/ftmm.c",
    "freetype/src/base/ftsystem.c",
    "freetype/src/cff/cff.c",
    "freetype/src/cff/cffobjs.h",
    "freetype/src/cff/cfftypes.h",
    "freetype/src/cid/type1cid.c",
    "freetype/src/psaux/psaux.c",
    "freetype/src/pshinter/pshinter.c",
    "freetype/src/psnames/psmodule.c",
    "freetype/src/raster/raster.c",
    "freetype/src/sfnt/sfnt.c",
    "freetype/src/smooth/smooth.c",
    "freetype/src/truetype/truetype.c",
    "freetype/src/type1/type1.c",
  ]
  if (pdf_use_skia) {
    sources += [
      "freetype/src/base/ftfntfmt.c",
      "freetype/src/base/ftfstype.c",
      "freetype/src/base/fttype1.c",
    ]
  }
}

if (!pdf_use_skia) {
  config("fx_agg_warnings") {
    visibility = [ ":*" ]
    if (is_clang) {
      # calc_butt_cap() in agg_vcgen_stroke.cpp is unused.
      cflags = [ "-Wno-unused-function" ]
    }
  }

  source_set("fx_agg") {
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      "//build/config/compiler:no_chromium_code",
      ":pdfium_third_party_config",

      # Must be after no_chromium_code for warning flags to be ordered correctly.
      ":fx_agg_warnings",
    ]
    sources = [
      "agg23/agg_basics.h",
      "agg23/agg_clip_liang_barsky.h",
      "agg23/agg_conv_dash.h",
      "agg23/agg_conv_stroke.h",
      "agg23/agg_curves.cpp",
      "agg23/agg_curves.h",
      "agg23/agg_path_storage.cpp",
      "agg23/agg_path_storage.h",
      "agg23/agg_rasterizer_scanline_aa.cpp",
      "agg23/agg_rasterizer_scanline_aa.h",
      "agg23/agg_renderer_scanline.h",
      "agg23/agg_rendering_buffer.h",
      "agg23/agg_scanline_u.h",
      "agg23/agg_vcgen_dash.cpp",
      "agg23/agg_vcgen_stroke.cpp",
    ]
  }
}

config("fx_lcms2_warnings") {
  visibility = [ ":*" ]
  if (is_clang) {
    cflags = [
      # cmslut.cc is sloppy with aggregate initialization. Version 2.7 of this
      # library doesn't appear to have this problem.
      "-Wno-missing-braces",

      # FindPrev() in cmsplugin.c is unused.
      "-Wno-unused-function",
    ]
  }
}

source_set("fx_lcms2") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",

    # Must be after no_chromium_code for warning flags to be ordered correctly.
    ":fx_lcms2_warnings",
  ]
  sources = [
    "lcms2-2.6/include/lcms2.h",
    "lcms2-2.6/include/lcms2_plugin.h",
    "lcms2-2.6/src/cmscam02.c",
    "lcms2-2.6/src/cmscgats.c",
    "lcms2-2.6/src/cmscnvrt.c",
    "lcms2-2.6/src/cmserr.c",
    "lcms2-2.6/src/cmsgamma.c",
    "lcms2-2.6/src/cmsgmt.c",
    "lcms2-2.6/src/cmshalf.c",
    "lcms2-2.6/src/cmsintrp.c",
    "lcms2-2.6/src/cmsio0.c",
    "lcms2-2.6/src/cmsio1.c",
    "lcms2-2.6/src/cmslut.c",
    "lcms2-2.6/src/cmsmd5.c",
    "lcms2-2.6/src/cmsmtrx.c",
    "lcms2-2.6/src/cmsnamed.c",
    "lcms2-2.6/src/cmsopt.c",
    "lcms2-2.6/src/cmspack.c",
    "lcms2-2.6/src/cmspcs.c",
    "lcms2-2.6/src/cmsplugin.c",
    "lcms2-2.6/src/cmsps2.c",
    "lcms2-2.6/src/cmssamp.c",
    "lcms2-2.6/src/cmssm.c",
    "lcms2-2.6/src/cmstypes.c",
    "lcms2-2.6/src/cmsvirt.c",
    "lcms2-2.6/src/cmswtpnt.c",
    "lcms2-2.6/src/cmsxform.c",
  ]
}

# This is only used for standalone builds.
config("jpeg_warnings") {
  visibility = [ ":*" ]
  if (is_clang) {
    cflags = [ "-Wno-shift-negative-value" ]
  }
}

source_set("jpeg") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",

    # Must be after no_chromium_code for warning flags to be ordered correctly.
    ":jpeg_warnings",
  ]
  sources = [
    "libjpeg/cderror.h",
    "libjpeg/cdjpeg.h",
    "libjpeg/fpdfapi_jcapimin.c",
    "libjpeg/fpdfapi_jcapistd.c",
    "libjpeg/fpdfapi_jccoefct.c",
    "libjpeg/fpdfapi_jccolor.c",
    "libjpeg/fpdfapi_jcdctmgr.c",
    "libjpeg/fpdfapi_jchuff.c",
    "libjpeg/fpdfapi_jcinit.c",
    "libjpeg/fpdfapi_jcmainct.c",
    "libjpeg/fpdfapi_jcmarker.c",
    "libjpeg/fpdfapi_jcmaster.c",
    "libjpeg/fpdfapi_jcomapi.c",
    "libjpeg/fpdfapi_jcparam.c",
    "libjpeg/fpdfapi_jcphuff.c",
    "libjpeg/fpdfapi_jcprepct.c",
    "libjpeg/fpdfapi_jcsample.c",
    "libjpeg/fpdfapi_jctrans.c",
    "libjpeg/fpdfapi_jdapimin.c",
    "libjpeg/fpdfapi_jdapistd.c",
    "libjpeg/fpdfapi_jdcoefct.c",
    "libjpeg/fpdfapi_jdcolor.c",
    "libjpeg/fpdfapi_jddctmgr.c",
    "libjpeg/fpdfapi_jdhuff.c",
    "libjpeg/fpdfapi_jdinput.c",
    "libjpeg/fpdfapi_jdmainct.c",
    "libjpeg/fpdfapi_jdmarker.c",
    "libjpeg/fpdfapi_jdmaster.c",
    "libjpeg/fpdfapi_jdmerge.c",
    "libjpeg/fpdfapi_jdphuff.c",
    "libjpeg/fpdfapi_jdpostct.c",
    "libjpeg/fpdfapi_jdsample.c",
    "libjpeg/fpdfapi_jdtrans.c",
    "libjpeg/fpdfapi_jerror.c",
    "libjpeg/fpdfapi_jfdctfst.c",
    "libjpeg/fpdfapi_jfdctint.c",
    "libjpeg/fpdfapi_jidctfst.c",
    "libjpeg/fpdfapi_jidctint.c",
    "libjpeg/fpdfapi_jidctred.c",
    "libjpeg/fpdfapi_jmemmgr.c",
    "libjpeg/fpdfapi_jmemnobs.c",
    "libjpeg/fpdfapi_jutils.c",
    "libjpeg/jchuff.h",
    "libjpeg/jconfig.h",
    "libjpeg/jdct.h",
    "libjpeg/jdhuff.h",
    "libjpeg/jerror.h",
    "libjpeg/jinclude.h",
    "libjpeg/jmemsys.h",
    "libjpeg/jmorecfg.h",
    "libjpeg/jpegint.h",
    "libjpeg/jpeglib.h",
    "libjpeg/jversion.h",
    "libjpeg/makefile",
    "libjpeg/transupp.h",
  ]
}

config("fx_libopenjpeg_warnings") {
  visibility = [ ":*" ]
  if (is_win) {
    cflags = [
      # Signed/unsigned comparisons.
      "/wd4018",
    ]
  }
}

source_set("fx_libopenjpeg") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",

    # Must be after no_chromium_code for warning flags to be ordered correctly.
    ":fx_libopenjpeg_warnings",
  ]
  sources = [
    "libopenjpeg20/bio.c",
    "libopenjpeg20/cio.c",
    "libopenjpeg20/dwt.c",
    "libopenjpeg20/event.c",
    "libopenjpeg20/function_list.c",
    "libopenjpeg20/image.c",
    "libopenjpeg20/invert.c",
    "libopenjpeg20/j2k.c",
    "libopenjpeg20/jp2.c",
    "libopenjpeg20/mct.c",
    "libopenjpeg20/mqc.c",
    "libopenjpeg20/openjpeg.c",
    "libopenjpeg20/opj_clock.c",
    "libopenjpeg20/pi.c",
    "libopenjpeg20/raw.c",
    "libopenjpeg20/t1.c",
    "libopenjpeg20/t2.c",
    "libopenjpeg20/tcd.c",
    "libopenjpeg20/tgt.c",
  ]
}

source_set("fx_lpng") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",
  ]
  sources = [
    "libpng16/png.c",
    "libpng16/png.h",
    "libpng16/pngconf.h",
    "libpng16/pngdebug.h",
    "libpng16/pngerror.c",
    "libpng16/pngget.c",
    "libpng16/pnginfo.h",
    "libpng16/pnglibconf.h",
    "libpng16/pngmem.c",
    "libpng16/pngpread.c",
    "libpng16/pngprefix.h",
    "libpng16/pngpriv.h",
    "libpng16/pngread.c",
    "libpng16/pngrio.c",
    "libpng16/pngrtran.c",
    "libpng16/pngrutil.c",
    "libpng16/pngset.c",
    "libpng16/pngstruct.h",
    "libpng16/pngtrans.c",
    "libpng16/pngwio.c",
    "libpng16/pngwrite.c",
    "libpng16/pngwtran.c",
    "libpng16/pngwutil.c",
  ]
}

if (pdf_enable_xfa) {
  source_set("fx_tiff") {
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      "//build/config/compiler:no_chromium_code",
      ":pdfium_third_party_config",
    ]
    if (is_win) {
      # Need to undefine the macro since it is redefined in
      # tif_ojpeg.c and tif_jpeg.c.
      configs -= [ "//build/config/win:lean_and_mean" ]
    }
    deps = [
      "//third_party:jpeg",
    ]
    sources = [
      "libtiff/tif_aux.c",
      "libtiff/tif_close.c",
      "libtiff/tif_codec.c",
      "libtiff/tif_color.c",
      "libtiff/tif_compress.c",
      "libtiff/tif_dir.c",
      "libtiff/tif_dirinfo.c",
      "libtiff/tif_dirread.c",
      "libtiff/tif_dirwrite.c",
      "libtiff/tif_dumpmode.c",
      "libtiff/tif_error.c",
      "libtiff/tif_extension.c",
      "libtiff/tif_fax3.c",
      "libtiff/tif_fax3sm.c",
      "libtiff/tif_flush.c",
      "libtiff/tif_getimage.c",
      "libtiff/tif_jpeg.c",
      "libtiff/tif_luv.c",
      "libtiff/tif_lzw.c",
      "libtiff/tif_next.c",
      "libtiff/tif_ojpeg.c",
      "libtiff/tif_open.c",
      "libtiff/tif_packbits.c",
      "libtiff/tif_pixarlog.c",
      "libtiff/tif_predict.c",
      "libtiff/tif_print.c",
      "libtiff/tif_read.c",
      "libtiff/tif_strip.c",
      "libtiff/tif_swab.c",
      "libtiff/tif_thunder.c",
      "libtiff/tif_tile.c",
      "libtiff/tif_version.c",
      "libtiff/tif_warning.c",
      "libtiff/tif_write.c",
      "libtiff/tif_zip.c",
      "libtiff/tiffiop.h",
      "libtiff/tiffvers.h",
    ]
  }
}

# TODO(dsinclair): Remove if fixed upstream. https://crbug.com/507712
config("fx_zlib_warnings") {
  visibility = [ ":*" ]
  if (is_clang) {
    cflags = [ "-Wno-shift-negative-value" ]
  }
}

source_set("fx_zlib") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",

    # Must be after no_chromium_code for warning flags to be ordered correctly.
    ":fx_zlib_warnings",
  ]
  sources = [
    "zlib_v128/adler32.c",
    "zlib_v128/compress.c",
    "zlib_v128/crc32.c",
    "zlib_v128/deflate.c",
    "zlib_v128/gzclose.c",
    "zlib_v128/gzlib.c",
    "zlib_v128/gzread.c",
    "zlib_v128/gzwrite.c",
    "zlib_v128/infback.c",
    "zlib_v128/inffast.c",
    "zlib_v128/inflate.c",
    "zlib_v128/inftrees.c",
    "zlib_v128/trees.c",
    "zlib_v128/uncompr.c",
    "zlib_v128/zutil.c",
  ]
}

source_set("pdfium_base") {
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":pdfium_third_party_config",
  ]
  sources = [
    "base/logging.h",
    "base/macros.h",
    "base/numerics/safe_conversions.h",
    "base/numerics/safe_conversions_impl.h",
    "base/numerics/safe_math.h",
    "base/numerics/safe_math_impl.h",
    "base/stl_util.h",
  ]
}