Skip to content

Commit

Permalink
Add macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Sep 28, 2017
1 parent 7db89f7 commit 175e21b
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 58 deletions.
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ language: cpp

matrix:
include:
- env: CONFIGURATION=Release
- env: CONFIGURATION=Debug
- os: linux
env: CONFIGURATION=Release
- os: linux
env: CONFIGURATION=Debug
- os: osx
osx_image: xcode9
env: CONFIGURATION=Release
- os: osx
osx_image: xcode9
env: CONFIGURATION=Debug

script: bash build.sh
script:
- bash build.sh
- bash test.sh

deploy:
provider: releases
Expand Down
6 changes: 3 additions & 3 deletions PDFiumConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(MSVC)
PROPERTIES
IMPORTED_LOCATION "${PDFium_BIN_PATH}/pdfium.dll"
IMPORTED_IMPLIB "${PDFium_LIB_PATH}/pdfium.dll.lib"
INTERFACE_INCLUDE_DIRECTORIES "${PDFium_INCLUDE_PATH}"
INTERFACE_INCLUDE_DIRECTORIES "${PDFium_INCLUDE_PATH};${PDFium_INCLUDE_PATH}/cpp"
)

file(TO_NATIVE_PATH "${PDFium_BIN_PATH}" PDFium_BIN_PATH)
Expand All @@ -45,8 +45,8 @@ else()
add_library(pdfium SHARED IMPORTED)
set_target_properties(pdfium
PROPERTIES
IMPORTED_LOCATION "${PDFium_LIB_PATH}/libpdfium.so"
INTERFACE_INCLUDE_DIRECTORIES "${PDFium_INCLUDE_PATH}"
IMPORTED_LOCATION "${PDFium_LIB_PATH}/libpdfium${CMAKE_SHARED_LIBRARY_SUFFIX}"
INTERFACE_INCLUDE_DIRECTORIES "${PDFium_INCLUDE_PATH};${PDFium_INCLUDE_PATH}/cpp"
)

if(NOT PDFium_FIND_QUIETLY)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Total number of downloads](https://img.shields.io/github/downloads/bblanchon/pdfium-binaries/total.svg)](https://github.com/bblanchon/pdfium-binaries/releases)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/85rqdhpyxt589700?svg=true)](https://ci.appveyor.com/project/bblanchon/pdfium-binaries)
[![Linux/macOS Build Status](https://travis-ci.org/bblanchon/pdfium-binaries.svg?branch=master)](https://travis-ci.org/bblanchon/pdfium-binaries)

# Pre-compiled binaries of PDFium

Expand All @@ -13,7 +14,7 @@ Here are the download links for latest release:

<table>
<tr>
<th>Plateform</th>
<th>Platform</th>
<th>Release build</th>
<th>Debug build</th>
</tr>
Expand All @@ -32,6 +33,11 @@ Here are the download links for latest release:
<td><a href="https://github.com/bblanchon/pdfium-binaries/releases/latest">pdfium-linux.zip</a></td>
<td><a href="https://github.com/bblanchon/pdfium-binaries/releases/latest">pdfium-linux-debug.zip</a></td>
</tr>
<tr>
<td>macOS</td>
<td><a href="https://github.com/bblanchon/pdfium-binaries/releases/latest">pdfium-darwin.zip</a></td>
<td><a href="https://github.com/bblanchon/pdfium-binaries/releases/latest">pdfium-darwin-debug.zip</a></td>
</tr>
</table>

### How too use in a CMake project
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ platform:

build_script:
- call build.bat
- cd %APPVEYOR_BUILD_FOLDER%
- call test.bat

artifacts:
- path: pdfium-*.zip
Expand Down
9 changes: 9 additions & 0 deletions args/darwin.args.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Disable component build (must be false)
is_component_build = false

# Build PDFium either with or without v8 support (default = true)
pdf_enable_v8 = false

# Build PDFium standalone (default = false)
pdf_is_standalone = true

2 changes: 1 addition & 1 deletion Linux.args.gn → args/linux.args.gn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Disable component build (must be false)
is_component_build = true
is_component_build = false

# Build PDFium either with or without v8 support (default = true)
pdf_enable_v8 = false
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ set DepotTools_DIR=%CD%/depot_tools
set PDFium_URL=https://pdfium.googlesource.com/pdfium.git
set PDFium_SOURCE_DIR=%CD%\pdfium
set PDFium_BUILD_DIR=%PDFium_SOURCE_DIR%\out
set PDFium_PATCH=%CD%\shared_library.patch
set PDFium_PATCH=%CD%\patches\shared_library.patch
set PDFium_CMAKE_CONFIG=%CD%\PDFiumConfig.cmake
set PDFium_ARGS=%CD%\Windows.args.gn
set PDFium_ARGS=%CD%\args\windows.args.gn

: Output
set PDFium_STAGING_DIR=%CD%\staging
Expand Down
34 changes: 20 additions & 14 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@

set -ex

OS=$(uname)
case $OS in
MINGW*)
OS="windows"
;;
*)
OS=$(echo $OS | tr '[:upper:]' '[:lower:]')
;;
esac

# Input
DepotTools_URL='https://chromium.googlesource.com/chromium/tools/depot_tools.git'
DepotTools_DIR="$PWD/depot_tools"
PDFium_URL='https://pdfium.googlesource.com/pdfium.git'
PDFium_SOURCE_DIR="$PWD/pdfium"
PDFium_BUILD_DIR="$PDFium_SOURCE_DIR/out"
PDFium_PATCH_DIR="$PWD"
PDFium_PATCH_DIR="$PWD/patches"
PDFium_CMAKE_CONFIG="$PWD/PDFiumConfig.cmake"
PDFium_ARGS="$PWD/Linux.args.gn"
PDFium_ARGS="$PWD/args/$OS.args.gn"

# Output
PDFium_STAGING_DIR="$PWD/staging"
PDFium_INCLUDE_DIR="$PDFium_STAGING_DIR/include"
PDFium_LIB_DIR="$PDFium_STAGING_DIR/lib"
PDFium_ARTIFACT="$PWD/pdfium-linux.tgz"
[ "$CONFIGURATION" == "Debug" ] && PDFium_ARTIFACT="$PWD/pdfium-linux-debug.tgz"
PDFium_ARTIFACT="$PWD/pdfium-$OS.tgz"
[ "$CONFIGURATION" == "Debug" ] && PDFium_ARTIFACT="$PWD/pdfium-$OS-debug.tgz"

# Prepare directories
mkdir -p "$PDFium_BUILD_DIR"
Expand All @@ -37,14 +47,9 @@ gclient config --unmanaged "$PDFium_URL"
gclient sync

# Checkout
if [[ -v PDFium_BRANCH ]]; then
cd "$PDFium_SOURCE_DIR"
git checkout "$PDFium_BRANCH"
gclient sync
fi

# Install build deps
sudo "$PDFium_SOURCE_DIR/build/install-build-deps.sh" --no-arm --no-chromeos-fonts --no-nacl --no-syms --no-prompt
cd "$PDFium_SOURCE_DIR"
git checkout "${PDFium_BRANCH:-master}"
gclient sync

# Patch
cd "$PDFium_SOURCE_DIR"
Expand All @@ -69,8 +74,9 @@ mv "$PDFium_SOURCE_DIR/LICENSE" "$PDFium_STAGING_DIR"
mv "$PDFium_SOURCE_DIR/public" "$PDFium_INCLUDE_DIR"
rm -f "$PDFium_INCLUDE_DIR/DEPS"
rm -f "$PDFium_INCLUDE_DIR/README"
mv "$PDFium_BUILD_DIR/libpdfium.so" "$PDFium_LIB_DIR"
[ "$OS" == "linux" ] && mv "$PDFium_BUILD_DIR/libpdfium.so" "$PDFium_LIB_DIR"
[ "$OS" == "darwin" ] && mv "$PDFium_BUILD_DIR/libpdfium.dylib" "$PDFium_LIB_DIR"

# Pack
cd "$PDFium_STAGING_DIR"
tar cvf "$PDFium_ARTIFACT" *
tar cvf "$PDFium_ARTIFACT" -- *
15 changes: 15 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8)
project(example)
enable_testing()

find_package(PDFium REQUIRED)

add_executable(example example.c)
target_link_libraries(example pdfium)

# Optional: copy library alongside with the excecutable
add_custom_command(
TARGET example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:pdfium> $<TARGET_FILE_DIR:example>)

add_test(example example)
9 changes: 9 additions & 0 deletions example/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <fpdfview.h>

int main()
{
FPDF_InitLibrary();

FPDF_DestroyLibrary();
return 0;
}
23 changes: 23 additions & 0 deletions patches/relative-includes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/public/cpp/fpdf_deleters.h b/public/cpp/fpdf_deleters.h
index 238ef30e6..720074222 100644
--- a/public/cpp/fpdf_deleters.h
+++ b/public/cpp/fpdf_deleters.h
@@ -5,12 +5,12 @@
#ifndef PUBLIC_CPP_FPDF_DELETERS_H_
#define PUBLIC_CPP_FPDF_DELETERS_H_

-#include "public/fpdf_dataavail.h"
-#include "public/fpdf_edit.h"
-#include "public/fpdf_formfill.h"
-#include "public/fpdf_structtree.h"
-#include "public/fpdf_text.h"
-#include "public/fpdfview.h"
+#include "../fpdf_dataavail.h"
+#include "../fpdf_edit.h"
+#include "../fpdf_formfill.h"
+#include "../fpdf_structtree.h"
+#include "../fpdf_text.h"
+#include "../fpdfview.h"

// Custom deleters for using FPDF_* types with std::unique_ptr<>.

54 changes: 54 additions & 0 deletions patches/shared_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/BUILD.gn b/BUILD.gn
index b4b93b584..d57bb555d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -23,6 +23,7 @@ config("pdfium_common_config") {
"OPJ_STATIC",
"PNG_PREFIX",
"PNG_USE_READ_MACROS",
+ "FPDFSDK_EXPORTS"
]

if (pdf_use_skia) {
@@ -100,7 +101,7 @@ config("xfa_warnings") {
}
}

-static_library("pdfium") {
+shared_library("pdfium") {
sources = [
"fpdfsdk/cba_annotiterator.cpp",
"fpdfsdk/cba_annotiterator.h",
diff --git a/public/fpdfview.h b/public/fpdfview.h
index 135d00a8f..89c89ed9c 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -142,13 +142,22 @@ typedef int FPDF_ANNOTATION_SUBTYPE;
// Dictionary value types.
typedef int FPDF_OBJECT_TYPE;

-#if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
-// On Windows system, functions are exported in a DLL
-#define FPDF_EXPORT __declspec(dllexport)
-#define FPDF_CALLCONV __stdcall
+#ifdef FPDFSDK_EXPORTS
+# if defined(_WIN32)
+# define FPDF_EXPORT __declspec(dllexport)
+# define FPDF_CALLCONV __stdcall
+# else
+# define FPDF_EXPORT __attribute__((visibility("default")))
+# define FPDF_CALLCONV
+# endif
#else
-#define FPDF_EXPORT
-#define FPDF_CALLCONV
+# if defined(_WIN32)
+# define FPDF_EXPORT __declspec(dllimport)
+# define FPDF_CALLCONV __stdcall
+# else
+# define FPDF_EXPORT
+# define FPDF_CALLCONV
+# endif
#endif

// Exported Functions
File renamed without changes.
34 changes: 0 additions & 34 deletions shared_library.patch

This file was deleted.

13 changes: 13 additions & 0 deletions test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set SOURCE_DIR=%CD%\example
set PDFium_DIR=%CD%\staging
set CMAKE_GENERATOR=Visual Studio 15 2017

if "%PLATFORM%"=="x64" set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64

@echo on

mkdir build
cd build
cmake -G "%CMAKE_GENERATOR%" "%SOURCE_DIR%"
cmake --build .
ctest --output-on-failure .
12 changes: 12 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -eux

export SOURCE_DIR="$PWD/example"
export PDFium_DIR="$PWD/staging"

mkdir build
cd build
cmake "$SOURCE_DIR"
cmake --build .
ctest --output-on-failure .

0 comments on commit 175e21b

Please sign in to comment.