Author Topic: multiplatform GTK proyect  (Read 17860 times)

epsilon_da

  • Guest
multiplatform GTK proyect
« on: April 08, 2009, 06:17:15 pm »
Hi.

I use codeblocks to program GTK applications together with some other libs like libusb and fftw3.

I programm mainly on linux i note lots of diferences which i will list on this post.

On OpenSuse,  Codeblocks 8.02 Build Mar 12 2009 svn 5483
On Windows,   Codeblocks 8.02 Build Feb 27 2008 no svn info

I started the first time with the GTK template, which in my opinion is incomplete.
It creates a simple, empty, non-portable Proyect with some gtk lines.

   GTK uses pkg-config for mostly everything.
   There are other ..-config programs like libusb-config
   Thoose programs makes life easier. And and can list "some" available libs on the libraries tab.

   On windows, the template AND the user have to add each include and linker related directory, which for GTK, are a lot. So it makes lernning GTK with codeblocks much more difficult for beginners.
   The options created by the template are global for the proyect and are not platform independent, so to compile the same proyect on linux, one have to re-estructure entirely the proyect and mantain a Debug/Release target for each OS. Debug-Win32, Debug-Linux, Release-Win32, Release-Linux,...
   This wont be necessary if pkg-config output where supported on windows too.
   It would be easier if the "libraries" tab worked in the same way for both platforms with all ..-config tools. Of course, a dialog to set the path to thoose tools will need to be available.


The Linux version have a funny limitation. The Linux version of CB can not edit the build properties of a target selected for windows, but the windows version can edit the properties for linux. I dont understand this limitation.

There should be also 2 versions of windows available. The "real" windows and CrossCompiling with MinGW for windows on linux. That is, producing exe's on linux.

That will make easier to use Codeblocks, and produce multiplatform opensource software.

Outside of that, Codeblocks is the best IDE ever.
I dont know why isnt it more used instead of Anjuta or KDevelop.



Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #1 on: April 08, 2009, 06:41:50 pm »
patches very welcome :)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #2 on: April 08, 2009, 07:16:07 pm »
I see, a bugreport isnt acepted without a patch to fix it.
Sure, then we will wait a couple of years with lucky, until i get used to wxwidgets and the codeblocks source code, and some have some other things in life finished. And, of course, it may not be acepted in main stream. At the end, it is easier to live with both problems. :)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #3 on: April 08, 2009, 07:53:07 pm »
I wasn't trying to be a wise guy with my response. I suggested a patch because:

* you gave us a detailed report suggesting you know enough about GTK to make a useful contribution;
* the wizards are scripted and should be relatively easy to understand for a newcomer;
* open source is all about scratching your own itch -- I don't know if any of the devs are using GTK as extensively as you are (I use pygtk from time to time, which is clearly irrelevant)
* we're actually pretty good about accepting patches. we have the usual open source problem of not enough hands to handle all of the requests.

If you don't want to contribute patches, it would be most helpful if you submit issues to the bug tracker or as a feature request. e.g. report bugs at http://developer.berlios.de/bugs/?group_id=5358

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #4 on: April 08, 2009, 08:03:06 pm »
   It would be easier if the "libraries" tab worked in the same way for both platforms with all ..-config tools. Of course, a dialog to set the path to thoose tools will need to be available.

that can be done in the wizard scripts.
alternatively, you have the wizard create global variables to allow the user to set paths to executables via that panel (this tends to be more useful on windows than on linux systems)

for more info:

http://wiki.codeblocks.org/index.php?title=Wizard_scripts

Quote
There should be also 2 versions of windows available. The "real" windows and CrossCompiling with MinGW for windows on linux. That is, producing exe's on linux.

you should be able to do that by creating a new compiler and setting up the appropriate tool chain.
« Last Edit: April 08, 2009, 08:08:58 pm by dmoore »

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #5 on: April 09, 2009, 04:45:28 am »
ok. I will check that about wizard scripts and try to make a portable GTK template.

But i think that the problem wont be fixed by that.

At the gtk wizard.script is this:

Code
if (PLATFORM == PLATFORM_MSW)
    {
        project.AddIncludeDir(GtkPathDefaultInc);
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
        // Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
        project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
        project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));
        project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));


        project.AddLibDir(GtkPathDefaultLib);

        // add link libraries
        project.AddLinkLib(_T("gtk-win32-2.0"));
        project.AddLinkLib(_T("gobject-2.0"));
        project.AddLinkLib(_T("glib-2.0"));

        // Notice: there are more libs required as the app gets more complex, e.g.:
        // pangocairo-1.0.lib, pangocairo-1.0.lib, libatk-1.0.dll.a,
        // gdk_pixbuf-2.0.lib, gdk-win32-2.0.lib,  pango-1.0.lib,
        // gmodule-2.0.lib,    gthread-2.0.lib,    cairo.lib,
        // pangoft2-1.0.lib    (...)

        project.AddCompilerOption(_T("-mms-bitfields"));
    }
    else
    {
        /*if (GtkVersion == 1)
        {*/
        project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
        project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
        /*}
        else
        {
            project.AddCompilerOption(_T("`pkg-config gtk+ --cflags`"));
            project.AddLinkerOption(_T("`pkg-config gtk+ --libs`"));
        }*/
    }


If you have programmed on linux you can see the special quotes used with pkg-config.
Thoose are not supported by windows so it wont work with a just system() or exec() call.
I have attached some screenshots to be more clear.

One shows my project setup, focused on the windows target and everything disabled. It shouldnt be. I should be able to change my own project options.
It also shows the pkg-config and others "--cflags" in an offtopic(?) place "Other options". Thoose lines should be somehow under the search Tab and be autoconfigured acordingly to the selected "Libraries used in the project" as shown in the other sshot.
This Libraries dialog should also be part of each target configuration, and not globals per project.
Windows may require sometimes different libs. Like if you use, libusb on linux and the windows USB-API. There are also differences on some export simbols used by glade to autoconnect signals.

The last images, shows error messages because the pkg-config call is not being executed, and the include and linker dirs are not found.

One can know where is pkg-config on windows. If you setup the GTK path then it is at $GTK/bin/pkg-config.exe
Then codeblocks should do what windows doesnt on parsing the special quotes `...`


What i am trying to say is that, i can make different targets for each OS an have a different configuration for each one, but this may be a work around to the better fix.
If the toolkit used is platform independent, ¿shouldnt it by default be configured the same on all platforms?

Also, it seems strange to configure a project on linux and CB, because all the normal lines are always on places like "Other Options" or "Other linker options" or "Other stuff", thoose places are always like "almost never used" or "use with acknowledge", and are not very obvius to the beginner.


I will post here my GTK template when i have it working because here is more handy to me.


[attachment deleted by admin]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #6 on: April 09, 2009, 05:09:36 am »
Then codeblocks should do what windows doesnt on parsing the special quotes `...`

IIRC, codeblocks provides support for backticks in build settings on windows (try it)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #7 on: April 09, 2009, 10:09:45 am »
hehe, i tried, of course, you can see the screenshots and it doesnt works.
Not with pkg-config alone, and not with the full path.
Can you show me an example?

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #8 on: April 09, 2009, 03:54:18 pm »
works for me

goto project -> build options -> compiler settings -> other options add the text

Code
`c:\gtk\bin\pkg-config gtk+-2.0 --cflags --errors-to-stdout`

You can see the compiler command lines and output after switching on full compiler logging in the compiler settings. In my case I get an error because PKG_CONFIG_PATH wasn't set

btw folks, it is a little worrying that if the back tick fails to execute C::B proceeds as if nothing is wrong. e.g. if pkg-config is missing wouldn't it be better to produce a compiler error, or at least a warning (maybe I've missed something)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #9 on: April 09, 2009, 06:42:56 pm »
 :shock:

ok. it worked.
I couldnt see the output, i just cant find an option to enable all outputs which works. Only all warnnings (-Wall)
I also couldnt find the pkg_config_path variable, but as it worked, i supose that it is correctly set.

thanks.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #10 on: April 09, 2009, 07:57:27 pm »
I couldnt see the output, i just cant find an option to enable all outputs which works.

settings -> compiler and debugger -> global compiler settings -> other settings -> compiler logging

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #11 on: April 09, 2009, 10:05:21 pm »
Thanks.

I have 2 questions about the scripting.

It seems like a will have to create different targets (i dont know how yet) for each OS unless CB supports the next stuff:

To be able to use the same pkg-config commands on any os, then it muss be on the path.
project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags --errors-to-stdout`"));
project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs --errors-to-stdout`"));

I need that codeblocks adds   GtkPathDefaultBin   to the path only when the project is run in windows. For that i need an script to be executed before each compilation and be able to check this variables and save it to the PATH before running gcc or the backquoted code.
Can this be done in "PRE build steps"?
Where is a tutorial or documentation or code examples to know what kind of scripting is used on this place.

Also i have to add -mms-bitfields to gcc only on windows

if _os_ == Windows:
   PATH += GtkPathDefault + FILE_SEP_PATH + "bin"
   CC += CC + "-mms-bitfields"

(Assuming that PATH and CC is reseted on every run)

OR -mms-bitfields, could be added directly to "Compiler Flags".
Also   -mno-cygwin  is an useful flag too.
Both should only be when compiling on windows.


Quote
If the API uses structs with certain kinds of bitfields, you must use the flag -mms-bitfields in gcc for the struct field packing to be identical to that MSVC uses. GTK+ uses such API, and the commonly used GTK+ binaries built by TorLillqvist are compiled using gcc with this flag. They are thus also usable from MSVC code, and when building GTK+-using software with gcc, the flag must also be used.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #12 on: April 09, 2009, 10:42:06 pm »
take a look at the wxWidgets wizard script as it uses the PLATFORM constant to determine which OS (see here for more on Scripting http://wiki.codeblocks.org/index.php?title=Scripting_commands).

I don't think there is support for setting the path via a script (yet). An alternative to setting the path is to define a custom variable for the project in project -> build options -> custom variables, say

gtk_bin_dir = C:\GTK\bin\

on win32 and leave it empty on linux. then your back tick would be:

`$(gtk_bin_dir)pkg-config gtk+-2.0 --cflags`

to do that in a script I think you would use the SetVar method of CompilerOptionsBase

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #13 on: April 09, 2009, 11:04:51 pm »
But i am on the same problem here, or not?

IF i have gtk_bin_dir setted to some path on windows side and then try to compile con linux, the path will be wrong.
I need to update this variable every time the program is built and check for OS.

I am currently reading what you gave me. Thanks.


Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #14 on: April 09, 2009, 11:15:34 pm »
IF i have gtk_bin_dir setted to some path on windows side and then try to compile con linux, the path will be wrong.
I need to update this variable every time the program is built and check for OS.

you could have the wizard add a build script to check platform and define variables accordingly every build.
Not sure how you will deal with cross-compiling...

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #15 on: April 09, 2009, 11:42:42 pm »
Thanks dmoore for your help.
I have managed to set the variables, once i have this working i will see to change the path depending on the OS, but it seems like variables inside backquotes are not parced.
I dont see variables inside backquotes on others wizards.


    project.SetVar(_T("pkg_config"), PkgConfig , false);
    project.AddCompilerOption(_T("`$(pkg_config) gtk+-2.0 --cflags --errors-to-stdout`"));
    project.AddLinkerOption(_T("`$(pkg_config) gtk+-2.0 --libs --errors-to-stdout`"));


This are the lines under "other option":

-mms-bitfields
`$(pkg_config) gtk+-2.0 --cflags --errors-to-stdout`

And this is the compilation line

mingw32-gcc.exe -Wall -mms-bitfields   -g     -c "C:\Documents and Settings\Diego_test\Escritorio\bbbbbb\main.c" -o obj\Debug\main.o


Is this what you say about that it is not outputing errors?

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #16 on: April 10, 2009, 08:17:27 pm »
yes, looks like backticks get substituted before variable expansions (I could be wrong, haven't looked at the code). not sure what the rationale for that would be...

The other not altogether unreasonable approach to take is to expect the user to put GTK\bin in their path. (Even if they can't change the path globally, the envvars plugins allows user to set up sets of environment variables that can be assigned per project.) This is not as newbie friendly, but less bug prone than relying on scripts. You could even have a pre-build script that tries to run pkg-config and spits out an error if it couldn't be found telling the user to put it in their path.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #17 on: April 10, 2009, 08:18:32 pm »
Is this what you say about that it is not outputing errors?

you don't see anything if the backtick fails to execute - C::B simply substitutes an empty string... not so good.

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #18 on: April 10, 2009, 08:45:03 pm »
Thanks.
I decided to make 4 targets, 2 for unixes (and possible mac too), and 2 for MSW.
Why?
Because, if you are testing and compiling your project on multipleplatforms, the compiled object code will need to be clean when you switch of desktop and thoose, making it slower to compile and test.

Too sad to hear that "backticks get substituted before variable expansions". That will make the project configuration cleaner by setting the gtk path and other stuff as variables.


Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #19 on: April 10, 2009, 08:59:42 pm »
Too sad to hear that "backticks get substituted before variable expansions". That will make the project configuration cleaner by setting the gtk path and other stuff as variables.

probably a trivial fix, just have to figure out if there is a good reason it does what it does.

I decided to make 4 targets, 2 for unixes (and possible mac too), and 2 for MSW.

nice. I assume you will provide a dialog that lets the user choose which targets they want to create. (I think this is done on the other wizards)


epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #20 on: April 11, 2009, 04:09:30 am »

I have a problem adding files to a project. This should be done automatically by returnning a path in
functions GetFilesDir()

But it doesnt work when i configure new Targets.

    project.DuplicateBuildTarget(0,_T("Debug-Unix") )
    project.DuplicateBuildTarget(0,_T("Release-Unix") )
    project.DuplicateBuildTarget(0,_T("Debug-MSW") )
    project.DuplicateBuildTarget(0,_T("Release-MSW") )
    project.RemoveBuildTarget(_T("default") );

I have not used the default Debug and Release.

With this, main.c is added to the project but not to the targets, so it wont compile.
I have to "Add File" manually and add it to each target to be able to compile.



The other problem that i cant find solution, is to set the current target selection. I tryed with this:

        if (PLATFORM == PLATFORM_MSW)
            project.SetActiveBuildTarget( _T("Debug-MSW") );

But is not doing anything.

Can you help me with this?

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #21 on: April 11, 2009, 08:25:46 pm »
Ok, the first is fixed, but, i still dont get the second fixed.

        if (PLATFORM == PLATFORM_MSW)
            project.SetActiveBuildTarget( _T("Debug-MSW") );


epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #22 on: April 12, 2009, 06:57:34 pm »
Here is my GTK Wizard.
Someone experienced with wizards should take a look at the code to see if there is something else to fix.

Now my question is: Will it be merged in mainstream? or should i keep my copy?

Differences with the original:
 - 4 targets created, 2 for unixes and 2 for windows, minimal differences.
 - The unixes targets could work with mac. I cant test that.
 - Added selection of starting code to a set of common examples of a minimal gtk, glade, systray icon, drawingarea, gdk and cairo, and custom widgets.
 - What is missing is a Clutter example.

Also it will be nice to create a GtkWidget/GObject generator plugin. ¿Is there any other similar plugin?

Cheers.



[attachment deleted by admin]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #23 on: April 13, 2009, 10:19:14 pm »
Now my question is: Will it be merged in mainstream? or should i keep my copy?

I think you have made a useful contribution...

Quote
Differences with the original:
 - 4 targets created, 2 for unixes and 2 for windows, minimal differences.

The user should be able to check off which ones they want

Quote
- Added selection of starting code to a set of common examples of a minimal gtk, glade, systray icon, drawingarea, gdk and cairo, and custom widgets.
 - What is missing is a Clutter example.

interesting. it probably does no harm, but do you need so many samples?

Quote
Also it will be nice to create a GtkWidget/GObject generator plugin. ¿Is there any other similar plugin?

a class wizard or a gui? there's a very simple class wizard plugin that you can use as a template. wxSmith provides a more fully integrated wxWidgets gui building experience.

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #24 on: April 14, 2009, 04:17:09 am »
The user should be able to check off which ones they want

The user can. From "Build Options" dialog. :)
I removed it for 2 reasongs. I couldnt find an easy way to separate windows configuration from linux configuration. And what if you launch the wizard from a Unix system?, then you wont be able to set a windows-gtk-path.
Also my opinion is that, making too much unnecesary pages in wizards, is like polution. I have never changed the Targets names, or paths. And i find the "Build Options" dialog simpler and smarter.
But if it is really needed, someone else could find the way to add the 4 targets. Its not my priority right now.


interesting. it probably does no harm, but do you need so many samples?
Thoose examples are zipped 64kb. This doesnt make harm, but it add a bonus and a starting point for each different project. Like a Glade based project with GtkBuilder or a plugin-based application with GModule starting with the same. A new custom widget which can be drawn with GDK or Cairo. Or using a DrawingArea which is very oft on gtk and can be done in many ways.
With this 64kb of examples, a new user can learn faster how to use a portable toolkit, and take a look before reading a complete tutorial.
It would be nice to have more starting points for wxWidgets and QT and be able to compile them on any platform.
In this way we help a bit more to show people that producing portable software is not hard.


Why would someone deliberately make a software non-portable when no extra code penalty is needed?
Or why shouldnt a portable IDE help to portability?

Cheers.

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #25 on: June 01, 2009, 12:43:00 am »
Will this be added to main stream?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: multiplatform GTK proyect
« Reply #26 on: June 02, 2009, 08:17:39 am »
Will this be added to main stream?
Only if I find the time to include it into the build process. Notice that you did not provide the Makefiles (Makefile.am) and alike. There is nothing wrong with it, but adding it to trunk as it is would break compilation of C::B on Linux. So - in the current stage it needs some more work.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #27 on: June 02, 2009, 04:50:07 pm »
ok, thanks.
I just need to know that i wouldnt need to overwrite the codeblocks gtk template each time it is updated in my distro.