Skip to content

Conversation

keynmol
Copy link
Contributor

@keynmol keynmol commented Jun 19, 2022

Closes #18
Closes #4

Very basic/hacky integration with pkg-config.

The main goal is to rely on package's own understanding of what it needs to compile/link. With changes in this PR even for a library as huge as GTK, your nativeConfig definition can look like this:

vcpkgDependencies := Set("gtk")

nativeConfig := {
  val conf = nativeConfig.value
  val pkgConfig = vcpkgConfigurator.value

  conf
    .withCompileOptions(
      pkgConfig.updateCompilationFlags(conf.compileOptions, "gtk4")
    )
    .withLinkingOptions(
      pkgConfig.updateLinkingFlags(conf.linkingOptions, "gtk4")
    )
}

And yes, of course gtk4 is different from vcpkg's package name.

And for binding builder:

import bindgen.interface.Binding

bindgenBindings := {
  val manager = vcpkgManager.value
  val pkgConfig = vcpkgConfigurator.value
  Seq(
    Binding(
      manager.includes("gtk") / "gtk-4.0" / "gtk" / "gtk.h",
      "gtk",
      cImports = List("gtk/gtk.h"),
      clangFlags = pkgConfig.compilationFlags("gtk4").toList
    )
  )
}

Unfortunately binding generator breaks on GTK about halfway through, but the flags passed in are sufficient for clang to parse the entire file.

In comparison, here's what you had to manually add to attempt to compile gtk:

def allTheFuckingIncludes(manager: com.indoorvivants.vcpkg.Vcpkg) = {
  val gtk = manager.includes("gtk") / "gtk-4.0"
  val glib = manager.includes("glib") / "glib-2.0"
  val cairo = manager.includes("cairo") / "cairo"
  val glibOther = manager.files("glib").libDir / "glib-2.0" / "include"

  List(
    gtk,
    glib,
    glibOther,
    cairo,
    manager.includes("pango") / "pango-1.0",
    manager.includes("harfbuzz") / "harfbuzz",
    manager.includes("gdk-pixbuf") / "gdk-pixbuf-2.0",
    manager.includes("graphene") / "graphene-1.0",
    manager.files("graphene").libDir / "graphene-1.0" / "include"
  )
    .map(_.toString)
    .map("-I" + _)
}

@keynmol keynmol merged commit 33b4e07 into main Jun 19, 2022
@keynmol keynmol deleted the pkg-config branch June 19, 2022 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate with pkg-config Windows support
1 participant