CMake is a cross-platform, open-source meta build system to build, test and package software. It creates Makefile or other build files (KDevelop, Eclipse). The intention is to test it if people like it and if we could replace the current build system with CMake.
Lets start to do a checkout and compile something. Run some commands and then come back and talk about the features.
$ git clone git://gitorious.org/samba-wip/samba-wip.git $ cd samba-wip $ git checkout -b cmake origin/cmake $ cd lib/talloc
CMake is designed to build out of the source. This has several advantages. You don't have to create thousand of entries in .gitignore. You can create a build directory for *every local git branch* you create. CMake can be invoked by differnet executables:
- cmake: the commandline tool
- ccmake: a ncurses based gui
- cmake-gui: a Qt gui.
$ mkdir build $ cd build $ cmake ..
This is a talloc stand alone build. Normally you have to copy libreplace in the talloc dir but there is a check to look for ../replace, if you're in the Samba tree. It does all the required configure checks here to build on Linux as this is just a test.
I think you know what it does. What's nice it shows only what it's building and the warnings and errors. If you want to see how make/cmake invokes the compiler, try the following:
$ make clean $ make VERBOSE=1
To see what targets are availalbe, you can use
$ make help
If you go to a source directory you have a target for each .c file.
$ cd replace $ make help $ cd ..
You can execute every binary in the build directory and it will work. CMake uses rpath to build executables so that test scripts are able to find the right libraries, and things like make test can be run from the build directory without requiring you to install or build everything statis. Executables are re-linked at install time to remove the rpath restriction. See:
$ ldd talloc_testsuite
This option can be completely disabled.
TODO: elaborate on rpath how you can disable that and what will happen if you do.
Advantages of CMake as a list
- Out of source build
- Automatic dependency generation (parallel builds)
- Build system in *one* language
- Good documentation (man cmake)
- Works on a lot of different machines and operating systems -> http://www.cdash.org/CDash/index.php?project=CMake
- Complex custom commands: qt moc, yacc, pidl!
- Reuns itself if one of the input files has changed