Modern CMake Modules

29 Jan 2022

[ cmake  c++  development  ]

CMakeLists.txt Notes

Pragmatic Recommendations

CMake Workflow

Module walktrough

PlanetExpress.cmake

FindPlanetExpress.cmake

PlanetExpressConfig.cmake or planet-express-config.cmake

Essential for CMake modules

API documentation

Testing

Printing messages

Installing a CMake module

CMakeLists.txt for CMake modules

cmake_minimum_required(VERSION 3.21)
project(cmake-planet-express LANGUAGES NONE)
enable_testing()
   
install(
  FILES PlanetExpressConfig.cmake
  DESTINATION share/cmake/PlanetExpress
  COMPONENT cmake-planet-express
)

Development Setup

export CMAKE_GENERATOR=Ninja
export CMAKE_TOOLCHAIN_FILE=path/to/Toolchain.cmake
export CMAKE_BUILD_TYPE=Debug
export DESTDIR=your/staging/dir

Development Workflow

git clone https://<host>/cmake-planet-express.git
cmake -B build -S cmake-planet-express
cmake --build build
ctest --test-dir build
cmake --install build --prefix /opt/myorg --component cmake-build-express

Integration Workflow

git clone https://<host>/cxx-project.git
cmake -B cxx-build -S cxx-project -DPlanetExpress_DIR-./cmake-planet-express
cmake --build cxx-build
ctest --ctest-dir cxx-build
cmake --install cxx-build --prefix /opt/myorg --component cxx-project

Modern CMake less briefly

Reference