CMake Basics


CMake manages the building and compiling of the complex set of codes and libraries that make up Dakota.

CMake uses two separate directories. In these pages the source directory is referred to as DAK_SRC; the build directory, DAK_BUILD. The source directory contains the Dakota source code and the cmake files. The user creates the build directory and builds from that directory. It is initially empty; it will be filled with the Dakota executable, libraries, packages and examples.

Use a CMake Script

The CMake build process has a number of configurable settings. These can be written in a file (referred to as build file here) or specified on the command line when calling cmake. The directory $DAK_SRC/cmake contains a collection of build files. There are platform specific files such as BuildRHEL5.cmake, Build_win_msvc_ifort.cmake, BuildCygwin.cmake and a template file, BuildDakotaTemplate.cmake.

Some common settings are:

  • specify the folder where the Dakota binaries will be installed
  • build without MPI
  • build with MPI and tell cmake where to find the relevant MPI files

Simple Build File Example

The most commonly used CMake variables are specified in the build file BuildDakotaTemplate.cmake. See Using BuildDakotaTemplate.cmake Script for a description of the variables and instructions for use. Once you have customized this script for your platform, run the CMake script as follows:

mkdir build 
cd build
cp ../cmake/BuildDakotaTemplate.cmake BuildDakota.cmake

# Make changes to BuildDakota.cmake for your platform (see link above)
# Once your script correctly builds Dakota, save it in a more permanent location for 
# later reuse.
# Configure the build tree
cmake -C BuildDakota.cmake DAK_SRC

Use Command line Options

Simple Command Line Example

mkdir build 
cd build

# Configure the build tree.
 -DCMAKE_INSTALL_PREFIX=/home/myFavoriteUser/dakota \

In this example the following settings are used:

  • -DCMAKE_INSTALL_PREFIX tells CMake where to install the Dakota executables, libraries and examples
  • -DDAKOTA_HAVE_MPI:BOOL=TRUE tells CMake to build with MPI to allow for parallel processing
  • -DCMAKE_CXX_COMPILER:FILEPATH tells CMake where the MPI compilers are
  • -DMPI_LIBRARY:FILEPATH tells CMake where the MPI libraries are

What Next?

If the CMake options in the BuildDakotaTemplate.cmake script are not sufficient, check out the Detailed CMake Options section. Or read example instructions for your platform.