1

Using GtkAda, I'm trying to use the resource API to include the Glade file directly inside my code.

For this, we can generate C code from a set of resources using glib-compile-resources which can then be linked to the Ada code.

The problem is that this C code requires Gtk includes which we usually get from the pkg-config command under Linux such as

gcc -c -x c `pkg-config --cflags gio-2.0` myglade.gresource.c

I'd like to know how to provide the same kind of information in a GPRBuild project file.

FYI, I already tried to use the pkg-config command inside the compiler package for C language without any success. Of course, I managed to build by hand but that's a bit long :)

Frédéric Praca
  • 1,620
  • 15
  • 29

2 Answers2

5

This might work for you:

project Config_Demo is
   Pkg_Config := external_as_list ("PKG_CONFIG", " ");
   package Compiler is
      --  only this file needs the extra switches
      for Switches ("myglade.gresource.c") use Pkg_Config;
   end Compiler;
end Config_Demo;

and then

gprbuild -P config_demo -XPKG_CONFIG="`pkg-config -cflags gio-2.0`"
Simon Wright
  • 25,108
  • 2
  • 35
  • 62
  • I wondered whether you could provide a special addition to the GPR configuration database which would use the `` feature, which runs an external command; but it’s only legal in a `` element, and introducing a new "compiler" for this seems ... wrong. Also, not sure how to get the result as a list - it’s intended for querying the compiler, e.g. `-dumpmachine`. – Simon Wright Feb 28 '19 at 12:08
  • 1
    Your first solution is working !... And I agree with you, providing a special compiler description in the GPR configuration database for this seems to me quite wrong as it's not the main purpose of it. – Frédéric Praca Feb 28 '19 at 21:25
3

Your best bet will be to do what GtkAda does: Look at its shared.gpr.in file, it uses the token @GTK_LIBS_GPR@ which will be replaced by the configure script, giving a usable shared.gpr.

Thing is, you need to issue the pkg-config call and build your gpr file from the result somehow. GPRBuild is not equipped to do this for you and process the result. If you're comfortable with GNU autotools, you can look further at how GtkAda achieves it:

GTK_LIBS_GPR is set in aclocal.m4 using a macro that converts the C-style flags to a GPR array. The value comes from GTK_LIBS which is queried here via pkg-config.

If you're not comfortable with GNU autotools, you can write your configure script using basic shell commandos, a scripting language like Python or with whatever other tool you're comfortable with.

flyx
  • 35,506
  • 7
  • 89
  • 126