CMake packaging essentials

CMake can install relocatable packages with CPack or without CPack. Here we discuss creating CMake config-file packages without CPack, as CPack is merely added on to an existing CMake package. C and C++ programs generally use header files (.h or .hpp) that must be part of an installed package. Fortran programs likewise use module files (.mod) that must be installed.

A basic structure for a CMake project that can create a CMake config-file package is shown in cmake-package-install. The boilerplate code under cmake/ directory is only slightly modified between projects. For example, see h5fortran for more advanced example in cmake/install.cmake and cmake/