From f1c713663192368d26031a4caed1f9705f4510af Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 9 Oct 2015 12:45:15 -0700 Subject: Allow compiling PDFium without V8. Original patch from issue 1391843004 at patchset 1 (http://crrev.com/1391843004#ps1) Introduce a pdf_enable_v8 GYP variable, which controls a corresponding PDF_ENABLE_V8 #define, and bring in the real JS library when set. Otherwise, link against a stub JS runtime. BUG=pdfium:211 R=dml@google.com, jochen@chromium.org, thestig@chromium.org Review URL: https://codereview.chromium.org/1395733006 . --- samples/BUILD.gn | 21 ++++++++++++++++----- samples/pdfium_test.cc | 10 ++++++++++ samples/samples.gyp | 24 +++++++++++++++++++++--- 3 files changed, 47 insertions(+), 8 deletions(-) (limited to 'samples') diff --git a/samples/BUILD.gn b/samples/BUILD.gn index 6f4518c17e..5749de90f1 100644 --- a/samples/BUILD.gn +++ b/samples/BUILD.gn @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("../pdfium.gni") + group("samples") { deps = [ ":pdfium_test", @@ -15,6 +17,11 @@ config("pdfium_samples_config") { "PNGPREFIX_H", "PNG_USE_READ_MACROS", ] + if (pdf_enable_v8) { + defines += [ + "PDF_ENABLE_V8", + ] + } } executable("pdfium_test") { @@ -28,13 +35,17 @@ executable("pdfium_test") { # always link this binary against the bundled one for consistency # of results across platforms. "//third_party/pdfium/third_party:fx_freetype", - "//v8:v8_libplatform", ":fx_lpng", ] - include_dirs = [ - "//v8", - "//v8/include", - ] + if (pdf_enable_v8) { + deps += [ + "//v8:v8_libplatform", + ] + include_dirs = [ + "//v8", + "//v8/include", + ] + } configs += [ ":pdfium_samples_config" ] } diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 74e797b944..f15e19c75b 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -19,8 +19,10 @@ #include "../public/fpdf_text.h" #include "../public/fpdfview.h" #include "image_diff_png.h" +#ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" +#endif #ifdef _WIN32 #define snprintf _snprintf @@ -79,6 +81,7 @@ static char* GetFileContents(const char* filename, size_t* retlen) { return buffer; } +#ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA // Returns the full path for an external V8 data file based on either // the currect exectuable path or an explicit override. @@ -116,6 +119,7 @@ static bool GetExternalData(const Options& options, return true; } #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 static bool CheckDimensions(int stride, int width, int height) { if (stride < 0 || width < 0 || height < 0) @@ -373,6 +377,7 @@ bool ParseCommandLine(const std::vector& args, options->output_format = OUTPUT_BMP; } #endif // _WIN32 +#ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA else if (cur_arg.size() > 10 && cur_arg.compare(0, 10, "--bin-dir=") == 0) { if (!options->bin_directory.empty()) { @@ -382,6 +387,7 @@ bool ParseCommandLine(const std::vector& args, options->bin_directory = cur_arg.substr(10); } #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--scale=") == 0) { if (!options->scale_factor_as_string.empty()) { fprintf(stderr, "Duplicate --scale argument\n"); @@ -595,6 +601,7 @@ int main(int argc, const char* argv[]) { return 1; } +#ifdef PDF_ENABLE_V8 v8::V8::InitializeICU(); v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); @@ -615,6 +622,7 @@ int main(int argc, const char* argv[]) { v8::V8::SetNativesDataBlob(&natives); v8::V8::SetSnapshotDataBlob(&snapshot); #endif // V8_USE_EXTERNAL_STARTUP_DATA +#endif // PDF_ENABLE_V8 FPDF_LIBRARY_CONFIG config; config.version = 2; @@ -649,8 +657,10 @@ int main(int argc, const char* argv[]) { } FPDF_DestroyLibrary(); +#ifdef PDF_ENABLE_V8 v8::V8::ShutdownPlatform(); delete platform; +#endif // PDF_ENABLE_V8 return 0; } diff --git a/samples/samples.gyp b/samples/samples.gyp index 4b6c16bf2e..496a274da7 100644 --- a/samples/samples.gyp +++ b/samples/samples.gyp @@ -3,6 +3,9 @@ # found in the LICENSE file. { + 'variables': { + 'pdf_enable_v8%': 1, + }, 'target_defaults': { 'defines' : [ 'PNG_PREFIX', @@ -11,8 +14,17 @@ ], 'include_dirs': [ '<(DEPTH)', - '<(DEPTH)/v8', - '<(DEPTH)/v8/include', + ], + 'conditions': [ + ['pdf_enable_v8==1', { + 'defines': [ + 'PDF_ENABLE_V8', + ], + 'include_dirs': [ + '<(DEPTH)/v8', + '<(DEPTH)/v8/include', + ], + }], ], }, 'targets': [ @@ -26,7 +38,6 @@ # always link this binary against the bundled one for consistency # of results across platforms. '../third_party/third_party.gyp:fx_freetype', - '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', ], 'sources': [ 'pdfium_test.cc', @@ -37,6 +48,13 @@ '-lfreetype', ], }, + 'conditions': [ + ['pdf_enable_v8==1', { + 'dependencies': [ + '<(DEPTH)/v8/tools/gyp/v8.gyp:v8_libplatform', + ], + }], + ], }, { 'target_name': 'pdfium_diff', -- cgit v1.2.3