Re: [Vala] Setting prefix and paths at configure time.



2008/9/24 Andrea Del Signore <sejerpz tin it>:
On Tue, 2008-09-23 at 23:55 +0200, Federico Pelloni wrote:
In my project I need to load some custom pixmaps that will be
installed into $prefix/share/projectname/pixmaps, with $prefix being
set at configure time. Classical situation for many applications. How
can I make my program find that files?
I'm using Waf to configure/build/install my application, and I can
have created a config.h file with those paths defined, but I don't
know how to access them within my .vala files.
I saw some projects (Valaide for example) using a "Config" namespace
or class, but I could not understand how it works.
I'd be glad if someone could explain me which direction I've to go to
solve this problem.

Thank you.

Federico Pelloni
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list

Hi Federico,

to use your generated config.h file you have to wrap it in a vapi file
and the compile it with your project.

E.g. you have to write a config.vapi file like this:

[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename =
"config.h")]
namespace Config {
       public const string VERSION;
       public const string PACKAGE_VERSION;
       public const string PACKAGE_STRING;
       public const string PACKAGE_DATA_DIR;
       public const string GETTEXT_PACKAGE;

       .... etc etc ....
}

and then compile it with your sources.

eg.

valac <your source files> --vapidir ./ --pkg config

or

valac <your source files> config.vapi

Cheers,
Andrea




Thank you both very much, it worked like a charm.

I post here some instruction that may be useful to somebody else:

To generate the config.h with Waf you have to define your constants in
the configure method of the main wscript:
    conf.define('PACKAGE', APPNAME)
    conf.define('DATADIR', os.path.join(conf.env['PREFIX'], 'share', APPNAME))
    ...
and then write the file (at the end of configure method):
    conf.write_config_header("config.h")

Then in the wscript_build file (or build method of wscript file,
depending on your file layout) inside the sources directory you simply
have to add a line specifying the location of your config.vapi file
    obj.vapi_dirs = '../vapi'
and add the "config" package to the packages string
    obj.packages = 'gtk+-2.0 glib-2.0 gio-2.0 config'

That was enough for me to make it work.

If you want to see the full sources they're here:
http://bazaar.launchpad.net/~fredp/ejecter/ejecter-vala/files

Regards,
Federico



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]