Otok public index

apotocki/cairo

Cairo, the 2D graphics library, for Windows: GDI, DirectWrite and, as an option, Direct2D.

Library
cairo
Newest
1.18.4 (r1, windows)
Targets
windows
License
LGPL-2.1-only OR MPL-1.1
Homepage
https://www.cairographics.org
Keywords
graphics, 2d, vector, direct2d

Use it

In otok.toml:

[deps.cairo]
recipe = "apotocki/cairo"
version = "~> 1.18.4"

Versions

VersionTargetChannelPublishedStatus
1.18.4 (r1, windows) windows stable 2026-11-07

1.18.4 (r1, windows)

Platforms

windows

Options

OptionTypeDefaultDescription
d2d bool false The Direct2D surface on Direct3D 10.1 and 11 (CAIRO_HAS_D2D_SURFACE, cairo_d2d_* in cairo-win32.h), its CSS blend modes and GPU drop shadow: the branch d2d of apotocki/cairo.

Dependencies

LibraryVersionRecipeDetails
freetype >= 2.10 apotocki/freetype linkage = static
libpng >= 1.6 apotocki/libpng linkage = static
pixman >= 0.40 apotocki/pixman linkage = static
zlib >= 1.2 apotocki/zlib

Toolchains

Recipe files

build.lua 2786 bytes · raw
-- Cairo's meson build (of the source, or of the resource d2d), the library only, with the Windows backends: Win32
-- surface and font, DirectWrite, FreeType, PNG, PDF, PS, SVG, script, tee.
-- What it installs: libcairo.a (static) or cairo.lib with cairo-2.dll; the headers in include/cairo/.

-- `from` in the file replaced by `to`, which must be there
local function replace(file, from, to)
    local text = otok.read(file)
    local at, last = text:find(from, 1, true)
    assert(at, file .. " no longer has: " .. from)
    otok.write(file, text:sub(1, at - 1) .. to .. text:sub(last + 1))
end

-- The tree to build. With clang-cl two things MSVC never meets: clang has __uint128_t, whose
-- division needs compiler-rt's __udivti3, which MSVC's runtime lacks, so cairo-wideint must not take it; and the
-- script interpreter's C99 inline functions have no external definition there, which MSVC emits anyway: it is not
-- built (it is not this recipe's library). The resource d2d is read-only in the cache: a copy.
local function source_of(slice, options)
    local source = options.d2d and slice.resources.d2d or slice.source
    if not slice.toolchain.cc:find("clang%-cl") then return source end
    if options.d2d then
        otok.copy(source, slice.build .. "/d2d")
        source = slice.build .. "/d2d"
    end
    replace(source .. "/meson.build", "  ['uint128_t', {'headers': ['stdint.h']}],\n  ['__uint128_t']\n", "")
    replace(source .. "/util/meson.build", "if conf.get('CAIRO_HAS_INTERPRETER', 0) == 1", "if false")
    return source
end

function build(slice, options, deps)
    local meson_options = {
        dwrite = "enabled", freetype = "enabled", fontconfig = "disabled", png = "enabled", zlib = "enabled",
        tee = "enabled", quartz = "disabled", xcb = "disabled", xlib = "disabled", tests = "disabled", lzo = "disabled",
        ["gtk2-utils"] = "disabled", glib = "disabled", spectre = "disabled", ["symbol-lookup"] = "disabled",
        gtk_doc = false,
    }
    -- the option d2d exists only in the fork's meson build
    if options.d2d then
        meson_options.d2d = "enabled"
    end
    local source = source_of(slice, options)
    otok.meson{
        source = source,
        -- beside the copy of d2d, not around it
        build = source:find(slice.build, 1, true) and slice.build .. "/build" or nil,
        options = meson_options,
    }
    local p = slice.prefix
    local dll = otok.glob("bin/cairo*.dll", p)[1]
    if dll then
        return { libraries = { cairo = { link = otok.glob("lib/cairo.lib", p)[1], runtime = dll } }, headers = p .. "/include/cairo" }
    end
    local lib = otok.glob("lib/libcairo.a", p)[1] or otok.glob("lib/cairo.lib", p)[1]
    return { libraries = { cairo = lib }, headers = p .. "/include/cairo" }
end
recipe.toml 2154 bytes · raw
# The otok recipe of Cairo (https://github.com/apotocki/otok) for Windows: Cairo 1.18.4 from its release archive, or
# with d2d the branch d2d of the fork https://github.com/apotocki/cairo, which adds the Direct2D surface on Direct3D
# 10.1 and 11. With MSVC or with clang-cl across from Linux. Static or dynamic; Pixman, FreeType and libpng static
# unless the project chooses otherwise, zlib as the project builds it.
[recipe]
api = 1
library = "cairo"
name = "cairo"
version = "1.18.4"
revision = 1
license = "LGPL-2.1-only OR MPL-1.1"
license-files = ["COPYING", "COPYING-LGPL-2.1", "COPYING-MPL-1.1"]
homepage = "https://www.cairographics.org"
description = "Cairo, the 2D graphics library, for Windows: GDI, DirectWrite and, as an option, Direct2D."
keywords = ["graphics", "2d", "vector", "direct2d"]
linkage = ["static", "dynamic"]

[source]
url = "https://cairographics.org/releases/cairo-1.18.4.tar.xz"
sha256 = "445ed8208a6e4823de1226a74ca319d3600e83f6369f99b14265006599c32ccb"

# the branch d2d of apotocki/cairo: the Direct2D surface (cairo_d2d_* of cairo-win32.h) on Cairo 1.18.4
[[resource]]
name = "d2d"
git = "https://github.com/apotocki/cairo"
commit = "e934468cdf8b488a72639ab7e2accabe5cd3e4b1"
when = { option = "d2d" }

[platforms]
supported = ["windows"]
build-on = ["windows/msvc", "linux/clang-cl"]

[options.d2d]
type = "bool"
default = false
doc = "The Direct2D surface on Direct3D 10.1 and 11 (CAIRO_HAS_D2D_SURFACE, cairo_d2d_* in cairo-win32.h), its CSS blend modes and GPU drop shadow: the branch d2d of apotocki/cairo."

[deps.pixman]
version = ">= 0.40"
default-recipe = "apotocki/pixman"
linkage = "static"

[deps.freetype]
version = ">= 2.10"
default-recipe = "apotocki/freetype"
linkage = "static"

[deps.libpng]
version = ">= 1.6"
default-recipe = "apotocki/libpng"
linkage = "static"

[deps.zlib]
version = ">= 1.2"
default-recipe = "apotocki/zlib"

[toolchains]
meson = { version = ">= 1.3", default-recipe = "apotocki/meson" }
ninja = { version = ">= 1.10", default-recipe = "apotocki/ninja" }
pkg-config = { version = ">= 1", default-recipe = "apotocki/pkgconf" }

[[product]]
name = "Cairo"
libraries = ["cairo"]