CMake

extern links: |- back -|- index -|- home -|

in page: preamble using linux examples windows end

Preamble - http://www.cmake.org/

2011-09-13: Since Simgear and FlightGear are switching over to use Cmake, it seems a GOOD time to update this page, especially since the last was 2008! ;=)). Remember, this page is only my personal usage, and in no way represents a definitive manual on it usage. Use the CMake site for that...

As their home page says CMake is a 'cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.'


top

Using CMake

Unix/Linux

There is a GUI version, a frontend using wxWidgets, called cmake-gui, but like all things linux, I use the command line version, 'cmake'. To me the problem with the GUI is that it 'hides' so much. It is just a 'frontend', but it does not exactly show you what 'commands' it passed to 'cmake' to configure and build the binaries. Maybe there is a way to do this, but I have NOT found it yet ;=((

CMake changes the 'standard' mantra of
'$ ./configure [options] && make && make install' to
'$ cmake [options] $srcdir && make && make install',
so you can see the CMake tool takes over the automake tools 'configure' step.

And 'cmake', like the 'configure' automake step, is where various 'configurations', or 'options' can be added.

Say for example, you have the 'Boost' headers installed in other than '/usr/include', then a parameter like '-D CMAKE_CXX_FLAGS=-I/my/dir/to/includes' must be added. The CMake wiki page gives a list - http://www.cmake.org/Wiki/CMake_Useful_Variables - Most, if not all these 'variables' can also be used the the actual CMake build files.

As well, or alternatively, CMake searches its module path for special 'find' scripts, which are named Find${PACKAGE}.cmake, and additional include header or libraries NOT install in the standard paths can be search through these...

And for example, to build a Debug version with -
$ cmake . -D CMAKE_BUILD_TYPE="Debug"
Other options here are 'Release', 'RelWithDebInfo', and 'MinSizeRel';

Or you can run it in interactive mode, which you start by typing -
$ cmake . -i
There is a large list of options to check out ;=))

CMake depends on a specific file 'CMakeLists.txt' to give it instructions concerning the source, but this brief outline does not include any help on building this/these files. You can get that information from the CMake site...

After running 'cmake', and checking everything desired was found - sometime you need to install other things, and run cmake again, and/or there were no CMake errors - these MUST be fixed before it will generate the actual Makefiles, then it is back to the 'standard' mantra of
'make && [sudo] make install'.

Rather than showing the actual 'gcc' compile and link lines, usually you only get a '[percent] Building CXX object <objects name>' output, which is fine if everything runs without errors. But to see MORE information, either turn on '-D CMAKE_VERBOSE_MAKEFILE=TRUE' or '-D CMAKE_VERBOSE_MAKEFILE="1", or 'make' can be run with 'VERBOSE=1' - then the actual 'gcc/g++' command lines can be checked.


top

Some examples

When building OpenSceneGraph in Ubuntu I use -

$ cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_FLAGS=-03 \
-D CMAKE_C_FLAGS=-03 \
-D LIB_POSTFIX= \
-D CMAKE_INSTALL_PREFIX:PATH=$INSTALL_DIR_OSG

In a recent FlightGear developers discussions, Mathias shared some of his SG/FG build script -

export CFLAGS= ...
export CXXFLAGS= ...
cmake \
-D CMAKE_BUILD_TYPE="RELWITHDEBINFO" \
-D CMAKE_DEBUG_POSTFIX="" \
-D CMAKE_MINSIZEREL_POSTFIX="" \
-D CMAKE_RELEASE_POSTFIX="" \
-D CMAKE_RELWITHDEBINFO_POSTFIX="" \
-D CMAKE_VERBOSE_MAKEFILE=TRUE \
-D CMAKE_INSTALL_PREFIX=$prefix \
-D ENABLE_RTI="ON" \
$srcdir

***TBD*** Add other examples


top

Windows

Again, while there is a command line version, here I prefer the GUI version.

CMake start - 02

It should be noted in this image I have adjust the CXX_FLAGS to use /MT, and /MTd. The DEFAULT is /MD, and /MDd. And further down the list I have unchecked DYNAMIC_OPENSCENEGRAPH and DYNAMIC_OPENTHREADS, to build only 'static' libraries, instead of the usual DLL build.

Also, note that [x] Advanced is checked, else some of these 'options' will not be shown. And specifically for building OSG for SG/FG I provide the path to the includes, and the libraries for PNG_PNG_INCLUDE_DIR, PNG_LIBRARY, ZLIB_INCLUDE_DIR, and ZLIB_LIBRARY, since it is necessary to 'include' these built-ins or 'extensions' to link with SG/FG...

After [ Configure ] is pressed most of these RED entries will become 'normal', and any remaining RED entries must be resolved before the final step of [ Generate ] is pressed.

If [ Generate ] runs without error, a quite large set of MSVC, MSVC8 in this case, build files will be generated, ready to run MSVC to do the build.

***TBD*** More to be added...


top

checked by tidy  Valid HTML 4.01 Transitional

Old CMake version 2.6

CMake start - 01


top