aboutsummaryrefslogtreecommitdiff
path: root/BUILD.gn
blob: 07a5b933a95dcfbb37f05f1f7b3fb62af10c31f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# Copyright 2016 The PDFium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/clang/clang.gni")
import("//build/config/gclient_args.gni")
import("//testing/test.gni")
import("pdfium.gni")

group("default") {
  testonly = true
  deps = [ ":pdfium" ]
  if (pdf_is_standalone) {
    deps += [ ":pdfium_all" ]
  }
}

group("freetype_common") {
  public_deps = []
  if (pdf_bundle_freetype) {
    public_deps += [ "third_party:fx_freetype" ]
  } else {
    public_deps += [ "//build/config/freetype" ]
  }
}

config("pdfium_common_config") {
  cflags = []
  cflags_cc = []
  ldflags = []
  include_dirs = [ "." ]
  defines = []

  if (!use_system_libopenjpeg2) {
    defines += [ "OPJ_STATIC" ]
  }

  if (pdf_enable_click_logging) {
    defines += [ "PDF_ENABLE_CLICK_LOGGING" ]
  }

  if (pdf_use_skia) {
    defines += [ "_SKIA_SUPPORT_" ]
  }

  if (pdf_use_partition_alloc) {
    defines += [ "PDF_USE_PARTITION_ALLOC" ]
  }

  if (is_win) {
    # Assume UTF-8 by default to avoid code page dependencies.
    cflags += [ "/utf-8" ]

    if (!is_clang) {
      cflags += [
        # Warnings permanently disabled:

        # C4091: 'typedef ': ignored on left of 'X' when no variable is
        #                    declared.
        # This happens in a number of Windows headers. Dumb.
        "/wd4091",

        # C4127: conditional expression is constant
        # This warning can in theory catch dead code and other problems, but
        # triggers in far too many desirable cases where the conditional
        # expression is either set by macros or corresponds some legitimate
        # compile-time constant expression (due to constant template args,
        # conditionals comparing the sizes of different types, etc.).  Some of
        # these can be worked around, but it's not worth it.
        "/wd4127",

        # C4251: 'identifier' : class 'type' needs to have dll-interface to be
        #        used by clients of class 'type2'
        # This is necessary for the shared library build.
        "/wd4251",

        # C4275:  non dll-interface class used as base for dll-interface class
        # This points out a potential (but rare) problem with referencing static
        # fields of a non-exported base, through the base's non-exported inline
        # functions, or directly. The warning is subtle enough that people just
        # suppressed it when they saw it, so it's not worth it.
        "/wd4275",

        # C4312 is a VS 2015 64-bit warning for integer to larger pointer.
        # TODO(brucedawson): fix warnings, crbug.com/554200
        "/wd4312",

        # C4324 warns when padding is added to fulfill alignas requirements,
        # but can trigger in benign cases that are difficult to individually
        # suppress.
        "/wd4324",

        # C4351: new behavior: elements of array 'array' will be default
        #        initialized
        # This is a silly "warning" that basically just alerts you that the
        # compiler is going to actually follow the language spec like it's
        # supposed to, instead of not following it like old buggy versions did.
        # There's absolutely no reason to turn this on.
        "/wd4351",

        # C4355: 'this': used in base member initializer list
        # It's commonly useful to pass |this| to objects in a class' initializer
        # list.  While this warning can catch real bugs, most of the time the
        # constructors in question don't attempt to call methods on the passed-in
        # pointer (until later), and annotating every legit usage of this is
        # simply more hassle than the warning is worth.
        "/wd4355",

        # C4503: 'identifier': decorated name length exceeded, name was
        #        truncated
        # This only means that some long error messages might have truncated
        # identifiers in the presence of lots of templates.  It has no effect on
        # program correctness and there's no real reason to waste time trying to
        # prevent it.
        "/wd4503",

        # Warning C4589 says: "Constructor of abstract class ignores
        # initializer for virtual base class." Disable this warning because it
        # is flaky in VS 2015 RTM. It triggers on compiler generated
        # copy-constructors in some cases.
        "/wd4589",

        # C4611: interaction between 'function' and C++ object destruction is
        #        non-portable
        # This warning is unavoidable when using e.g. setjmp/longjmp.  MSDN
        # suggests using exceptions instead of setjmp/longjmp for C++, but
        # Chromium code compiles without exception support.  We therefore have to
        # use setjmp/longjmp for e.g. JPEG decode error handling, which means we
        # have to turn off this warning (and be careful about how object
        # destruction happens in such cases).
        "/wd4611",

        # Warnings to evaluate and possibly fix/reenable later:

        "/wd4100",  # Unreferenced formal function parameter.
        "/wd4121",  # Alignment of a member was sensitive to packing.
        "/wd4244",  # Conversion: possible loss of data.
        "/wd4505",  # Unreferenced local function has been removed.
        "/wd4510",  # Default constructor could not be generated.
        "/wd4512",  # Assignment operator could not be generated.
        "/wd4610",  # Class can never be instantiated, constructor required.
        "/wd4838",  # Narrowing conversion. Doesn't seem to be very useful.
        "/wd4995",  # 'X': name was marked as #pragma deprecated
        "/wd4996",  # Deprecated function warning.

        # These are variable shadowing warnings that are new in VS2015. We
        # should work through these at some point -- they may be removed from
        # the RTM release in the /W4 set.
        "/wd4456",
        "/wd4457",
        "/wd4458",
        "/wd4459",

        # All of our compilers support the extensions below.
        "/wd4200",  # nonstandard extension used: zero-sized array in
                    # struct/union
        "/wd4201",  # nonstandard extension used: nameless struct/union
        "/wd4204",  # nonstandard extension used : non-constant aggregate
                    # initializer

        "/wd4221",  # nonstandard extension used : 'identifier' : cannot be
                    # initialized using address of automatic variable

        # http://crbug.com/588506 - Conversion suppressions waiting on Clang
        # -Wconversion.
        "/wd4245",  # 'conversion' : conversion from 'type1' to 'type2',
                    # signed/unsigned mismatch

        "/wd4267",  # 'var' : conversion from 'size_t' to 'type', possible loss
                    # of data

        "/wd4305",  # 'identifier' : truncation from 'type1' to 'type2'
        "/wd4389",  # 'operator' : signed/unsigned mismatch

        "/wd4702",  # unreachable code

        # http://crbug.com/848979 - MSVC is more conservative than Clang with
        # regards to variables initialized and consumed in different branches.
        "/wd4701",  # Potentially uninitialized local variable 'name' used
        "/wd4703",  # Potentially uninitialized local pointer variable 'name'
                    # used

        # http://crbug.com/848979 - Remaining Clang permitted warnings.
        "/wd4661",  # 'identifier' : no suitable definition provided for
                    # explicit
                    # template instantiation request

        "/wd4706",  # assignment within conditional expression
                    # MSVC is stricter and requires a boolean expression.

        "/wd4715",  # 'function' : not all control paths return a value'
                    # MSVC does not analyze switch (enum) for completeness.
      ]

      cflags_cc += [
        # Allow "noexcept" annotations even though we compile with exceptions
        # disabled.
        "/wd4577",
      ]

      if (current_cpu == "x86") {
        if (msvc_use_sse2) {
          cflags += [ "/arch:SSE2" ]
        }
      }
    }
  }

  if (is_clang) {
    # Override -Wno-c++11-narrowing.
    cflags += [ "-Wc++11-narrowing" ]

    # TODO(crbug.com/1213098): Remove once this is in //build.
    cflags += [ "-Wdeprecated-copy" ]

    # May flag some issues when converting int to size_t.
    cflags += [ "-Wtautological-unsigned-zero-compare" ]
  }

  if (!is_win && !is_clang) {
    cflags += [
      # Override -Wno-narrowing for GCC.
      "-Wnarrowing",

      # GCC assumes that control can get past an exhaustive switch and then
      # warns if there's no return there.
      "-Wno-return-type",
    ]
  }
}

config("pdfium_implementation_config") {
  defines = [ "FPDF_IMPLEMENTATION" ]
  visibility = [ ":pdfium_public_headers" ]
}

config("pdfium_public_config") {
  defines = []

  if (pdf_enable_v8) {
    defines += [ "PDF_ENABLE_V8" ]

    if (pdf_enable_xfa) {
      defines += [ "PDF_ENABLE_XFA" ]
      if (pdf_enable_xfa_bmp) {
        defines += [ "PDF_ENABLE_XFA_BMP" ]
      }
      if (pdf_enable_xfa_gif) {
        defines += [ "PDF_ENABLE_XFA_GIF" ]
      }
      if (pdf_enable_xfa_png) {
        defines += [ "PDF_ENABLE_XFA_PNG" ]
      }
      if (pdf_enable_xfa_tiff) {
        defines += [ "PDF_ENABLE_XFA_TIFF" ]
      }
    }
  }
}

config("pdfium_core_config") {
  cflags = []
  configs = [
    ":pdfium_common_config",
    ":pdfium_public_config",
    "//build/config/compiler:noshadowing",
  ]
  defines = []
  if (is_win) {
    cflags += [
      "/wd4324",
      "/wd4577",
    ]
  }
  if (is_clang) {
    cflags += [ "-Wcovered-switch-default" ]
  }
}

config("pdfium_plugin_config") {
  cflags = []
  defines = []
  if (clang_use_chrome_plugins) {
    # Catch misuse of C-style pointers.
    # TODO(tsepez): enable for windows, too.
    if (!is_win) {
      cflags += [
        "-Xclang",
        "-plugin-arg-find-bad-constructs",
        "-Xclang",
        "check-raw-ptr-fields",

        "-Xclang",
        "-plugin-arg-find-bad-constructs",
        "-Xclang",
        "raw-ptr-exclude-path=public",

        "-Xclang",
        "-plugin-arg-find-bad-constructs",
        "-Xclang",
        "raw-ptr-exclude-path=test",

        # TODO(tsepez): enforce raw_ref<> as well.
        # "-Xclang",
        # "-plugin-arg-find-bad-constructs",
        # "-Xclang",
        # "check-raw-ref-fields",
      ]
      defines += [ "PDF_ENABLE_UNOWNED_PTR_EXCLUSION" ]
    }

    # Catch misuse of cppgc in XFA.
    if (pdf_enable_xfa) {
      cflags += [
        "-Xclang",
        "-add-plugin",
        "-Xclang",
        "blink-gc-plugin",
      ]
    }
  }
}

config("pdfium_strict_config") {
  configs = [
    ":pdfium_core_config",
    ":pdfium_plugin_config",
    "//build/config/compiler:wexit_time_destructors",
    "//build/config/compiler:wglobal_constructors",
  ]
}

config("pdfium_noshorten_config") {
  cflags = []
  if (is_clang) {
    cflags += [ "-Wshorten-64-to-32" ]
  }
}

source_set("pdfium_public_headers_impl") {
  sources = [
    "public/cpp/fpdf_deleters.h",
    "public/cpp/fpdf_scopers.h",
    "public/fpdf_annot.h",
    "public/fpdf_attachment.h",
    "public/fpdf_catalog.h",
    "public/fpdf_dataavail.h",
    "public/fpdf_doc.h",
    "public/fpdf_edit.h",
    "public/fpdf_ext.h",
    "public/fpdf_flatten.h",
    "public/fpdf_formfill.h",
    "public/fpdf_fwlevent.h",
    "public/fpdf_javascript.h",
    "public/fpdf_ppo.h",
    "public/fpdf_progressive.h",
    "public/fpdf_save.h",
    "public/fpdf_searchex.h",
    "public/fpdf_signature.h",
    "public/fpdf_structtree.h",
    "public/fpdf_sysfontinfo.h",
    "public/fpdf_text.h",
    "public/fpdf_transformpage.h",
    "public/fpdfview.h",
  ]
}

group("pdfium_public_headers") {
  public_deps = [ ":pdfium_public_headers_impl" ]
  public_configs = [
    ":pdfium_public_config",
    ":pdfium_implementation_config",
  ]
}

component("pdfium") {
  output_name = "pdfium"
  libs = []
  configs += [ ":pdfium_strict_config" ]
  public_configs = [ ":pdfium_public_config" ]

  deps = [
    "constants",
    "core/fpdfapi/page",
    "core/fpdfapi/parser",
    "core/fpdfdoc",
    "core/fxcodec",
    "core/fxcrt",
    "core/fxge",
    "fpdfsdk",
    "fpdfsdk/formfiller",
    "fxjs",
    "third_party:pdfium_base",
  ]

  public_deps = [
    ":pdfium_public_headers_impl",
    "core/fxcrt",
  ]

  if (pdf_enable_xfa) {
    deps += [
      "fpdfsdk/fpdfxfa",
      "xfa/fxfa",
      "xfa/fxfa/parser",
    ]
  }

  if (is_win) {
    libs += [
      "advapi32.lib",
      "gdi32.lib",
      "user32.lib",
    ]
  }

  if (is_mac) {
    frameworks = [
      "AppKit.framework",
      "CoreFoundation.framework",
    ]
  }

  if (pdf_is_complete_lib) {
    static_component_type = "static_library"
    complete_static_lib = true
    configs -= [ "//build/config/compiler:thin_archive" ]
  }
}

# Targets below this are only visible within this file.
visibility = [ ":*" ]

group("pdfium_unittest_deps") {
  testonly = true
  public_deps = [
    "core/fxcrt",
    "testing:unit_test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]
  visibility += [
    "core/*",
    "fpdfsdk/*",
    "fxbarcode/*",
    "fxjs/*",
    "xfa/*",
  ]
}

test("pdfium_unittests") {
  testonly = true
  sources = [ "testing/unit_test_main.cpp" ]
  deps = [
    "core/fdrm:unittests",
    "core/fpdfapi/edit:unittests",
    "core/fpdfapi/font:unittests",
    "core/fpdfapi/page:unittests",
    "core/fpdfapi/parser:unittests",
    "core/fpdfapi/render:unittests",
    "core/fpdfdoc:unittests",
    "core/fpdftext:unittests",
    "core/fxcodec:unittests",
    "core/fxcrt",
    "core/fxcrt:unittests",
    "core/fxge:unittests",
    "fpdfsdk:unittests",
    "testing:unit_test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]
  configs += [ ":pdfium_core_config" ]
  if (is_android) {
    use_raw_android_executable = true
  }
  if (pdf_enable_v8) {
    configs += [ "//v8:external_startup_data" ]
    deps += [
      "fxjs:unittests",
      "//v8",
    ]
    if (pdf_enable_xfa) {
      deps += [
        "core/fxcrt/css:unittests",
        "fxbarcode:unittests",
        "xfa/fde:unittests",
        "xfa/fgas/crt:unittests",
        "xfa/fgas/font:unittests",
        "xfa/fgas/layout:unittests",
        "xfa/fxfa:unittests",
        "xfa/fxfa/formcalc:unittests",
        "xfa/fxfa/parser:unittests",
      ]
    }
  }
}

group("pdfium_embeddertest_deps") {
  testonly = true
  public_deps = [
    ":pdfium_public_headers",
    "core/fxcrt",
    "testing:embedder_test_support",
    "third_party:pdfium_base_test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]
  visibility += [
    "core/*",
    "fpdfsdk/*",
    "fxjs/*",
    "xfa/*",
  ]
}

test("pdfium_embeddertests") {
  testonly = true
  sources = [ "testing/embedder_test_main.cpp" ]
  deps = [
    ":pdfium_embeddertest_deps",
    "core/fpdfapi/edit:embeddertests",
    "core/fpdfapi/parser:embeddertests",
    "core/fpdfapi/render:embeddertests",
    "core/fxcodec:embeddertests",
    "core/fxcrt",
    "core/fxge:embeddertests",
    "fpdfsdk:embeddertests",
    "fpdfsdk/formfiller:embeddertests",
    "fpdfsdk/pwl:embeddertests",
    "testing/image_diff",
    "//testing/gmock",
    "//testing/gtest",
  ]
  include_dirs = [ "testing/gmock/include" ]
  configs += [ ":pdfium_core_config" ]

  if (is_android) {
    ignore_all_data_deps = true
    use_raw_android_executable = true
  }

  if (pdf_enable_v8) {
    deps += [
      "fxjs:embeddertests",
      "//v8",
    ]
    configs += [ "//v8:external_startup_data" ]
  }

  if (pdf_enable_xfa) {
    deps += [
      "fpdfsdk/fpdfxfa:embeddertests",
      "xfa/fwl:embeddertests",
      "xfa/fxfa/layout:embeddertests",
      "xfa/fxfa/parser:embeddertests",
    ]
  }
}

executable("pdfium_diff") {
  visibility += [ "testing/tools:test_runner_py" ]
  testonly = true
  sources = [ "testing/image_diff/image_diff.cpp" ]
  deps = [
    "core/fxcrt",
    "testing:path_service",
    "testing/image_diff",
    "//build/win:default_exe_manifest",
  ]
  configs += [ ":pdfium_strict_config" ]
}

group("pdfium_all") {
  testonly = true
  deps = [
    ":pdfium_diff",
    ":pdfium_embeddertests",
    ":pdfium_unittests",
    "samples",
    "testing/fuzzers",
  ]

  if (pdf_is_standalone) {
    deps += [ "testing/tools:test_runner_py" ]
  }
}

# Makes additional targets reachable only for "gn check". These are not always
# built by the "all" Ninja target, which uses the "default" group, which in turn
# depends on the "pdfium_all" group.
group("gn_check") {
  deps = []

  # TODO(crbug.com/pdfium/1832): Remove !is_android when //third_party/expat is
  # available.
  if (defined(checkout_skia) && checkout_skia && !is_android) {
    deps += [ "//skia" ]
  }
}