GitHunt
SC

scivision/cmakeutils

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

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

Clean CMake build directories under root directory

CMake build directories might take 100s of MBs each for large projects.
To clean (optionally recursively) all CMake build directories under a root directory use:

uv run cmake_clean_build_dirs.py <root_dir> [--recursive] [--dryrun]

convert CMake hierarchy .dot to SVG or PNG

CMake plots
dependency graphs
with a small CMake script:

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

Then convert to PNG or SVG like:

python cmake_dependency_graph.py ~/myprog/graphviz

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

cmake -Dhtml=~/myprog/graphviz/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.

Languages

CMake74.9%Python12.2%Shell5.2%C++4.6%C1.6%Fortran1.5%

Contributors

MIT License
Created October 18, 2018
Updated March 9, 2026