project-navigation
Personal tools

Author Topic: Using cmake to setup build env  (Read 36020 times)

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Using cmake to setup build env
« on: August 06, 2015, 10:34:31 pm »
Hello,

First, thanks again for this great game. I've played 2.5 a year ago (finished it in normal) and I've recently started a new campaign to try 2.6 in hard mode and it seems you have done some great work. I will give you some more feedback when I will have played a little bit more.

I've recently downloaded the code source from github and compiled it (at least game, ifo2map, ufoed and ufo). Have you ever considered using cmake ?
Would you be interested in using it ?
If yes, I'm not a cmake expert but I can give a try ^^

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #1 on: August 07, 2015, 04:16:26 am »
Hi,

Glad you are enjoying the game, and sure if you could get cmake working that would be very nice :)

Offline anonymissimus

  • Sergeant
  • *****
  • Posts: 347
    • View Profile
Re: Using cmake to setup build env
« Reply #2 on: August 08, 2015, 04:49:58 pm »
I've done a little research regarding cmake at some point, it's likely a lot of work. Stackoverflow has some valuable info.
cmake would allow generating an MSVC project file, as it seems the ability to compile with MSVC was present some time way in the past and then got lost due to nobody maintaining it. That is bad, since it should have a positive effect on code stability if you're able to compile and/or debug using various tools, and developer interest can rise.

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #3 on: August 08, 2015, 10:34:45 pm »
Well, actually, it was easier than I expected. I choose to not use a bundle for dependencies to try the latest versions I can find. Note that I use code blocks with MinGW64.
ATM, I can build every project excepted uforadiant because it needs gtk. I've downloaded gtk dev libraries but it seems an older version is used in this project as I get errors complaining that only gtk/gtk.h should be included (from what I've seen, many files here include gtkwidget or only what they need - which seems not the way to do in the new version).
Because of that, I've downloaded ufoai codeblocks zip to get the includes and libraries used in the project (since I cannot use the latest version, the easier is to use this one).

For finding the dependencies, I've tried to use the scripts bundled with cmake as much as possible (because they probably include more search paths than the ones I will think of - especially on environments I don't know like MAC OS). Fortunately, I could find those for most of the required dependencies.

Once I get uforadiant to compile, I will have a look with linux (with Ubuntu running in virtualbox). I guess it will be easier as with windows, no dependency is found by itself.

That is bad, since it should have a positive effect on code stability if you're able to compile and/or debug using various tools, and developer interest can rise.
Yes, finding people who want to join an open source project is hard enough to not have them have to change the environment they like.
The good point with cmake is that it sets up the environment you like (be it MSVC, codeblocks MinGW, ...) by itself. The problem with maintaining project files is that when there is no more coder using it (for example MSVC), it will die fast (when a new file is addedn for example). When using cmake, you had a new file in the makefile and it will change all configurations ^^ (even some you had never tried and even knew they exist)


Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #4 on: August 10, 2015, 02:06:50 am »
Good to hear that you are making good progress, looking forward to it :)

To be fair uforadiant has always caused us problems... I'm not even sure if it actually compile on windows right now — see bug #5252 (I know it compiles on linux)

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #5 on: August 11, 2015, 12:29:50 am »
Yes, I had this error when using the headers/libraries from the codeblocks+mingw package.
The error comes from this commit:
https://github.com/hwoarangmy/ufoai/commit/bf841a7ff5325e10775cae7a67eaf7ebea67a30f#diff-3062a8827676e9b846c0ac56236a4744L340

because g_mutex_init and the mutex related functions are not found. For my tests, I've rolled back this commit and it worked.
If I am not mistaken, those functions are from glib. I guess your Linux distros have more recent glib. The best would probably be to update the bundled glib. I will try with a new version and tell you if it works.

Concerning cmake, I was able to build all the projects (including radian). There were too many dependencies so I didn't want to mess with gtk and all their dependencies. That's why I used the package libraries. For cmake finding module, I will assume there is 1 include directory per needed library (in the bundle, the include directory will be the same for all dependencies).
Now, the last missing thing is the icon ^^

Then, I will try on linux

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #6 on: August 11, 2015, 10:55:32 pm »
I've tried with a newer version of glib (the one bundled with the latest gtk version) and, as expected, it fixes the compilation problem with mutex functions.

Concerning cmake,  could make it work and found a way to use icons with only a small modification of the rc files. ATM, they use a flag to know if they should use a relative path. I've removed the flag and replaced it with the path to use. That makes the rc file more straight forward.

Concerning the bundle, I can make a new one to fix the issue by replacing glib headers + libs. Do you want me to do that ?

Concerning cmake, I'm testing on linux.

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #7 on: August 12, 2015, 07:09:39 pm »
Concerning the bundle, I can make a new one to fix the issue by replacing glib headers + libs. Do you want me to do that ?
That would be nice for our windows users.

Quote
Concerning cmake, I'm testing on linux.
Great!

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #8 on: August 16, 2015, 12:56:57 am »
I'm done with the first version. I've tested on Linux and it builds successfully on my Ubuntu as well as on windows.
I've rebased tonight and made the required changes due to lua.

Note that I've tried to follow what was done on the makefiles while working on cmake. But I couldn't test on Solaris or MacOSX.

If you want to integrate it, I can make a pull request on guthub.

The next steps, if you want, could be to turn building projects optional (with only game + ufo checked by default).
It might also be a good idea to allow to enter a dependency path so that users can compile without having to mess with the dependencies (that would be very close to the codeblocks current zip but with the dependencies only).

To test, you can have a look:
https://github.com/hwoarangmy/ufoai

WDYT ?

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #9 on: August 16, 2015, 02:52:50 am »
This is great!

Will a better look later, but just from what I can see: There seems to be no support for SDL2? I'm sure that's the direction Mattn wanted to move on. Is that something that can be made optional choosing between SDL 1.x and SDL 2.x? (Or maybe its already in and I'm just not seeing it...)

Also yes, having the option to turn projects on and off would be nice, as for dependecies, I gues that would be most useful for windows user I'd think?

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #10 on: August 16, 2015, 11:03:20 am »
There seems to be no support for SDL2?
It works with both. I've tested on windows with SDL2 (I downloaded) and SDL (from the package). Both worked. You just have to choose the corresponding includes you want and the libraries.

Also yes, having the option to turn projects on and off would be nice, as for dependecies, I gues that would be most useful for windows user I'd think?
I guess that most users won't use radiant and it has many dependencies so it could be nice to be able to turn it off. And if we are there, we can do the same for all.

BTW, note that I've simplified the rc files to allow choosing the path. Do you want me to change the codeblocks projects in build/projects to match ?
Moreover, I don't know how to choose the icon on linux (the equivalent to the rc files). Do you know how does it work ?

EDIT: I've installed SDL2/SDL2-mixer/SDL2-ttf and I confirm it works when we change the include paths/libraries. I remember having read news about bugs in UFOAI when using SDL2. Later, the makefile can be changed to look for SDL2 before SDL.
Note that I've tested and if SDL2 is installed but not SDL, SDL2 is not found

EDIT2: If you want to try, I've updated the commit in my repo so that if SDL is found, it is used. And if not, it will search for SDL2.
« Last Edit: August 16, 2015, 10:35:27 pm by hwoarangmy »

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #11 on: August 17, 2015, 05:21:26 am »
It works with both. I've tested on windows with SDL2 (I downloaded) and SDL (from the package). Both worked. You just have to choose the corresponding includes you want and the libraries.
I've now had time to actually test and I see this now, my bad.

Quote
I guess that most users won't use radiant and it has many dependencies so it could be nice to be able to turn it off. And if we are there, we can do the same for all.
But on linux after running cmake you can just do make ufo game to build just the game, so most helpful to windows user (but now that I think VS should have something similar...) anyway I mostly meant that a dependency path would be most helpful to windows users, still making the other modules optional would be nice anyway.

Quote
BTW, note that I've simplified the rc files to allow choosing the path. Do you want me to change the codeblocks projects in build/projects to match ?
For consistency I'd have to say yes please.

Quote
Moreover, I don't know how to choose the icon on linux (the equivalent to the rc files). Do you know how does it work ?
Linux executables don't have icons

Quote
EDIT: I've installed SDL2/SDL2-mixer/SDL2-ttf and I confirm it works when we change the include paths/libraries. I remember having read news about bugs in UFOAI when using SDL2. Later, the makefile can be changed to look for SDL2 before SDL.
Note that I've tested and if SDL2 is installed but not SDL, SDL2 is not found

EDIT2: If you want to try, I've updated the commit in my repo so that if SDL is found, it is used. And if not, it will search for SDL2.
Well we currently have SDL2 taking priority over SDL (and the worst bugs are already fixed :) ) so this is maybe backwards, but OK for starting.

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #12 on: August 17, 2015, 09:54:03 am »
But on linux after running cmake you can just do make ufo game to build just the game, so most helpful to windows user (but now that I think VS should have something similar...)
Well, it is always possible to compile only one project but the point with turning them optional is to not ask for dependencies. This way, if you disable uforadiant, for example, cmake will not ask for GTK (or at least won't complain if it is missing)

Linux executables don't have icons
Ok, nice to know

Well we currently have SDL2 taking priority over SDL (and the worst bugs are already fixed :) ) so this is maybe backwards, but OK for starting.
Ok. So, I will change so that SDL2 is chosen in priority to SDL.

For consistency I'd have to say yes please.
Ok. I will do that.

Note that I won't be around for a few days so I won't have time to do requested changes now. I will do them once I'm back ^^

Offline DarkRain

  • Project Coder
  • Captain
  • ***
  • Posts: 746
    • View Profile
Re: Using cmake to setup build env
« Reply #13 on: August 19, 2015, 04:56:47 am »
Well, it is always possible to compile only one project but the point with turning them optional is to not ask for dependencies. This way, if you disable uforadiant, for example, cmake will not ask for GTK (or at least won't complain if it is missing)

You have a good point there.

Quote
Note that I won't be around for a few days so I won't have time to do requested changes now. I will do them once I'm back ^^
That's OK, take care!

Offline hwoarangmy

  • Rookie
  • ***
  • Posts: 84
    • View Profile
Re: Using cmake to setup build env
« Reply #14 on: August 25, 2015, 01:19:10 am »
I'm almost done with what I wanted to do. I could build all the projects with Windows and Linux. All of them are optional (only UFO and GAME checked by default).
However, I'm lacking quick description for the projects:
- GAME: "Build the library handling the battlescape"
- UFO2MAP: "Build the tool to compile maps"
- UFODED: ?
- UFO: "Build the main game"
- UFOMODEL: ?
- UFOSLICER: ?
- UFORADIANT: "Build UFO AI editor"
- UFOTESTALL: "Build unitary tests"

If someone could fill unknow projects (or complete the other ones if needed), it would be nice.

I'm also building a package with UFO AI dependencies only (allowing to build with any code-blocks/MinGW anyone has installed instead of having to use a full bundle)

Now, I'm going to try to build the game with an older computer with MinGW32 (I've currently used MinGW64) and with MSVS2013 (except radiant and maybe testall because they have too many dependencies). If I can build it with MSVS2013, I will add required dependencies in the bundle.