/cmakeutils

Helpful scripts and modules for CMake, especially for scientific computing, HPC, and Fortran

Primary LanguageCMakeMIT LicenseMIT

CMake Utils

DOI ci

CMake is a powerful and easy to use build system for a wide variety of languages including:

It's important to use a recent CMake version to be effective and clean with CMake script. This can be done via the Python package described below, or from CMake >= 2.8.12 by:

cmake -P scripts/install_cmake.cmake

Ninja is recommended in general for use with CMake instead of Make:

cmake -P scripts/install_ninja.cmake

convert CMake hierarchy .dot to SVG or PNG

CMake plots dependency graphs for programs like:

cmake -B build --graphviz=gfx/block.dot

Then convert to PNG or SVG like:

python graph.py ~/myprog/gfx

Convert the resulting index.html with the SVGs to PDF like:

cmake -Dhtml=~/myprog/gfx/index.html -P html2pdf.cmake

CMake regular expressions

CMake regular expressions have a distinct syntax tied to the origins of CMake syntax in the late 1990s. The CMake regex syntax is not the same as Python, Perl, etc. We give a few examples under regex.

Using CMake to build Autotools projects

Examples of project using CMake ExternalProject are under scripts/mpi. This project can be invoked to build OpenMPI or MPICH (each are Autotools projects):

cmake -S scripts/mpi -B build --install-prefix=$HOME/openmpi

cmake --build build

or by convenience scripts build_openmpi.cmake or build_mpich.cmake.

Build CMake itself

To compile CMake from source:

cmake -S scripts/build_cmake -B build

cmake --build build

Requirements:

  • SSL library
  • C++ compiler
  • GNU Make or Ninja

Examples

  • Download with git using FetchContent
  • Download and extract ZIP
  • measure system parameters with CMake. Note Cygwin reports really small RAM and zero virtual memory.