CMake Performance Tips

From KitwarePublic
Revision as of 14:03, 23 July 2007 by Alex (talk | contribs) (New page: 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. If ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to 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. If you build CMake yourself without any special settings, i.e.

$ 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=RELASE ..
$ 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)
</pre

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().