This is an old revision of the document!
Table of Contents
CMake tutorial
CMake is a cross-platform build system with many nice features. It generates platform specific build files, such as Makefiles or Visual Studio project files during configuration.
It supports multiple targets, e.g. out-of-tree configurations and builds (simply configure from multiple build directories).
Developers
To add new files to be compiled, you will need to edit one of the following files
oofem/src/oofemlib/CMakeLists.txt oofem/src/sm/CMakeLists.txt oofem/src/fm/CMakeLists.txt oofem/src/tm/CMakeLists.txt
Add new files to new lines which makes it less likely to conflict when merging code in git.
set (oofemlib_element element.C structuralelement.C nlstructuralelement.C my_new_element.C )
For more complex additions that require new configuration options, you will need to modify CMakeLists.txt in the root directory
oofem/CMakeLists.txt
If new tests files are added CMake will find them automatically, just re-run cmake from the build directory.
Linux
Install CMake from the package system of your choice. Create a out-of-tree build directory
mkdir -p ~/build/debug/ cd ~/build/debug/ cmake ~/oofem/ make ctest
Instead of cmake
can use ccmake
which uses an ncurses interface, or cmake-gui
for a GUI.
Use the command make help
for a list of all targets.
To make configuration options, either use the cmake
, cmake-gui
or supply additional commands directly
cmake -DCMAKE_CXX_FLAGS="-Werror" ~/oofem/
In order to use a different compiler you need to start a new clean configuration (from an empty directory) and supply the new compiler using -DCMAKE_CXX_COMPILER
mkdir -p ~/build/clang/ cd ~/build/clang/ cmake -DCMAKE_CXX_COMPILER=clang++ ~/oofem/ make ctest
Note: After initial configuration, you cannot change compiler. If you install a new version of GCC, you will need to remove the build directory and do the configuration again. Just doing make clean
isn't enough.
CTest
Some useful options for ctest include running the tests in parallel;
ctest -j 4
and regex search for limiting the tests you wish to check (the following example runs cemhyd01.in and cemhyd02.in)
ctest -R cemhyd
and lastly a verbose option to see what went wrong
ctest -V
CPack
CPack allows you to make source and binary releases. You will first need to configure using cmake
(as detailed above). The following commands are executed from the build directory.
To generate a source package (which excludes .git/ and generated files) run
make source_package
To generate a DEB, RPM, ZIP binary packages of your currently configured directory, run
cpack -G DEB cpack -G RPM cpack -G ZIP ...
KDevelop
The KDevelop IDE has build in support for CMake projects (and GIT). It includes a graphical configuration of multiple targets. Simply choose to import a project, and select CMakeLists.txt from the source directory You can then open the configuration from the menu and make your choices:
Windows (Visual Studio)
- Install CMake
- Start CMake, select the source directory, and then select a new directory for the build.
- Press configure, select your options, configure again
- Press generate to produce project files for VS.
To run the test suite, open the solution explorer in VS and “build” the test
target to run through the test suite.
Note: The build types (debug, release) are handled internally by Visual Studio, so no configuration option for this is presented in CMake Note: PETSc isn't easily built on windows, so support for parallel builds is still lacking