CMake build script

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CMake build script

Post by CuteAlien »

Interesting - next VS comes with CMake support: https://blogs.msdn.microsoft.com/vcblog ... rc-update/
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: CMake build script

Post by REDDemon »

Best new of the year. No vs understand cmake and open it Like a project! :)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Ragora
Posts: 4
Joined: Sun Aug 30, 2015 6:32 pm
Location: Pennsylvania, United States
Contact:

Re: CMake build script

Post by Ragora »

I actually ended up making one myself that supports the examples too, and not by including a CMake script for each one (at least explicitly). Though it also supports properly finding dependent libraries and can be used to configure Irrlicht all the way through the same way IrrCompileConfig.h can. It also fixes linking problems I've had with SDL when using the SDL driver because it conditionally links in SDL for the built libraries as well as everything else.

However mine is mostly an experimental result after a handful of hours of experimenting and it still needs work and I only just now noticed there was already something in progress for Irrlicht supporting CMake. It also makes changes to IrrCompileConfig.h because of redeclaration problems it will run into otherwise.

I've mostly only tested on my Linux machine but it should mostly work on Windows, aside from not finding the DirectX SDK explicitly but that might not be necessary on Visual Studio.

I noticed I don't seem to be able to attach an archive, so I hope this link is fine:
https://dx.no-ip.org/bits/IrrlichtCMake.tar.gz

Just extract over a fresh Irrlicht 1.8.4 codebase and it should work. The examples will fail to build unless you tell it where the Irrlicht includes/library is so you can use:

Code: Select all

-DIRRLICHT_LIBRARIES="/path/to/library" -DIRRLICHT_INCLUDES="/path/to/includes"
Or use the CMake GUI to do it. On Linux, if you have an Irrlicht library installed, it will find that one and use it.

Script overview:
  1. Default configuration mirrors what's in IrrCompileConfig.h by default (just generate a config with CMake without changing anything and the output should be equivalent to a non-CMake Irrlicht build. However, see #5 in the section below)
  2. Allows for full configuration of Irrlicht just as IrrCompileConfig.h does (unless I overlooked something) by using CMake's definition generator in a programmatic fashion
  3. Searches for appropriate external libraries where appropriate (SDL, Xf86VidMode, etc) which also allows it to report more user friendly errors when stuff isn't found
  4. Conditionally links libraries to avoid later linking problems (like when enabling the SDL driver)
  5. Coexists with the existing project files while still allowing for project file generation that CMake supports (though it will generate similar example project file names for each example, where the difference is ##.<name>)
  6. Auto generates CMake files for the examples to cut down in duplication (since these are all pretty much the same)
  7. The quality setting for BurningsVideo can be adjusted using a friendly string name (use -DBURNINGSVIDEO_RENDERER_QUALITY="BEAUTIFUL|FAST|ULTRA_FAST|CE")
  8. Example project files behave in the same way as the old projects did (you can build individual projects or build them all in one go using the root cmake script), through #6
  9. Can generate shared or static libraries (generate static libraries with -D_IRR_STATIC_LIB_=ON)
What it doesn't do (or should have done to it) right now:
  1. Setup output directories at all, it just spits out the main library next to the root CMakeLists.txt right now (example executables get put in the same place they would when not using my CMake script)
  2. Some cleaning up of the root CMakeLists.txt, I always found CMake scripts to be an insane clusterfuck.
  3. Testing on more platforms (I've only tested on Linux Mint thus far)
  4. Have a developer review the IrrCompileConfig.h to see if the changes are to their liking (the changes I've made are necessary for a fully capable CMake configuration because of redeclaration/overwriting problems)
  5. Fix linker errors associated with using the prepackaged libpng, libjpeg, etc libraries. (currently worked around with -D_IRR_USE_NON_SYSTEM_BZLIB_=OFF -D_IRR_USE_NON_SYSTEM_JPEG_LIB_=OFF -D_IRR_USE_NON_SYSTEM_LIB_PNG_=OFF)
  6. Review the root CMakeLists.txt to ensure all settings behave as intended
Credits to Olof Naessen for the FindIrrlicht.cmake script I used when building the examples (examples/cmake/FindIrrlicht.cmake).

If some other host is preferred, just ask.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CMake build script

Post by CuteAlien »

Nice, thanks for sharing!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ragora
Posts: 4
Joined: Sun Aug 30, 2015 6:32 pm
Location: Pennsylvania, United States
Contact:

Re: CMake build script

Post by Ragora »

CuteAlien wrote:Nice, thanks for sharing!
I've updated the script and crossed off #1 and #5 above in the 'todo list' and also added install rules so "make install" works on Unix-like systems. So now the archive should be able to be extracted on top of Irrlicht and built + installed with: cmake . && make -j8 && sudo make install. With this CMake system installed, Irrlicht should still be able to be compiled without using the script (So the normal project files and makefile should still work).

For #1, it will attempt to auto-detect your build environment and output everything to the corresponding directories as you would get without the Cmake script. So Windows with GCC will output to Win32-gcc and Windows with VS64 will output to visualStudio-64bit. This applies to both the library file itself and all example applications.

For #5, it removes test/application/unused source files from the project (not your file system) to allow the library to build as intended.

As mentioned above, it is a very comprehensive script but I still haven't tested it on anything aside from Linux Mint (I have code paths for OSX and Windows, I just haven't had a chance to try it yet as I don't run anything but Linux here).

Also as a thing aside, I feel like I slightly hijacked the thread. Should I move this elsewhere or?
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CMake build script

Post by CuteAlien »

Your posts fit the thread very well I think, so let's keep it here.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply