chromium/third_party/freetype/BUILD.gn

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

import("//build/config/cast.gni")
import("//build/config/freetype/freetype.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//third_party/harfbuzz-ng/harfbuzz.gni")

assert(!use_system_freetype, "Not used when using system freetype.")

config("freetype_component_config") {
  include_dirs = [
    "include",
    "include/freetype-custom",
    "src/include",
  ]

  defines = [
    # Long directory name to avoid accidentally using wrong headers.
    # GN currently does not escape '<' and '>' when generating xml based Visual
    # Studio project files. As a result, use quotes instead of pointy brackets
    # in these defines.
    "FT_CONFIG_MODULES_H=\"freetype-custom/freetype/config/ftmodule.h\"",
    "FT_CONFIG_OPTIONS_H=\"freetype-custom/freetype/config/ftoption.h\"",
  ]

  if (!is_android) {
    # Selects type1cid.c and type1.c modules in
    # freetype-custom-include/freetype/config/ftmodule.h.
    defines += [ "PDFIUM_REQUIRED_MODULES" ]
  } else {
    # Using HarfBuzz assisted autohinting has a performance impact that we do
    # not want to take on Android, see crbug.com/724095.
    defines += [ "WITHOUT_HARFBUZZ" ]
  }

  if (!is_component_build) {
    defines += [ "CHROMIUM_RESTRICT_VISIBILITY" ]
  }
}

config("freetype_config") {
  configs = [ ":freetype_component_config" ]

  if (is_win && is_component_build) {
    # Used for managing declspec(dllimport/export) visibility.
    defines = [ "FT2_BUILD_DLL" ]
  }
}

config("freetype-warnings") {
  cflags = []

  if (is_clang) {
    # The reduction of FreeType files to a minimum triggers -Wunused-function
    # warnings in ftbase.c
    cflags += [
      # TODO(drott): Remove once we can roll past a commit that fixes:
      # https://savannah.nongnu.org/bugs/index.php?54852
      "-Wno-deprecated-declarations",

      "-Wno-unused-function",
    ]
  }
}

source_set("freetype_source") {
  visibility = [ "//third_party:freetype_harfbuzz" ]

  defines = []
  include_dirs = []

  # FreeType only exposes ft2build.h, all other FreeType headers are accessed by macro names.
  # gn check does not expand macros, so list only this header.
  public = [ "src/include/ft2build.h" ]

  sources = [
    "include/freetype-custom/freetype/config/ftmodule.h",
    "include/freetype-custom/freetype/config/ftoption.h",
    "include/freetype-custom/freetype/config/public-macros.h",
    "src/src/autofit/autofit.c",
    "src/src/base/ftbase.c",
    "src/src/base/ftbbox.c",
    "src/src/base/ftbitmap.c",
    "src/src/base/ftdebug.c",
    "src/src/base/ftfstype.c",
    "src/src/base/ftgasp.c",
    "src/src/base/ftglyph.c",
    "src/src/base/ftinit.c",
    "src/src/base/ftmm.c",
    "src/src/base/ftstroke.c",
    "src/src/base/fttype1.c",
    "src/src/cff/cff.c",
    "src/src/gzip/ftgzip.c",
    "src/src/psaux/psaux.c",
    "src/src/pshinter/pshinter.c",
    "src/src/psnames/psnames.c",
    "src/src/raster/raster.c",
    "src/src/sfnt/sfnt.c",
    "src/src/smooth/smooth.c",
    "src/src/truetype/truetype.c",
  ]

  # ftsystem.c provides implementations of FT_Memory and FT_Stream_Open.
  # While Chromium itself avoids using this code, any build of Chromium which
  # depends on //third_party/fontconfig:fontconfig with use_bundled_fontconfig
  # will make heavy use of these implementations, so use the best available.
  if (is_posix || is_fuchsia) {
    sources += [ "src/builds/unix/ftsystem.c" ]

    # builds/unix/ftsystem.c directly includes <ftconfig.h> instead of using
    # FT_CONFIG_CONFIG_H. The includes/freetype/config directory should not be
    # on the include path to avoid accidentally using the ftoption or ftmodule
    # from there.
    include_dirs += [ "src/include/freetype/config" ]

    # builds/unix/ftsystem.c requires the following defines to be set.
    defines += [
      "HAVE_UNISTD_H",
      "HAVE_FCNTL_H",
    ]
  } else {
    sources += [ "src/src/base/ftsystem.c" ]
  }

  if (!is_android) {
    sources += [
      "src/src/base/ftcid.c",
      "src/src/cid/type1cid.c",
      "src/src/type1/type1.c",
    ]
  }

  if (is_linux || is_chromeos || is_cast_android) {
    # Needed for content_shell on Linux and Chromecast, since fontconfig
    # requires FT_Get_BDF_Property.
    sources += [ "src/src/base/ftbdf.c" ]

    # Needed on Fedora whose libfreetype builds ftsynth.c containing
    # FT_GlyphSlot_Embolden, which we need to replace in content_shell if
    # we are linking against our own FreeType.
    sources += [ "src/src/base/ftsynth.c" ]
  }

  defines += [ "FT2_BUILD_LIBRARY" ]

  # Reduce the max number of hinting instructions per glyph when fuzzing.
  # The default limit is 1,000,000. Reduce to a more realistic 10,000.
  if (use_fuzzing_engine) {
    defines += [ "TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES=10000" ]
  }

  if (use_system_harfbuzz) {
    configs += [ "//third_party/harfbuzz-ng:harfbuzz_from_pkgconfig" ]
  } else {
    configs += [ "//third_party/harfbuzz-ng:harfbuzz_config" ]
  }
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]
  configs += [ "//build/config/sanitizers:cfi_icall_generalize_pointers" ]
  configs += [ ":freetype-warnings" ]

  public_configs = [ ":freetype_config" ]

  deps = [
    "//third_party/libpng",
    "//third_party/zlib",
  ]
}