Qt with cmake

From qtnode

Jump to: navigation, search
Qt_with_cmake
* Qt3_with_cmake
* Qt4_with_cmake

cmake is a Makefile generator, that means it does not replace the "make" program (in contrast to e.g. scons).

Thus cmake is comparable to autotools (see Qt with autotools). However:

  • cmake also works on Windows
  • cmake is much easier to learn than autotools
  • cmake scripts are much easier to read than autotools scripts
  • cmake comes with many configure test macros built in
  • cmake comes with support for Qt and KDE

Contents

History: KDE4

cmake was one of the alternatives investigated by the KDE project to replace the usage of autotools for KDE4. SCons was chosen initially, but got dropped due to some inherent problems and currently (May 2006) it looks like cmake will be the default build system for KDE4. Since KDE is built upon Qt, it is logical that cmake support for both Qt and KDE will be very good once KDE4 is released. However Qt/KDE in cmake support already is very good right now.

Using cmake

When you have a cmake based project and just want to compile it, do the following:

cd project
mkdir build
cd build
cmake ..
make
make install

Or if you want to install to /home/foo/bar instead of the default install prefix:

cd project
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/home/foo/bar ..
make
make install

You can also use "ccmake" instead of "cmake". This will give you a more or less graphical tool to configure the application - a graphical window on windows and a text/menu based program on unix.

cmake for qt3/qt4

Installing files

Installing in cmake is very easy - to install the "qtproject" executable created above add this to the end of the CMakeLists.txt file:

install(TARGETS qtproject DESTINATION bin)

This will install to the "bin" subdirectory of CMAKE_INSTALL_PREFIX.

Instead of TARGETS you could also use FILES, which would allow you to install any random file that exists in the source directory.

For a complete reference of the install() macro, see the cmake documentation at http://www.cmake.org.

Configure tests

To be written

Personal tools