See also CMake wiki page on internal company wiki.
I've been trying to start using CMake for some things. It seems like it may be the best thing available, but some things make me cringe. These are just some random observations and links:
M-x unscreamify-cmake-bufferin CMake mode in Emacs
CMake is configured with a "CMakeLists.txt" file in each subdirectory.
Build can (probably should) be done "out-of-source". To start a build, do something like this:
# in top-level project directory mkdir build cd build ccmake .. # use interface to configure make
To build in-source, skip the "build" directory and run
"ccmake" is a Curses (console) UI for configuring a project. Use "cmake-gui" for a Qt4-based GUI, or "cmake" for non-interactive mode (variables can be defined with the "-D" option).
A common non-interactive build might look like this:
mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make make install #optional
Unlike qmake, CMake subdirectories inherit the environment of the parent directories.
Sometimes I use "glob" to get a list of files, rather than listing them each in the CMake file. For example:
file(GLOB SOURCES *.cpp)
If this is done, then CMake needs to be manually rerun when files are added or removed (or renamed). Just running "cmake .." from the build directory will retain all the settings from previous runs.
An alternative (that appears to be commonly used) is to list each file in the CMake file. That way, CMake automatically gets rerun when you run "make". Either way, something manually needs to be done, but this way is more explicit.
The KDE CMake Coding Style seems reasonable. In short:
See also cmake-lint.
It can be useful to look at existing find modules, but they are very inconsistent.
Relevant pages on the CMake wiki:
Module help may have stuff not in the online documentation. Examples:
cmake --help-module-list cmake --help-module CPack cmake --help-module CPackRPM
It's easy to use the
FindSubversion module, but then the revision number doesn't get updated until you re-run CMake. There are a few different ways to get around this.
Examples of creating a header containing the SVN version: http://stackoverflow.com/questions/3780667/use-cmake-to-get-build-time-svn-revision
For setting CPack variables, you can set
CPACK_PROJECT_CONFIG_FILE (something like
CPackOptions.cmake), which gets run once each build for each generator, but there are some gotchas. In particular, you don't have access to
CMAKE_... variables, so you may need to generate the CPack project config file from a ".in" using
configure_file. See http://cmake.3232098.n2.nabble.com/Automatically-add-a-revision-number-to-the-CPack-installer-name-td7356239.html.