Update 25.09.2015: I created a github project: https://github.com/ZahlGraf/IrrlichtCMake
All further updates will be released there.
Update: Here is the irrlicht 1.8.3 build system
(Nothing has changed in the CMake build system, except the version number)
Since I need to compile Irrlicht with several different compilers I created for the version 1.8.2 a CMake build system.
You can download it from here: irrlicht-1.8.2.zip
Just merge the directory "irrlicht-1.8.2" with the official download from Irrlicht. No file should be overwritten, it will just add CMakeLists.txt files to the main project, examples and tools and the CMake folder where all module-files are included.
I tried to bring the CMake system as close as possible to the Makefiles, so almost all compiler options should be the same.
What is CMake
CMake is a meta-build system, that generates all kind of different make-files or project-files. You just need to specify the make-system you want to use (gnu make, nmake, ninja mingw-makefiles, msys-makefiles) or an IDE you use (Eclipse project file, Visual Studio project file) and CMake will then generate all necessary files for that.
The big advantage - compared to single Makefiles and project files - is that you just need to maintain the files of CMake and you don't need to maintain all VC-project files and makefiles independently.
Of course you first need to understand how CMake works, but I was able to learn it very fast and I hope I wrote the CMake files in a way that they are easy to maintain.
From my point of view CMake is the only way to have a build-system that is compatible to any compiler and any operating system. I’m always happy when I download an open source project and see that is uses CMake for compiling.
What can this CMake-System do
With my CMake files you can compile the Library itself (as static or shared, debug or release version) and if you want, you can also compile all examples and tools with the same settings. You can start the compilation of "everything" just by entering one command to your shell.
I implemented the CMake-System for Windows, Unix Like systems and MacOSX. It should also support GCC (including MingW 32/64bit), Visual C++, Intel-Compiler (windows/linux) and CLang.
However:
Of course I was not able to test every compiler and operating system. The following tests have been done by myself:
- Windows 7, MSCV2015, 64bit
- Windows 7, Intel 16.0 Compiler (MSCV2015 front end), 64bit
- Windows 7, MinGW 32bit
- Windows 7, MinGW 64bit
File Description
In the Root, example and tools directory there is always a CMakeLists.txt file. In every directory where you can find such a file, you can start a build.
So when you start the build in the root directory, you can build the library, examples and tools.
When you start in the examples directory, you can build all examples (without library or tools) and of course you can just build one specific example by going into that example sub-directory.
In the CMake directory you can find different Module files, that should help to maintain the build system easily. These module files are included by the main CMakeLists.txt file.
- IrrlichtSource.cmake - contains a list of all source and header files for the Irrlicht library. When you add new file to the project, you must also add it here to the list. The source-files of the examples and tools, are stored in the CMakeLists.txt file of the corresponding subproject, since normally this is just a single file (main.cpp). But for the Irrlicht library there are so many files, that I think it is a good idea to have it in a dedicated module file.
- ExampleBuild.cmake - contains a subfunction for building examples or tools. So when you want to change anything for the examples only (other defines or compiler flags, you can add them here)
- IrrlichtVersion.cmake - contains the version number of the library (1.8.2)
- PrintSettings.cmake and WriteSettings.cmake - a module file, that prints/writes a summary of all settings, when you add new settings, you should add the variables also here.
- Compiler/*.cmake - The files in this directory contain specific settings for every supported compiler. At the moment just MSVC like compilers are supported (compilers that uses the front end and arguments of Visual C++ like Visual Studio and Intel Compiler on Windows) and GCC like compilers (compilers that uses the front-end and arguments of GCC, like MinGW, GCC, CLang, Intel on Linux)
- Dependencies/*.cmake - The files in this directory contain settings that belongs to dependencies like DirectX9 and OpenGL. These files decide if directx or opengl libraries are linked to Irrlicht or not. When you add new dependencies, you can add also new files here for the dependency related settings.
- OperatingSystems/*.cmake - The files in this directory contain settings that are specific to the operating system. (it seems, that MacOSX needs some other settings then Linux or Windows) These files also decide, if - depending on the operating system - specific libraries should be linked to Irrlicht or specific defines should be set.
- Option/*.cmake - I added some options to the build system like enabling profiling or build static library. The logic behind, and if necessary also the settings for those options are stored in the files in this directory.
- Packages/*.cmake - In this directory there are two files that are necessary to find the paths to the directx9 SDK. I did not implement those files, I just copied them from the Ogre3D project ( http://www.ogre3d.org/ ) - Of course the licence allows it and also a developer of the Ogre3D project allowed me to release these files together with the Irrlicht CMake build system.
- First of all make sure, that CMake is installed on your computer ( http://www.cmake.org/ )
- The CMake bin directory should be inside your PATH variable when you start your programming shell.
- Merge the files from my ZIP into your irrlicht 1.8.2 directory.
- Open your programming shell (like the one where you called “vcvarsall.bat amd64” for Visual C++ 64bit)
- Goto your Irrlicht directory.
- Enter in your shell “cmake-gui” (for experts there is also a command line tool without gui)
- On the top of the windows there is a text field “Where is the source code”. Be sure, that this is the path to the irrlicht-root directory (where the main CMakeLists.txt file is in)
- Below this line there is a text field “Where to build the binary”. Enter here any path you want, where the temporary files for the build process are stored in. For example <irrlicht-root-dir>/build-vc64/debug/shared (when you want to build the shared library in debug mode)
- Click on Configure. It asks you, if it should create the build path – click on “Yes” and then you can select the build-system you want to use. For Visual C++ you can use “NMake Makefiles” or you can create a Visual Studio Project file (I have not tested it so far, since my Visual Studio IDE is broken).
For MingW you can select MingW Makefile or MSYS-Makefile (I prefere MSYS-Makefile). For GCC on Linux just select Unix Makefile. - Below the build system selector you can select if you want to use default compiler or if you want to use a different compiler. For example for Intel Compiler on Windows, you select NMake Makefile and “Specify native compilers” where you can now specify the “ICL” command instead of the Visual C++ “CL” command for compiling. In this way you can also define a cross compiler, if necessary. For Visual C++, just select “use default native compiler” together with “NMake Makefiles”.
- After clicking on Finish, the system searches for the compiler binary and figures out where it can find OpenGL and DirectX. When you build the main project (Irrlicht Library) there should not be any Warning or Error. In the text window on the bottom, it should print a summary of your configuration and you should read the text “Configuration done”. In the middle part of the window, you will see a red list of variables, that have been changed in this configuration step.
- Edit the variables in the way you want. Make sure, that you set at least the following one:
- ”CMAKE_BUILD_TYPE = Debug” (or Release)
- ”CMAKE_INSTALL_PREFIX = <the path where you want to have the binaries and include files>” For example: example <irrlicht-root-dir>/install-vc64/debug/shared
- If you are happy with your configuration, click again on Configure. All variables should be white now, since they have not changed.
- Then click on Generate to generate the Makefiles.
- In the Shell Window go to the build path (<irrlicht-root-dir>/build-vc64/debug/shared – in my example) and enter “nmake install”. This will compile Irrlicht, the Examples and the Tools and afterwards it will install everything to the specified directory.
- Enjoy Irrlicht
GrafZahl