Reputation: 3418
I wanted to build an application that both runs on Gtk 2 and Gtk 3 environments. What are my options?
I am using C++ with cmake
on a linux machine.
Upvotes: 1
Views: 884
Reputation: 11454
FWIW, I think it's the wrong path. Unless you're targetting very old systems that only ship GTK+2, GTK+3 is the way to go. GTK+3 has been released in 2011 (9 years ago as I'm writing this), and GTK+2 is in maintenance mode since then. As soon as GTK+4 will be released (sometime in 2020 if things go well), then GTK+2 will no longer be maintained.
So the right question should rather be "GTK+3 and/or GTK+4 ?".
Use GtkBuilder to have most of the interface building stuff done for you and factored out. For the comportment part, you may test things at compile time:
#if GTK_VERSION(3, 22, 0)
// code neeeding GTK+ >= 3.22.0
#endif
Or just use a separate branch of code so you can make GUI specific stuff while still being able to merge non-UI-dependant code.
Upvotes: 0
Reputation: 180103
- Have two separate projects?
Of course that's an option.
- Have two separate build steps?
That, too, but the key objective there is to produce two different binaries (not necessarily both standalone executables, though, see below).
- Can a single executable be built so that it is able to run on both environments?
Yes, but doing so is not straightforward. Each binary you build will be linked against a specific library. It cannot be otherwise, because there are manifold name collisions between the v2 and v3 libraries.
If you are willing to abstract your Gtk usage, however, so as to provide for pluggable back-ends, then you could provide both Gtk+2 and Gtk+3 back-ends. And others, too. But this is non-trivial, especially if you've already written the application with direct Gtk calls.
Upvotes: 2