Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

CMake Build System

CMake is a build tool which creates Makefile for you. There are also additional generators for any kind of development environment like KDevelop or Code::Blocks or even Eclipse CDT 4.0.

Using CMake

If you only want to build Makefiles for use under linux it is very simple indeed. We recommend to build 'out-of-source', which means that the Makefiles will not pollute your source directory but be put in another folder. Simple create a new one like for instance 'build', switch to it and run 'cmake ..' (.. for subsequent path).

$ mkdir build
$ cd build
$ cmake ..

With those Makefiles, the project the can be built completely:

$ make -j3

The -j3 option is to use 3 parallel tasks to boost multi core systems. The rule is to use one more task than cores on your machine.

Rebuilding the CMakeCache

Sometimes it can happen that CMake won't accept the new setting you added somewhere in a CMakeLists.txt. As a workaround — I have not found a better solution yet — delete the the toplevel CMakeCache, and rebuild every Makefile.

$ cd <some/branch/or/trunk> && ./cmakeclearcache && cmake . 

Writing CMakeLists.txt

Just as an simple example for how to write a CMakeLists.txt.

# Put all your source files (not headers!) in a variable to be used later
SET( MYLIB_SRC_FILES
  some_soource.cc
  another_source.cc
)

# This adds the current directory to the listing of all directories to be
# searched when looking for a header file.
INCLUDE_DIRECOTRIES(.)

# Creates the actual library. ''shared'' is dynamic under windows.
ADD_LIBRARY(mylib shared ${MYLIB_SRC_FILES})

# Link library against others. You will have to use ''${VARNAME}'' with external ones.
TARGET_LINK_LIBRARIES(mylib ${OgreMain} myOtherLib)

Using CMake generated project files

CMake is capable of creating project files for various IDEs so it's easier to integrate the project into the IDE of your choice. The following sections give a quick overview of possible ways to generate these project files. We don't care which (or if any) IDE you use, but we strongly advise you to use one to write clean code quickly and to benefit from code completion and other benefits the IDE provides.

Using CMake with Eclipse

You can also use CMake to create project files for Eclipse CDT 4.0.

Note: Eclipse does not like your build directory being a sub directory of your source directory. In order to use Eclipse please create a build directory on the same level as your source directory.

To do that use following command (in source directory):

$ cd ~/orxonox/
$ ls
trunk
$ mkdir build
$ cd build
$ cmake ../trunk -G"Eclipse CDT4 - Unix Makefiles"

CMake now generated a fully working Eclipse project: Go to this site to learn how to import it.

Using CMake with KDevelop

CMake is capable of creating .kdevelop files, which are used as project files in KDevelop. To create them simply use the following command:

$ cmake .. -GKDevelop3

Go to this site to learn about optimizing KDevelop for your purposes.

Using CMake with Code::Blocks

CMake is capable of creating .cbp files for Code::Blocks. Create a Code::Blocks project by simply using the following command:

$ cmake .. -G"CodeBlocks - Unix Makefiles"

Please add details for Code::Blocks if you're using it to develop Orxonox

Debug CMake paths

If you want to look at the paths of a library, run CMake with verbose option:

$ cmake -L ..
Last modified 8 years ago Last modified on Apr 12, 2017, 11:52:25 PM