CMake Performance Tips: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Replace content with link to new CMake community wiki)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
While CMake itself is already very fast, there are some things you can do to ensure works
{{CMake/Template/Moved}}
as fast as possible.


==Build it with optimization enabled==
This page has moved [https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Performance-Tips here].
 
Ok, this is obvious, but anyway. Let's say you build CMake yourself without any special settings, e.g.
<pre>
$ cmake ..
$ make
</pre>
 
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:
<pre>
$ cmake -DCMAKE_BUILD_TYPE=RELEASE ..
$ make
</pre>
Also possible are RELWITHDEBINFO and MINSIZEREL.
 
or
 
<pre>
$ export CXXFLAGS=-O2
$ cmake ..
$ make
</pre>
 
or
 
<pre>
$ export CXXFLAGS=-O2
$ cmake ..
$ make edit_cache (or ccmake ..)
... edit CMAKE_CXX_FLAGS in the advanced view
$ make
</pre>
 
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:
 
<pre>
  SET(myVar ${myVar} newItem)
</pre>
 
and since CMake 2.4 there is the new LIST() command:
 
<pre>
  LIST(APPEND myVar newItem)
</pre>
 
LIST(APPEND ...) is for large lists and many appends much faster than the method using SET().

Latest revision as of 15:41, 30 April 2018


The CMake community Wiki has moved to the Kitware GitLab Instance.

This page has moved here.