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) { 43 defines += [ "_SKIA_SUPPORT_" ] 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 # TODO(crbug.com/1213098): Remove once this is in //build. 214 cflags += [ "-Wdeprecated-copy" ] 215 216 # May flag some issues when converting int to size_t. 217 cflags += [ "-Wtautological-unsigned-zero-compare" ] 218 } 219 220 if (!is_win && !is_clang) { 221 cflags += [ 222 # Override -Wno-narrowing for GCC. 223 "-Wnarrowing", 224 225 # GCC assumes that control can get past an exhaustive switch and then 226 # warns if there's no return there. 227 "-Wno-return-type", 228 ] 229 } 230} 231 232config("pdfium_implementation_config") { 233 defines = [ "FPDF_IMPLEMENTATION" ] 234 visibility = [ ":pdfium_public_headers" ] 235} 236 237config("pdfium_public_config") { 238 defines = [] 239 240 if (pdf_enable_v8) { 241 defines += [ "PDF_ENABLE_V8" ] 242 243 if (pdf_enable_xfa) { 244 defines += [ "PDF_ENABLE_XFA" ] 245 if (pdf_enable_xfa_bmp) { 246 defines += [ "PDF_ENABLE_XFA_BMP" ] 247 } 248 if (pdf_enable_xfa_gif) { 249 defines += [ "PDF_ENABLE_XFA_GIF" ] 250 } 251 if (pdf_enable_xfa_png) { 252 defines += [ "PDF_ENABLE_XFA_PNG" ] 253 } 254 if (pdf_enable_xfa_tiff) { 255 defines += [ "PDF_ENABLE_XFA_TIFF" ] 256 } 257 } 258 } 259} 260 261config("pdfium_core_config") { 262 cflags = [] 263 configs = [ 264 ":pdfium_common_config", 265 ":pdfium_public_config", 266 "//build/config/compiler:noshadowing", 267 ] 268 defines = [] 269 if (is_win) { 270 cflags += [ 271 "/wd4324", 272 "/wd4577", 273 ] 274 } 275 if (is_clang) { 276 cflags += [ "-Wcovered-switch-default" ] 277 } 278} 279 280config("pdfium_plugin_config") { 281 cflags = [] 282 defines = [] 283 if (clang_use_chrome_plugins) { 284 # Catch misuse of C-style pointers. 285 # TODO(tsepez): enable for windows, too. 286 if (!is_win) { 287 cflags += [ 288 "-Xclang", 289 "-plugin-arg-find-bad-constructs", 290 "-Xclang", 291 "check-raw-ptr-fields", 292 293 "-Xclang", 294 "-plugin-arg-find-bad-constructs", 295 "-Xclang", 296 "raw-ptr-exclude-path=public", 297 298 "-Xclang", 299 "-plugin-arg-find-bad-constructs", 300 "-Xclang", 301 "raw-ptr-exclude-path=test", 302 303 # TODO(tsepez): enforce raw_ref<> as well. 304 # "-Xclang", 305 # "-plugin-arg-find-bad-constructs", 306 # "-Xclang", 307 # "check-raw-ref-fields", 308 ] 309 defines += [ "PDF_ENABLE_UNOWNED_PTR_EXCLUSION" ] 310 } 311 312 # Catch misuse of cppgc in XFA. 313 if (pdf_enable_xfa) { 314 cflags += [ 315 "-Xclang", 316 "-add-plugin", 317 "-Xclang", 318 "blink-gc-plugin", 319 ] 320 } 321 } 322} 323 324config("pdfium_strict_config") { 325 configs = [ 326 ":pdfium_core_config", 327 ":pdfium_plugin_config", 328 "//build/config/compiler:wexit_time_destructors", 329 "//build/config/compiler:wglobal_constructors", 330 ] 331} 332 333config("pdfium_noshorten_config") { 334 cflags = [] 335 if (is_clang) { 336 cflags += [ "-Wshorten-64-to-32" ] 337 } 338} 339 340source_set("pdfium_public_headers_impl") { 341 sources = [ 342 "public/cpp/fpdf_deleters.h", 343 "public/cpp/fpdf_scopers.h", 344 "public/fpdf_annot.h", 345 "public/fpdf_attachment.h", 346 "public/fpdf_catalog.h", 347 "public/fpdf_dataavail.h", 348 "public/fpdf_doc.h", 349 "public/fpdf_edit.h", 350 "public/fpdf_ext.h", 351 "public/fpdf_flatten.h", 352 "public/fpdf_formfill.h", 353 "public/fpdf_fwlevent.h", 354 "public/fpdf_javascript.h", 355 "public/fpdf_ppo.h", 356 "public/fpdf_progressive.h", 357 "public/fpdf_save.h", 358 "public/fpdf_searchex.h", 359 "public/fpdf_signature.h", 360 "public/fpdf_structtree.h", 361 "public/fpdf_sysfontinfo.h", 362 "public/fpdf_text.h", 363 "public/fpdf_transformpage.h", 364 "public/fpdfview.h", 365 ] 366} 367 368group("pdfium_public_headers") { 369 public_deps = [ ":pdfium_public_headers_impl" ] 370 public_configs = [ 371 ":pdfium_public_config", 372 ":pdfium_implementation_config", 373 ] 374} 375 376component("pdfium") { 377 output_name = "pdfium" 378 libs = [] 379 configs += [ ":pdfium_strict_config" ] 380 public_configs = [ ":pdfium_public_config" ] 381 382 deps = [ 383 "constants", 384 "core/fpdfapi/page", 385 "core/fpdfapi/parser", 386 "core/fpdfdoc", 387 "core/fxcodec", 388 "core/fxcrt", 389 "core/fxge", 390 "fpdfsdk", 391 "fpdfsdk/formfiller", 392 "fxjs", 393 "third_party:pdfium_base", 394 ] 395 396 public_deps = [ 397 ":pdfium_public_headers_impl", 398 "core/fxcrt", 399 ] 400 401 if (pdf_enable_xfa) { 402 deps += [ 403 "fpdfsdk/fpdfxfa", 404 "xfa/fxfa", 405 "xfa/fxfa/parser", 406 ] 407 } 408 409 if (is_win) { 410 libs += [ 411 "advapi32.lib", 412 "gdi32.lib", 413 "user32.lib", 414 ] 415 } 416 417 if (is_mac) { 418 frameworks = [ 419 "AppKit.framework", 420 "CoreFoundation.framework", 421 ] 422 } 423 424 if (pdf_is_complete_lib) { 425 static_component_type = "static_library" 426 complete_static_lib = true 427 configs -= [ "//build/config/compiler:thin_archive" ] 428 } 429} 430 431# Targets below this are only visible within this file. 432visibility = [ ":*" ] 433 434group("pdfium_unittest_deps") { 435 testonly = true 436 public_deps = [ 437 "core/fxcrt", 438 "testing:unit_test_support", 439 "//testing/gmock", 440 "//testing/gtest", 441 ] 442 visibility += [ 443 "core/*", 444 "fpdfsdk/*", 445 "fxbarcode/*", 446 "fxjs/*", 447 "xfa/*", 448 ] 449} 450 451test("pdfium_unittests") { 452 testonly = true 453 sources = [ "testing/unit_test_main.cpp" ] 454 deps = [ 455 "core/fdrm:unittests", 456 "core/fpdfapi/edit:unittests", 457 "core/fpdfapi/font:unittests", 458 "core/fpdfapi/page:unittests", 459 "core/fpdfapi/parser:unittests", 460 "core/fpdfapi/render:unittests", 461 "core/fpdfdoc:unittests", 462 "core/fpdftext:unittests", 463 "core/fxcodec:unittests", 464 "core/fxcrt", 465 "core/fxcrt:unittests", 466 "core/fxge:unittests", 467 "fpdfsdk:unittests", 468 "testing:unit_test_support", 469 "//testing/gmock", 470 "//testing/gtest", 471 ] 472 configs += [ ":pdfium_core_config" ] 473 if (is_android) { 474 use_raw_android_executable = true 475 } 476 if (pdf_enable_v8) { 477 configs += [ "//v8:external_startup_data" ] 478 deps += [ 479 "fxjs:unittests", 480 "//v8", 481 ] 482 if (pdf_enable_xfa) { 483 deps += [ 484 "core/fxcrt/css:unittests", 485 "fxbarcode:unittests", 486 "xfa/fde:unittests", 487 "xfa/fgas/crt:unittests", 488 "xfa/fgas/font:unittests", 489 "xfa/fgas/layout:unittests", 490 "xfa/fxfa:unittests", 491 "xfa/fxfa/formcalc:unittests", 492 "xfa/fxfa/parser:unittests", 493 ] 494 } 495 } 496} 497 498group("pdfium_embeddertest_deps") { 499 testonly = true 500 public_deps = [ 501 ":pdfium_public_headers", 502 "core/fxcrt", 503 "testing:embedder_test_support", 504 "third_party:pdfium_base_test_support", 505 "//testing/gmock", 506 "//testing/gtest", 507 ] 508 visibility += [ 509 "core/*", 510 "fpdfsdk/*", 511 "fxjs/*", 512 "xfa/*", 513 ] 514} 515 516test("pdfium_embeddertests") { 517 testonly = true 518 sources = [ "testing/embedder_test_main.cpp" ] 519 deps = [ 520 ":pdfium_embeddertest_deps", 521 "core/fpdfapi/edit:embeddertests", 522 "core/fpdfapi/parser:embeddertests", 523 "core/fpdfapi/render:embeddertests", 524 "core/fxcodec:embeddertests", 525 "core/fxcrt", 526 "core/fxge:embeddertests", 527 "fpdfsdk:embeddertests", 528 "fpdfsdk/formfiller:embeddertests", 529 "fpdfsdk/pwl:embeddertests", 530 "testing/image_diff", 531 "//testing/gmock", 532 "//testing/gtest", 533 ] 534 include_dirs = [ "testing/gmock/include" ] 535 configs += [ ":pdfium_core_config" ] 536 537 if (is_android) { 538 ignore_all_data_deps = true 539 use_raw_android_executable = true 540 } 541 542 if (pdf_enable_v8) { 543 deps += [ 544 "fxjs:embeddertests", 545 "//v8", 546 ] 547 configs += [ "//v8:external_startup_data" ] 548 } 549 550 if (pdf_enable_xfa) { 551 deps += [ 552 "fpdfsdk/fpdfxfa:embeddertests", 553 "xfa/fwl:embeddertests", 554 "xfa/fxfa/layout:embeddertests", 555 "xfa/fxfa/parser:embeddertests", 556 ] 557 } 558} 559 560executable("pdfium_diff") { 561 visibility += [ "testing/tools:test_runner_py" ] 562 testonly = true 563 sources = [ "testing/image_diff/image_diff.cpp" ] 564 deps = [ 565 "core/fxcrt", 566 "testing:path_service", 567 "testing/image_diff", 568 "//build/win:default_exe_manifest", 569 ] 570 configs += [ ":pdfium_strict_config" ] 571} 572 573group("pdfium_all") { 574 testonly = true 575 deps = [ 576 ":pdfium_diff", 577 ":pdfium_embeddertests", 578 ":pdfium_unittests", 579 "samples", 580 "testing/fuzzers", 581 ] 582 583 if (pdf_is_standalone) { 584 deps += [ "testing/tools:test_runner_py" ] 585 } 586} 587 588# Makes additional targets reachable only for "gn check". These are not always 589# built by the "all" Ninja target, which uses the "default" group, which in turn 590# depends on the "pdfium_all" group. 591group("gn_check") { 592 deps = [] 593 594 # TODO(crbug.com/pdfium/1832): Remove !is_android when //third_party/expat is 595 # available. 596 if (defined(checkout_skia) && checkout_skia && !is_android) { 597 deps += [ "//skia" ] 598 } 599} 600