Compiling with &package_string;

3

Compiling with &package_string;

Notes on compiling.

## Building

If you need to build &package_string;, get the source from here and see the `README.md` file.

## Using pkg-config

Like other GNOME libraries, &package_string; uses pkg-config to provide compiler options. The package name is "`&package_ver_str;`".

If you use Automake/Autoconf, in your `configure.ac` script, you might specify something like:

          PKG_CHECK_MODULES(LIBHANDY, [&package_ver_str;])
          AC_SUBST(LIBHANDY_CFLAGS)
          AC_SUBST(LIBHANDY_LIBS)

Or when using the Meson build system you can declare a dependency like:

          dependency('&package_ver_str;')

The "`&package_api_version;`" in the package name is the "API version" (indicating "the version of the &package_string; API that first appeared in version &package_api_version;") and is essentially just part of the package name.

## Bundling the library

As &package_string; uses the Meson build system, bundling it as a subproject when it is not installed is easy. Add this to your `meson.build`:

          &package_string;_dep = dependency('&package_ver_str;', version: '>= &package_version;', required: false)
          if not &package_string;_dep.found()
            &package_string; = subproject(
              '&package_string;',
              install: false,
              default_options: [
                'examples=false',
                'package_subdir=my-project-name',
                'tests=false',
              ]
            )
            &package_string;_dep = &package_string;.get_variable('&package_string;_dep')
          endif

Then add &package_string; as a git submodule:

          git submodule add &package_url;.git subprojects/&package_string;

To bundle the library with your Flatpak application, add the following module to your manifest:

          {
            "name" : "&package_string;",
            "buildsystem" : "meson",
            "builddir" : true,
            "config-opts": [
              "-Dexamples=false",
              "-Dtests=false"
            ],
            "sources" : [
              {
                "type" : "git",
                "url" : "&package_url;.git"
              }
            ]
          }

## Building on macOS

To build on macOS you need to install the build-dependencies first. This can e.g. be done via `brew`:

            brew install pkg-config gtk+3 adwaita-icon-theme meson glade gobject-introspection vala

After running the command above, one may now build the library:

            git clone https://gitlab.gnome.org/GNOME/libhandy.git
            cd libhandy
            meson . _build
            ninja -C _build test
            ninja -C _build install

Working with the library on macOS is pretty much the same as on Linux. To link it, use `pkg-config`:

            gcc $(pkg-config --cflags --libs gtk+-3.0) $(pkg-config --cflags --libs libhandy-1) main.c -o main