Use system FreeType on Linux.
[pdfium.git] / BUILD.gn
index 2021b4c..9c58b03 100644 (file)
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -2,15 +2,22 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+import("//testing/test.gni")
+
 pdf_use_skia = false
 
+declare_args() {
+  # On Android there's no system FreeType. On Windows and Mac, only a few
+  # methods are used from it.
+  bundle_freetype = !is_linux
+}
+
 config("pdfium_config") {
   cflags = []
   defines = [
-    "FOXIT_CHROME_BUILD",
-    "_FXFT_VERSION_=2501",
     "_FPDFSDK_LIB",
     "_NO_GDIPLUS_",  # workaround text rendering issues on Windows
+    "OPJ_STATIC",
   ]
 
   if (pdf_use_skia) {
@@ -35,6 +42,13 @@ config("pdfium_config") {
       "/wd4345",
     ]
   }
+
+  if (bundle_freetype) {
+    include_dirs = [ "third_party/freetype/include" ]
+    defines += [ "FT2_BUILD_LIBRARY" ]
+  } else {
+    include_dirs = [ "/usr/include/freetype2" ]
+  }
 }
 
 static_library("pdfium") {
@@ -42,7 +56,6 @@ static_library("pdfium") {
     "fpdfsdk/include/fpdfdoc.h",
     "fpdfsdk/include/fpdfedit.h",
     "fpdfsdk/include/fpdfformfill.h",
-    "fpdfsdk/include/fpdfoom.h",
     "fpdfsdk/include/fpdftext.h",
     "fpdfsdk/include/fpdfview.h",
     "fpdfsdk/include/fpdf_dataavail.h",
@@ -60,7 +73,6 @@ static_library("pdfium") {
     "fpdfsdk/src/fpdfeditimg.cpp",
     "fpdfsdk/src/fpdfeditpage.cpp",
     "fpdfsdk/src/fpdfformfill.cpp",
-    "fpdfsdk/src/fpdfoom.cpp",
     "fpdfsdk/src/fpdfppo.cpp",
     "fpdfsdk/src/fpdfsave.cpp",
     "fpdfsdk/src/fpdftext.cpp",
@@ -85,12 +97,11 @@ static_library("pdfium") {
 
   libs = []
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 
   deps = [
+    "third_party:bigint",
+    "third_party:safemath",
     ":fdrm",
     ":formfiller",
     ":fpdfapi",
@@ -112,10 +123,16 @@ static_library("pdfium") {
   if (is_mac) {
     libs += [ "AppKit.framework", "CoreFoundation.framework" ]
   }
+
+  if (bundle_freetype) {
+    deps += [ "third_party:freetype" ]
+  } else {
+    libs += [ "freetype" ]
+  }
 }
 
 # Targets below this are only visible within this file.
-visibility = ":*"
+visibility = [ ":*" ]
 
 static_library("fdrm") {
   sources = [
@@ -125,9 +142,6 @@ static_library("fdrm") {
     "core/src/fdrm/crypto/fx_crypt_sha.cpp",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -157,9 +171,6 @@ static_library("fpdfdoc") {
     "core/src/fpdfdoc/tagged_int.h",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -261,7 +272,6 @@ static_library("fpdfapi") {
     "core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp",
     "core/src/fpdfapi/fpdf_page/fpdf_page_image.cpp",
     "core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp",
-    "core/src/fpdfapi/fpdf_page/fpdf_page_parser_new.cpp",
     "core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp",
     "core/src/fpdfapi/fpdf_page/fpdf_page_path.cpp",
     "core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp",
@@ -284,9 +294,6 @@ static_library("fpdfapi") {
     "core/src/fpdfapi/fpdf_render/render_int.h",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -302,9 +309,6 @@ static_library("fpdftext") {
     "core/src/fpdftext/unicodenormalizationdata.cpp",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -471,8 +475,11 @@ static_library("fxcodec") {
     "core/src/fxcodec/libjpeg/transupp.h",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
+
   if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
+    # core/src/fxcodec/fx_libopenjpeg/src/fx_mct.c does an pointer-to-int
+    # conversion to check that an address is 16-bit aligned (benign).
+    cflags_c = [ "-Wno-pointer-to-int-cast" ]
   }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
@@ -506,7 +513,6 @@ static_library("fxcrt") {
     "core/src/fxcrt/fx_basic_list.cpp",
     "core/src/fxcrt/fx_basic_maps.cpp",
     "core/src/fxcrt/fx_basic_memmgr.cpp",
-    "core/src/fxcrt/fx_basic_memmgr_mini.cpp",
     "core/src/fxcrt/fx_basic_plex.cpp",
     "core/src/fxcrt/fx_basic_utf.cpp",
     "core/src/fxcrt/fx_basic_util.cpp",
@@ -516,14 +522,10 @@ static_library("fxcrt") {
     "core/src/fxcrt/fx_unicode.cpp",
     "core/src/fxcrt/fx_xml_composer.cpp",
     "core/src/fxcrt/fx_xml_parser.cpp",
-    "core/src/fxcrt/mem_int.h",
     "core/src/fxcrt/plex.h",
     "core/src/fxcrt/xml_int.h",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -589,34 +591,7 @@ static_library("fxge") {
     "core/src/fxge/fontdata/chromefontdata/FoxitSerifItalic.c",
     "core/src/fxge/fontdata/chromefontdata/FoxitSerifMM.c",
     "core/src/fxge/fontdata/chromefontdata/FoxitSymbol.c",
-    "core/src/fxge/fx_freetype/include/fxft_cffobjs.h",
-    "core/src/fxge/fx_freetype/include/fxft_cfftypes.h",
-    "core/src/fxge/fx_freetype/include/fxft_freetype.h",
-    "core/src/fxge/fx_freetype/include/fxft_ft2build.h",
-    "core/src/fxge/fx_freetype/include/fxft_ftmm.h",
-    "core/src/fxge/fx_freetype/include/fxft_ftobjs.h",
-    "core/src/fxge/fx_freetype/include/fxft_ftotval.h",
-    "core/src/fxge/fx_freetype/include/fxft_ftoutln.h",
-    "core/src/fxge/fx_freetype/include/fxft_ftstream.h",
-    "core/src/fxge/fx_freetype/include/fxft_tttables.h",
-    "core/src/fxge/fx_freetype/include/fxft_tttypes.h",
-    "core/src/fxge/fx_freetype/src/fxft_cff.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftbase.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftbitmap.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftglyph.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftinit.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftlcdfil.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftmm.c",
-    "core/src/fxge/fx_freetype/src/fxft_ftsystem.c",
-    "core/src/fxge/fx_freetype/src/fxft_psaux.c",
-    "core/src/fxge/fx_freetype/src/fxft_pshinter.c",
-    "core/src/fxge/fx_freetype/src/fxft_psmodule.c",
-    "core/src/fxge/fx_freetype/src/fxft_raster.c",
-    "core/src/fxge/fx_freetype/src/fxft_sfnt.c",
-    "core/src/fxge/fx_freetype/src/fxft_smooth.c",
-    "core/src/fxge/fx_freetype/src/fxft_truetype.c",
-    "core/src/fxge/fx_freetype/src/fxft_type1.c",
-    "core/src/fxge/fx_freetype/src/fxft_type1cid.c",
+    "core/src/fxge/freetype/fx_freetype.c",
     "core/src/fxge/ge/fx_ge.cpp",
     "core/src/fxge/ge/fx_ge_device.cpp",
     "core/src/fxge/ge/fx_ge_font.cpp",
@@ -629,9 +604,6 @@ static_library("fxge") {
   ]
 
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 
   if (pdf_use_skia) {
@@ -664,7 +636,6 @@ static_library("fxge") {
     ]
     configs -= [
       "//build/config/win:lean_and_mean",
-      "//build/config/win:nominmax",
     ]
   }
 }
@@ -682,9 +653,6 @@ static_library("fxedit") {
     "fpdfsdk/src/fxedit/fxet_pageobjs.cpp",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -728,9 +696,6 @@ static_library("pdfwindow") {
     "fpdfsdk/src/pdfwindow/PWL_Wnd.cpp",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }
 
@@ -781,17 +746,18 @@ static_library("javascript") {
   ]
 
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
   include_dirs = [
+    "//v8",
     "//v8/include",
   ]
-  deps = [
+
+  public_deps = [
     "//v8",
   ]
-  forward_dependent_configs_from = [ "//v8" ]
+  deps = [
+    "//v8:v8_libplatform",
+  ]
 }
 
 static_library("jsapi") {
@@ -801,17 +767,15 @@ static_library("jsapi") {
   ]
 
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
   include_dirs = [
+    "//v8",
     "//v8/include",
   ]
-  deps = [
+
+  public_deps = [
     "//v8",
   ]
-  forward_dependent_configs_from = [ "//v8" ]
 }
 
 static_library("formfiller") {
@@ -841,8 +805,42 @@ static_library("formfiller") {
     "fpdfsdk/src/formfiller/FFL_Utils.cpp",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-  if (is_posix) {
-    configs -= [ "//build/config/gcc:no_exceptions" ]
-  }
+  configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
+}
+
+test("pdfium_unittests") {
+  sources = [
+    "core/src/fxcrt/fx_basic_bstring_unittest.cpp",
+    "core/src/fxcrt/fx_basic_wstring_unittest.cpp",
+    "testing/fx_string_testhelpers.cpp",
+    "testing/fx_string_testhelpers.h",
+  ]
+  deps = [
+    "//testing/gtest",
+    "//testing/gtest:gtest_main",
+    ":pdfium"
+  ]
+  include_dirs = [ "." ]
+  configs -= [ "//build/config/compiler:chromium_code" ]
+  configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
+}
+
+test("pdfium_embeddertests") {
+  sources = [
+    "fpdfsdk/src/fpdf_dataavail_embeddertest.cpp",
+    "fpdfsdk/src/fpdfdoc_embeddertest.cpp",
+    "fpdfsdk/src/fpdftext_embeddertest.cpp",
+    "fpdfsdk/src/fpdfview_embeddertest.cpp",
+    "testing/embedder_test.cpp",
+    "testing/embedder_test.h",
+    "testing/fx_string_testhelpers.cpp",
+    "testing/fx_string_testhelpers.h",
+  ]
+  deps = [
+    "//testing/gtest",
+    ":pdfium"
+  ]
+  include_dirs = [ "." ]
+  configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [ ":pdfium_config", "//build/config/compiler:no_chromium_code" ]
 }