Skip to content

Downloading CPM.cmake in CMake

Lars Melchior edited this page May 28, 2020 · 17 revisions

As outlined in the README, there is more than one way to include CPM.cmake in your project. In addition to using the command line, you can use CMake to download a specific release of CPM.cmake to your project and include it automatically.

set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")
set(CPM_VERSION 0.25)

if(NOT EXISTS ${CPM_DOWNLOAD_LOCATION})
  message(STATUS "Downloading CPM.cmake")
  file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif(NOT EXISTS ${CPM_DOWNLOAD_LOCATION})

include(${CPM_DOWNLOAD_LOCATION})

To update the version of CPM.cmake that is included, just update the CPM_VERSION variable with the correct version number, omitting the v prefix. Note that the CPM.cmake file at ${CMAKE_BINARY_DIR}/cmake/CPM.cmake must be deleted after updating, otherwise the file will not be re-downloaded.

Clone this wiki locally