CMake vs Premake

Started by
5 comments, last by 3DModelerMan 12 years, 4 months ago
I'm trying to decide what build system to use. I want to be able to just create one CMake or Premake project file and generate the project files/solutions for Microsoft Visual C++ 2010/2008, and Code::Blocks. I might also need to generate XCode projects, and possibly kDevelop. Which one is easier to use? And also, do either support custom build steps like batch files?
Advertisement
Well, I've never heard of Premake, but CMake is widely used (for example, by the entire KDE project). Some people swear by it (and others at it, you know the drill).

I know CMake is extensible. Adding platform-specific things like batch files might just defeat the purpose of a cross-platform build, but I'm pretty sure you can add "if windows do this..." type constructs to the CMakeFile.txt so yeah, that's possible.

Stephen M. Webb
Professional Free Software Developer

I haven't used CMake so can't really comment on it.

As for Premake I have found it quite easy to use and setting up scripts is quite easy using their documentation. If you have any Lua experience then the scripting will be even easier for you as it's based on that. I haven't needed to run custom build steps as I'm only using it to build fairly simple solutions/projects. There is however the "if win { do something }" constructs from which you could then extend Premake to launch a batch script.
I've not used Premake, but I like the sounds of it -- it uses Lua for it's project scripts, whereas CMake uses it's own internal scripting language (which is simple to learn, but still, it's not Lua!).

I really love CMake, but it did have a bit of a learning curve in getting the projects scripts set up the way I wanted them. I actually found it easiest to get started by copying another project's build files wink.gif
After getting past the initial learning curve, I find it pretty easy to use and quite powerful -- I've got CMake set up to produce a VS2008 solution containing multiple libraries and EXEs in three configurations (debug, development, retail, each with different compiler options/defines). Some of the EXEs are unit-tests, which have post-build steps that run the EXE (printing unit test failures to MSVC's build output window) as part of a regular build.
The cmake script files show up in MSVC's file tree, so It's pretty easy to add new files to the project, and whenever the project files are changed, your solution will be re-generated next time you hit the build button.
Also, I've got some simple CMake macros set up to organise files in the MSVC file tree -- e.g. I can easily say: any files in "[font="Lucida Console"][size="1"]./include/foo/bar[/font]" or "[font="Lucida Console"][size="1"]./source/foo/bar[/font]" inside the "Foo" project should be grouped under a folder named "Bar".
I'm a happy user of CMake.
And it has a lot of happy user I think. :-)

However, it's unhappy to start with CMake.
The syntax is really horrible.
But after you get used with it, you will be happy with it.

Now whenever I add new unit test file, I don't tell CMake about that, and it will find it automatically, it really saves my time.

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.

cmake's scripting language is no lua and can be rather cumbersome at times, but despite of this cmake is actually easy to use. For instance, I found it much easier to do complicated stuff with cmake (such as generating correct dependencies for a code generation tool built as part of a project and used later during the build) than with scons despite that the later uses python as its scripting language. I never used premake though, so I don't know how it compares with cmake, but since the later is widely used it is probably supported better all around. For instance you have good chances to find a cmake module somewhere for every major library.

As for custom build steps not only does it support them but you can usually do it all using cmake's own language instead of having to rely on platform specific scripts such as .bat or .sh scripts. cmake also have some nice goodies such as the ability to generate platform specific installation packages from generic installation rules located throughout the cmake files. It can generate nsis installers on windows, debian / rpm / self-extracting tarballs on linux, etc.

You can of course also have platform specific code in your build files, that's also supported. Overall cmake is a very complete multiplatform build system, at least for C++.

As for kdevelop, if you use kdevelop4 you can directly import the top level cmakelists.txt file as a project.
I ended up just downloading both and trying them out to see which one I liked best. I ended up going with premake because I'm familiar with Lua.

This topic is closed to new replies.

Advertisement