set(CPM_DOWNLOAD_VERSION 0.34.0)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")
set(CPM_DOWNLOAD_LINK "https://raw.githubusercontent.com/cpm-cmake/CPM.cmake/v${CPM_DOWNLOAD_VERSION}/cmake/CPM.cmake")

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
    message(STATUS "Downloading CPM.cmake")
    message(STATUS "From: ${CPM_DOWNLOAD_LINK}")
    message(STATUS "To: ${CPM_DOWNLOAD_LOCATION}")
    file(DOWNLOAD ${CPM_DOWNLOAD_LINK} ${CPM_DOWNLOAD_LOCATION} STATUS DOWNLOAD_STATUS)
    list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
    list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE)
    if(${STATUS_CODE} EQUAL 0)
    message(STATUS "Download completed successfully!")
    else()
    message(FATAL_ERROR "Error occurred during download: ${ERROR_MESSAGE}")
    endif()
else()
    message(STATUS "Found CPM.cmake: ${CPM_DOWNLOAD_LOCATION}")
endif()

message(STATUS "Found CPM.cmake: ${CPM_DOWNLOAD_LOCATION}")
include(${CPM_DOWNLOAD_LOCATION})