68 lines
2.5 KiB
CMake
68 lines
2.5 KiB
CMake
# PDFium integration.
|
|
# Creates imported target pdfium::pdfium from third_party/pdfium/install/.
|
|
|
|
if(NOT PDFENGINE_WITH_PDFIUM)
|
|
message(STATUS "PDFium: disabled (PDFENGINE_WITH_PDFIUM=OFF). "
|
|
"Engine builds without raw PDFium linkage.")
|
|
return()
|
|
endif()
|
|
|
|
# Desktop uses the GN-built tree; WASM uses the prebuilt Emscripten static lib
|
|
# (third_party/pdfium-wasm, fetched by get_pdfium_wasm.ps1 — a relinkable libpdfium.a).
|
|
if(EMSCRIPTEN)
|
|
set(PDFIUM_INSTALL_DIR "${CMAKE_SOURCE_DIR}/third_party/pdfium-wasm"
|
|
CACHE PATH "Root of the wasm32 PDFium tree (prebuilt libpdfium.a + include)")
|
|
else()
|
|
set(PDFIUM_INSTALL_DIR "${CMAKE_SOURCE_DIR}/third_party/pdfium/install"
|
|
CACHE PATH "Root of the PDFium install tree produced by build_pdfium.*")
|
|
endif()
|
|
|
|
if(EMSCRIPTEN)
|
|
# Emscripten's toolchain sets CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY, which makes
|
|
# find_library ignore custom PATHS (it only searches the emsdk sysroot). Set the
|
|
# prebuilt wasm32 lib + headers directly instead.
|
|
set(PDFIUM_INCLUDE_DIR "${PDFIUM_INSTALL_DIR}/include")
|
|
set(PDFIUM_LIBRARY "${PDFIUM_INSTALL_DIR}/lib/libpdfium.a")
|
|
if(NOT EXISTS "${PDFIUM_INCLUDE_DIR}/fpdfview.h")
|
|
set(PDFIUM_INCLUDE_DIR "")
|
|
endif()
|
|
if(NOT EXISTS "${PDFIUM_LIBRARY}")
|
|
set(PDFIUM_LIBRARY "")
|
|
endif()
|
|
else()
|
|
find_path(PDFIUM_INCLUDE_DIR
|
|
NAMES fpdfview.h
|
|
PATHS "${PDFIUM_INSTALL_DIR}/include"
|
|
NO_DEFAULT_PATH)
|
|
|
|
find_library(PDFIUM_LIBRARY
|
|
NAMES pdfium libpdfium
|
|
PATHS "${PDFIUM_INSTALL_DIR}/lib"
|
|
NO_DEFAULT_PATH)
|
|
endif()
|
|
|
|
if(NOT PDFIUM_INCLUDE_DIR OR NOT PDFIUM_LIBRARY)
|
|
message(FATAL_ERROR
|
|
"PDFENGINE_WITH_PDFIUM=ON but no PDFium install tree was found under:\n"
|
|
" ${PDFIUM_INSTALL_DIR}\n"
|
|
"Build PDFium first (one-time, slow):\n"
|
|
" Windows: pwsh third_party/pdfium/build_pdfium.ps1\n"
|
|
" Unix: ./third_party/pdfium/build_pdfium.sh\n"
|
|
"See third_party/pdfium/README.md.")
|
|
endif()
|
|
|
|
add_library(pdfium::pdfium STATIC IMPORTED GLOBAL)
|
|
set_target_properties(pdfium::pdfium PROPERTIES
|
|
IMPORTED_LOCATION "${PDFIUM_LIBRARY}"
|
|
INTERFACE_INCLUDE_DIRECTORIES "${PDFIUM_INCLUDE_DIR}")
|
|
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
set_property(TARGET pdfium::pdfium APPEND PROPERTY
|
|
INTERFACE_LINK_LIBRARIES pthread dl)
|
|
endif()
|
|
|
|
message(STATUS "PDFium: found")
|
|
message(STATUS " include .. ${PDFIUM_INCLUDE_DIR}")
|
|
message(STATUS " library .. ${PDFIUM_LIBRARY}")
|