cmake introduction
A short example project for the CMake build system
|
CMake is a convenient tool to manage the build process of software in a portable way. CMake can locate compilers, executables, files, and libraries, set up complicated library hierarchies, and help you to install your project. It also has integrated testing capabilities e.g. to automatically test whether new features of your project have broken older parts of the code.
CMake is used to control the software compilation process using simple platform and compiler independent configuration files. These files are always called CMakeLists.txt
and you usually have one per subdirectory. They are input text files that contain the project parameters and describe the flow control of the build process in simple CMake language. Speaking of which, the CMakeLists language is full-fledged programming language with variables, loops, conditional statements, function declarations etc.
CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice: Visual C++, Kdevelop3, Eclipse, XCode, makefiles (Unix, NMake, Borland, Watcom, MinGW, MSYS, Cygwin), Code::Blocks, etc. (call cmake --help
to see a list of available generators for your system).
You can find more information at these locations:
Interesting projects that use CMake:
This project contains a brief introduction to CMake by means of a simple example. We assume that you are working on the command line and use a UNIX-type system.
git clone https://lab.wias-berlin.de/liero/cxx-test-project/
).mkdir <BUILD_DIR>
. Change in to the build directory, i.e. cd <BUILD_DIR>
.cmake ..
(the two dots tell CMake to look for the top-level CMakelists.txt
in the parent directory). CMake now checks whether you have a working C++ and C compiler and tries to locate the LAPACK library.make
to start the compilation of the project.make doc
to build the documentation of the project. It can be found in the build directory in <BUILD_DIR>/documentation/html/index.html
make install
to install the compiled library, executable, and header files to the system. You can set the variable CMAKE_INSTALL_PREFIX
to a specific location when calling CMake in Step 4, e.g. cmake -DCMAKE_INSTALL_PREFIX=<PATH TO DIRECTORY> ..
. Otherwise the default directory is /usr/local/*
.make uninstall
.