Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 17 (modified by rgrieder, 16 years ago) (diff)

TracNav(TracNav/TOC_Development)?

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.

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

Sometime it happens, that CMake won't accept the new setting you added some where 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 with KDevelop

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

$ cmake .. -GKDevelop3

Optimize KDevelop

Do some configursation to make the usage of KDevelop smoother

Go to Project->Project Option->Build Option->Make, and do the following changes

  • Select Run Multiple Jobs, and set Number of Simultaneous Jobs to 3
  • set Make Prority to 5
  • Optional: Add Environment Variables
    • i.e Name: CXXFLAGS; Value: -O2 -pipe
    • CXXFLAGS or LDFLAGS are also possible. In fact any compiler flags can be set here
      If you don't know what CFLAGS are, don't set them, otherwise use at you own discretion. Only reasonable flags will be supported

Go to Project->Project Option->Run Option

  • Working Directory: just add /bin you still need to run ./run-script the first time

Debug CMake paths

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

$ cmake -L ..