Skip to content

Downloading CPM.cmake in CMake

Lars Melchior edited this page Sep 18, 2023 · 16 revisions

As outlined in the README, there is more than one way to include CPM.cmake in your project. Instead of including the full get_cpm.cmake script as found in the releases, you can shrink it down to the essentials to easily include it in your main CMakeLists.txt.

[...]

# download CPM.cmake
file(
  DOWNLOAD
  https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
  EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

# add dependencies here
CPMAddPackage(...)

[...]

Note however, that using this short version requires an active internet connection on first configure, even when the CPM_SOURCE_CACHE is set and populated. To update the version of CPM.cmake that is included, update the version number in the url and SHA hash as found in the most recent release asset.