VS2017 編譯pdfium
1、本地創建google目錄,進入
2、下載
mkdir google
cd google
gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
gclient sync
3、修改DEBUG_LEVEL
在DEBUG模式下編譯時,會報:
#error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'
buid/config/BUILD.gn
if (is_win) {
if (!enable_iterator_debugging && !use_custom_libcxx) {
# Iterator debugging is enabled by default by the compiler on debug
# builds, and we have to tell it to turn it off.
#將原來的_HAS_ITERATOR_DEBUGGING=0修改爲以下:(確保DEBUG模式時,_ITERATOR_DEBUG_LEVEL爲2)
defines += [ "_HAS_ITERATOR_DEBUGGING=1" ]
defines += [ "_ITERATOR_DEBUG_LEVEL=2" ]
}
修改:pdfium/BUILD.gn
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" ]
}
if(is_debug){
#增加debug級別
defines += ["_DEBUG"]
defines += ["_HAS_ITERATOR_DEBUGGING=1"]
defines += ["_ITERATOR_DEBUG_LEVEL=2"]
}
}
}
4、生成工程
官方:
#lease refer to Chromium's Visual Studio set up for requirements and instructions on build environment configuration.
#Run set DEPOT_TOOLS_WIN_TOOLCHAIN=0, or set that variable in your global environment.
#Compilation is done through Ninja, not Visual Studio.
use_goma = true # Googlers only. Make sure goma is installed and running first.
is_debug = true # Enable debugging features.
# Set true to enable experimental Skia backend.
pdf_use_skia = false
# Set true to enable experimental Skia backend (paths only).
pdf_use_skia_paths = false
pdf_enable_xfa = true # Set false to remove XFA support (implies JS support).
pdf_enable_v8 = true # Set false to remove Javascript support.
pdf_is_standalone = true # Set for a non-embedded build.
is_component_build = false # Disable component build (Though it should work)
clang_use_chrome_plugins = false # Currently must be false.
For sample applications like pdfium_test to build, one must set pdf_is_standalone = true.
By default, the entire project builds with C++14, because features like V8 support, XFA support, and the Skia backend all have dependencies on libraries that require C++14. If one does not need any of those features, and need to fall back to building in C++11 mode, then set use_cxx11 = true. This fallback is temporary and will go away in the future when PDFium fully transitions to C++14. See this bug for details.
When complete the arguments will be stored in <directory>/args.gn, and GN will automatically use the new arguments to generate build files. Should your files fail to generate, please double-check that you have set use_sysroot as indicated above.
===============
執行:
cd pdfium
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
gn args out/x86
在彈出窗口中,貼:
#Buildargumentsgohere.
#See"gnargs<out_dir>--list"foravailablebuildarguments.
#是否啓用goma支持
use_goma=false
#是否編譯爲Chrome插件
clang_use_chrome_plugins=false
#是否進行編譯測試
pdf_is_standalone=true
#是否啓用skia支持
pdf_use_skia=false
pdf_use_skia_paths=false
#true編譯爲debug版本,false編譯爲release版本
is_debug=true
#true編譯爲動態庫 /MD,/MDd,false編譯爲靜態庫 /MT,/MTd
is_component_build=false
#編譯爲一個獨立的靜態庫(is_component_build必須爲false)
#pdf_is_complete_lib爲false時,編譯爲多個靜態庫,true編譯爲一個獨立的靜態庫
pdf_is_complete_lib=true
#xfa支持
pdf_enable_xfa=true
#v8支持
pdf_enable_v8=true
#cpu架構;x86、x64可選
target_cpu="x86"
#true將用clang進行編譯,false將用VS2017編譯
is_clang=false
5、編譯pdfium
cd pdfium
ninja -C out/x86 pdfium
編譯時間較長,DEBUG結果有900MB以上,RELEASE結果有600M左右