CMake Performance Tips

From KitwarePublic
Revision as of 09:25, 1 August 2007 by Alex (Talk | contribs)

Jump to: navigation, search

While CMake itself is already very fast, there are some things you can do to ensure works as fast as possible.

Build it with optimization enabled

Ok, this is obvious, but anyway. Let's say you build CMake yourself without any special settings, e.g.

$ cmake ..
$ make

If you do it this way, you will get a CMake with optimizations turned off. There are different ways to get an optimized build. You can select one of the predefined build types:

$ cmake -DCMAKE_BUILD_TYPE=RELEASE ..
$ make

Also possible are RELWITHDEBINFO and MINSIZEREL.

or

$ export CXXFLAGS=-O2
$ cmake ..
$ make

or

$ export CXXFLAGS=-O2
$ cmake ..
$ make edit_cache (or ccmake ..)
... edit CMAKE_CXX_FLAGS in the advanced view
$ make

CMake built with optimizations enabled can give you an almost 50% performance boost (time for running CMake on VTK went down from 25 s to 14 s).

Use LIST(APPEND ...)

There are two ways to append values to a variable in CMake:

  SET(myVar ${myVar} newItem)

and since CMake 2.4 there is the new LIST() command:

  LIST(APPEND myVar newItem)
</pre

LIST(APPEND ...) is for large lists and many appends much faster than the method using SET().