• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The PDFium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/clang/clang.gni")
6import("//build/config/gclient_args.gni")
7import("//testing/test.gni")
8import("pdfium.gni")
9
10group("default") {
11  testonly = true
12  deps = [ ":pdfium" ]
13  if (pdf_is_standalone) {
14    deps += [ ":pdfium_all" ]
15  }
16}
17
18group("freetype_common") {
19  public_deps = []
20  if (pdf_bundle_freetype) {
21    public_deps += [ "third_party:fx_freetype" ]
22  } else {
23    public_deps += [ "//build/config/freetype" ]
24  }
25}
26
27config("pdfium_common_config") {
28  cflags = []
29  cflags_cc = []
30  ldflags = []
31  include_dirs = [ "." ]
32  defines = []
33
34  if (!use_system_libopenjpeg2) {
35    defines += [ "OPJ_STATIC" ]
36  }
37
38  if (pdf_enable_click_logging) {
39    defines += [ "PDF_ENABLE_CLICK_LOGGING" ]
40  }
41
42  if (pdf_use_skia && pdf_enable_fontations) {
43    defines += [ "PDF_ENABLE_FONTATIONS" ]
44  }
45
46  if (pdf_use_partition_alloc) {
47    defines += [ "PDF_USE_PARTITION_ALLOC" ]
48  }
49
50  if (is_win) {
51    # Assume UTF-8 by default to avoid code page dependencies.
52    cflags += [ "/utf-8" ]
53
54    if (!is_clang) {
55      cflags += [
56        # Warnings permanently disabled:
57
58        # C4091: 'typedef ': ignored on left of 'X' when no variable is
59        #                    declared.
60        # This happens in a number of Windows headers. Dumb.
61        "/wd4091",
62
63        # C4127: conditional expression is constant
64        # This warning can in theory catch dead code and other problems, but
65        # triggers in far too many desirable cases where the conditional
66        # expression is either set by macros or corresponds some legitimate
67        # compile-time constant expression (due to constant template args,
68        # conditionals comparing the sizes of different types, etc.).  Some of
69        # these can be worked around, but it's not worth it.
70        "/wd4127",
71
72        # C4251: 'identifier' : class 'type' needs to have dll-interface to be
73        #        used by clients of class 'type2'
74        # This is necessary for the shared library build.
75        "/wd4251",
76
77        # C4275:  non dll-interface class used as base for dll-interface class
78        # This points out a potential (but rare) problem with referencing static
79        # fields of a non-exported base, through the base's non-exported inline
80        # functions, or directly. The warning is subtle enough that people just
81        # suppressed it when they saw it, so it's not worth it.
82        "/wd4275",
83
84        # C4312 is a VS 2015 64-bit warning for integer to larger pointer.
85        # TODO(brucedawson): fix warnings, crbug.com/554200
86        "/wd4312",
87
88        # C4324 warns when padding is added to fulfill alignas requirements,
89        # but can trigger in benign cases that are difficult to individually
90        # suppress.
91        "/wd4324",
92
93        # C4351: new behavior: elements of array 'array' will be default
94        #        initialized
95        # This is a silly "warning" that basically just alerts you that the
96        # compiler is going to actually follow the language spec like it's
97        # supposed to, instead of not following it like old buggy versions did.
98        # There's absolutely no reason to turn this on.
99        "/wd4351",
100
101        # C4355: 'this': used in base member initializer list
102        # It's commonly useful to pass |this| to objects in a class' initializer
103        # list.  While this warning can catch real bugs, most of the time the
104        # constructors in question don't attempt to call methods on the passed-in
105        # pointer (until later), and annotating every legit usage of this is
106        # simply more hassle than the warning is worth.
107        "/wd4355",
108
109        # C4503: 'identifier': decorated name length exceeded, name was
110        #        truncated
111        # This only means that some long error messages might have truncated
112        # identifiers in the presence of lots of templates.  It has no effect on
113        # program correctness and there's no real reason to waste time trying to
114        # prevent it.
115        "/wd4503",
116
117        # Warning C4589 says: "Constructor of abstract class ignores
118        # initializer for virtual base class." Disable this warning because it
119        # is flaky in VS 2015 RTM. It triggers on compiler generated
120        # copy-constructors in some cases.
121        "/wd4589",
122
123        # C4611: interaction between 'function' and C++ object destruction is
124        #        non-portable
125        # This warning is unavoidable when using e.g. setjmp/longjmp.  MSDN
126        # suggests using exceptions instead of setjmp/longjmp for C++, but
127        # Chromium code compiles without exception support.  We therefore have to
128        # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
129        # have to turn off this warning (and be careful about how object
130        # destruction happens in such cases).
131        "/wd4611",
132
133        # Warnings to evaluate and possibly fix/reenable later:
134
135        "/wd4100",  # Unreferenced formal function parameter.
136        "/wd4121",  # Alignment of a member was sensitive to packing.
137        "/wd4244",  # Conversion: possible loss of data.
138        "/wd4505",  # Unreferenced local function has been removed.
139        "/wd4510",  # Default constructor could not be generated.
140        "/wd4512",  # Assignment operator could not be generated.
141        "/wd4610",  # Class can never be instantiated, constructor required.
142        "/wd4838",  # Narrowing conversion. Doesn't seem to be very useful.
143        "/wd4995",  # 'X': name was marked as #pragma deprecated
144        "/wd4996",  # Deprecated function warning.
145
146        # These are variable shadowing warnings that are new in VS2015. We
147        # should work through these at some point -- they may be removed from
148        # the RTM release in the /W4 set.
149        "/wd4456",
150        "/wd4457",
151        "/wd4458",
152        "/wd4459",
153
154        # All of our compilers support the extensions below.
155        "/wd4200",  # nonstandard extension used: zero-sized array in
156                    # struct/union
157        "/wd4201",  # nonstandard extension used: nameless struct/union
158        "/wd4204",  # nonstandard extension used : non-constant aggregate
159                    # initializer
160
161        "/wd4221",  # nonstandard extension used : 'identifier' : cannot be
162                    # initialized using address of automatic variable
163
164        # http://crbug.com/588506 - Conversion suppressions waiting on Clang
165        # -Wconversion.
166        "/wd4245",  # 'conversion' : conversion from 'type1' to 'type2',
167                    # signed/unsigned mismatch
168
169        "/wd4267",  # 'var' : conversion from 'size_t' to 'type', possible loss
170                    # of data
171
172        "/wd4305",  # 'identifier' : truncation from 'type1' to 'type2'
173        "/wd4389",  # 'operator' : signed/unsigned mismatch
174
175        "/wd4702",  # unreachable code
176
177        # http://crbug.com/848979 - MSVC is more conservative than Clang with
178        # regards to variables initialized and consumed in different branches.
179        "/wd4701",  # Potentially uninitialized local variable 'name' used
180        "/wd4703",  # Potentially uninitialized local pointer variable 'name'
181                    # used
182
183        # http://crbug.com/848979 - Remaining Clang permitted warnings.
184        "/wd4661",  # 'identifier' : no suitable definition provided for
185                    # explicit
186                    # template instantiation request
187
188        "/wd4706",  # assignment within conditional expression
189                    # MSVC is stricter and requires a boolean expression.
190
191        "/wd4715",  # 'function' : not all control paths return a value'
192                    # MSVC does not analyze switch (enum) for completeness.
193      ]
194
195      cflags_cc += [
196        # Allow "noexcept" annotations even though we compile with exceptions
197        # disabled.
198        "/wd4577",
199      ]
200
201      if (current_cpu == "x86") {
202        if (msvc_use_sse2) {
203          cflags += [ "/arch:SSE2" ]
204        }
205      }
206    }
207  }
208
209  if (is_clang) {
210    # Override -Wno-c++11-narrowing.
211    cflags += [ "-Wc++11-narrowing" ]
212
213    # May flag some issues when converting int to size_t.
214    cflags += [ "-Wtautological-unsigned-zero-compare" ]
215  }
216
217  if (!is_win && !is_clang) {
218    cflags += [
219      # Override -Wno-narrowing for GCC.
220      "-Wnarrowing",
221
222      # GCC assumes that control can get past an exhaustive switch and then
223      # warns if there's no return there.
224      "-Wno-return-type",
225    ]
226  }
227
228  if (clang_use_chrome_plugins) {
229    defines += [ "PDF_USE_CHROME_PLUGINS" ]
230
231    # Catch misuse of C-style pointers.
232    # TODO(crbug.com/1320670): enable for non-debug builds once this stops
233    # interfering with code generation.
234    # TODO(tsepez): enable for windows, too.
235    if (is_debug && !is_win) {
236      cflags += [
237        "-Xclang",
238        "-plugin-arg-raw-ptr-plugin",
239        "-Xclang",
240        "check-raw-ptr-fields",
241
242        "-Xclang",
243        "-plugin-arg-raw-ptr-plugin",
244        "-Xclang",
245        "raw-ptr-exclude-path=public",
246
247        "-Xclang",
248        "-plugin-arg-raw-ptr-plugin",
249        "-Xclang",
250        "raw-ptr-exclude-path=test",
251
252        # TODO(tsepez): enforce raw_ref<> as well.
253        # "-Xclang",
254        # "-plugin-arg-raw-ptr-plugin",
255        # "-Xclang",
256        # "check-raw-ref-fields",
257      ]
258      defines += [ "PDF_ENABLE_UNOWNED_PTR_EXCLUSION" ]
259    }
260
261    # Catch misuse of cppgc in XFA.
262    if (pdf_enable_xfa) {
263      cflags += [
264        "-Xclang",
265        "-add-plugin",
266        "-Xclang",
267        "blink-gc-plugin",
268      ]
269
270      # Disable GC plugin forbidding off-heap collections of GCed:
271      cflags += [
272        "-Xclang",
273        "-plugin-arg-blink-gc-plugin",
274        "-Xclang",
275        "disable-off-heap-collections-of-gced-check",
276      ]
277    }
278  }
279}
280
281config("pdfium_implementation_config") {
282  defines = [ "FPDF_IMPLEMENTATION" ]
283  visibility = [ ":pdfium_public_headers" ]
284}
285
286config("pdfium_public_config") {
287  defines = []
288
289  if (pdf_enable_v8) {
290    defines += [ "PDF_ENABLE_V8" ]
291
292    if (pdf_enable_xfa) {
293      defines += [ "PDF_ENABLE_XFA" ]
294      if (pdf_enable_xfa_bmp) {
295        defines += [ "PDF_ENABLE_XFA_BMP" ]
296      }
297      if (pdf_enable_xfa_gif) {
298        defines += [ "PDF_ENABLE_XFA_GIF" ]
299      }
300      if (pdf_enable_xfa_png) {
301        defines += [ "PDF_ENABLE_XFA_PNG" ]
302      }
303      if (pdf_enable_xfa_tiff) {
304        defines += [ "PDF_ENABLE_XFA_TIFF" ]
305      }
306    }
307  }
308
309  if (pdf_use_skia) {
310    defines += [ "PDF_USE_SKIA" ]
311  }
312}
313
314config("pdfium_core_config") {
315  cflags = []
316  configs = [
317    ":pdfium_common_config",
318    ":pdfium_public_config",
319    "//build/config/compiler:noshadowing",
320  ]
321  defines = []
322  if (is_win) {
323    cflags += [
324      "/wd4324",
325      "/wd4577",
326    ]
327  }
328  if (is_clang) {
329    cflags += [ "-Wcovered-switch-default" ]
330  }
331}
332
333config("pdfium_strict_config") {
334  configs = [
335    ":pdfium_core_config",
336    "//build/config/compiler:wexit_time_destructors",
337    "//build/config/compiler:wglobal_constructors",
338  ]
339}
340
341config("pdfium_noshorten_config") {
342  cflags = []
343  if (is_clang) {
344    cflags += [ "-Wshorten-64-to-32" ]
345  }
346}
347
348source_set("pdfium_public_headers_impl") {
349  sources = [
350    "public/cpp/fpdf_deleters.h",
351    "public/cpp/fpdf_scopers.h",
352    "public/fpdf_annot.h",
353    "public/fpdf_attachment.h",
354    "public/fpdf_catalog.h",
355    "public/fpdf_dataavail.h",
356    "public/fpdf_doc.h",
357    "public/fpdf_edit.h",
358    "public/fpdf_ext.h",
359    "public/fpdf_flatten.h",
360    "public/fpdf_formfill.h",
361    "public/fpdf_fwlevent.h",
362    "public/fpdf_javascript.h",
363    "public/fpdf_ppo.h",
364    "public/fpdf_progressive.h",
365    "public/fpdf_save.h",
366    "public/fpdf_searchex.h",
367    "public/fpdf_signature.h",
368    "public/fpdf_structtree.h",
369    "public/fpdf_sysfontinfo.h",
370    "public/fpdf_text.h",
371    "public/fpdf_transformpage.h",
372    "public/fpdfview.h",
373  ]
374}
375
376group("pdfium_public_headers") {
377  public_deps = [ ":pdfium_public_headers_impl" ]
378  public_configs = [
379    ":pdfium_public_config",
380    ":pdfium_implementation_config",
381  ]
382}
383
384component("pdfium") {
385  output_name = "pdfium"
386  libs = []
387  configs += [ ":pdfium_strict_config" ]
388  public_configs = [ ":pdfium_public_config" ]
389
390  deps = [
391    "constants",
392    "core/fpdfapi/page",
393    "core/fpdfapi/parser",
394    "core/fpdfdoc",
395    "core/fxcodec",
396    "core/fxcrt",
397    "core/fxge",
398    "fpdfsdk",
399    "fpdfsdk/formfiller",
400    "fxjs",
401  ]
402
403  public_deps = [
404    ":pdfium_public_headers_impl",
405    "core/fxcrt",
406  ]
407
408  if (pdf_enable_xfa) {
409    deps += [
410      "fpdfsdk/fpdfxfa",
411      "xfa/fxfa",
412      "xfa/fxfa/parser",
413    ]
414  }
415
416  if (is_win) {
417    libs += [
418      "advapi32.lib",
419      "gdi32.lib",
420      "user32.lib",
421    ]
422  }
423
424  if (is_mac) {
425    frameworks = [
426      "AppKit.framework",
427      "CoreFoundation.framework",
428    ]
429  }
430
431  if (pdf_is_complete_lib) {
432    static_component_type = "static_library"
433    complete_static_lib = true
434    configs -= [ "//build/config/compiler:thin_archive" ]
435  }
436}
437
438# Targets below this are only visible within this file.
439visibility = [ ":*" ]
440
441group("pdfium_unittest_deps") {
442  testonly = true
443  public_deps = [
444    "core/fxcrt",
445    "testing:unit_test_support",
446    "//testing/gmock",
447    "//testing/gtest",
448  ]
449  visibility += [
450    "core/*",
451    "fpdfsdk/*",
452    "fxbarcode/*",
453    "fxjs/*",
454    "xfa/*",
455  ]
456}
457
458test("pdfium_unittests") {
459  testonly = true
460  sources = [ "testing/unit_test_main.cpp" ]
461  deps = [
462    "core/fdrm:unittests",
463    "core/fpdfapi/edit:unittests",
464    "core/fpdfapi/font:unittests",
465    "core/fpdfapi/page:unittests",
466    "core/fpdfapi/parser:unittests",
467    "core/fpdfapi/render:unittests",
468    "core/fpdfdoc:unittests",
469    "core/fpdftext:unittests",
470    "core/fxcodec:unittests",
471    "core/fxcrt",
472    "core/fxcrt:unittests",
473    "core/fxge:unittests",
474    "fpdfsdk:unittests",
475    "testing:unit_test_support",
476    "//testing/gmock",
477    "//testing/gtest",
478  ]
479  configs += [ ":pdfium_core_config" ]
480  if (is_android) {
481    use_raw_android_executable = true
482  }
483  if (pdf_enable_v8) {
484    configs += [ "//v8:external_startup_data" ]
485    deps += [
486      "fxjs:unittests",
487      "//v8",
488    ]
489    if (pdf_enable_xfa) {
490      deps += [
491        "core/fxcrt/css:unittests",
492        "fxbarcode:unittests",
493        "xfa/fde:unittests",
494        "xfa/fgas/crt:unittests",
495        "xfa/fgas/font:unittests",
496        "xfa/fgas/layout:unittests",
497        "xfa/fxfa:unittests",
498        "xfa/fxfa/formcalc:unittests",
499        "xfa/fxfa/parser:unittests",
500      ]
501    }
502  }
503}
504
505group("pdfium_embeddertest_deps") {
506  testonly = true
507  public_deps = [
508    ":pdfium_public_headers",
509    "core/fxcrt",
510    "testing:embedder_test_support",
511    "//testing/gmock",
512    "//testing/gtest",
513  ]
514  visibility += [
515    "core/*",
516    "fpdfsdk/*",
517    "fxjs/*",
518    "xfa/*",
519  ]
520}
521
522test("pdfium_embeddertests") {
523  testonly = true
524  sources = [ "testing/embedder_test_main.cpp" ]
525  deps = [
526    ":pdfium_embeddertest_deps",
527    "core/fpdfapi/edit:embeddertests",
528    "core/fpdfapi/parser:embeddertests",
529    "core/fpdfapi/render:embeddertests",
530    "core/fxcodec:embeddertests",
531    "core/fxcrt",
532    "core/fxge:embeddertests",
533    "fpdfsdk:embeddertests",
534    "fpdfsdk/formfiller:embeddertests",
535    "fpdfsdk/pwl:embeddertests",
536    "testing/image_diff",
537    "//testing/gmock",
538    "//testing/gtest",
539  ]
540  include_dirs = [ "testing/gmock/include" ]
541  configs += [ ":pdfium_core_config" ]
542
543  if (is_android) {
544    ignore_all_data_deps = true
545    use_raw_android_executable = true
546  }
547
548  if (pdf_enable_v8) {
549    deps += [
550      "fxjs:embeddertests",
551      "//v8",
552    ]
553    configs += [ "//v8:external_startup_data" ]
554  }
555
556  if (pdf_enable_xfa) {
557    deps += [
558      "fpdfsdk/fpdfxfa:embeddertests",
559      "xfa/fwl:embeddertests",
560      "xfa/fxfa/layout:embeddertests",
561      "xfa/fxfa/parser:embeddertests",
562    ]
563  }
564}
565
566executable("pdfium_diff") {
567  visibility += [ "testing/tools:test_runner_py" ]
568  testonly = true
569  sources = [ "testing/image_diff/image_diff.cpp" ]
570  deps = [
571    "core/fxcrt",
572    "testing:path_service",
573    "testing/image_diff",
574    "//build/win:default_exe_manifest",
575  ]
576  configs += [ ":pdfium_strict_config" ]
577}
578
579group("pdfium_all") {
580  testonly = true
581  deps = [
582    ":pdfium_diff",
583    ":pdfium_embeddertests",
584    ":pdfium_unittests",
585    "testing:pdfium_test",
586    "testing/fuzzers",
587  ]
588
589  if (pdf_is_standalone) {
590    deps += [ "testing/tools:test_runner_py" ]
591  }
592}
593
594# Makes additional targets reachable only for "gn check". These are not always
595# built by the "all" Ninja target, which uses the "default" group, which in turn
596# depends on the "pdfium_all" group.
597group("gn_check") {
598  deps = []
599
600  # TODO(crbug.com/pdfium/1832): Remove !is_android when //third_party/expat is
601  # available.
602  if (defined(checkout_skia) && checkout_skia && !is_android) {
603    deps += [ "//skia" ]
604  }
605}
606