diff --git a/src/Index.cmake b/src/Index.cmake
index 4397d2c3f825f1e656cdadffc55514f471de2cd0..c7981de2639af3321cff93faf585402d825f29e6 100644
--- a/src/Index.cmake
+++ b/src/Index.cmake
@@ -5,10 +5,15 @@ include_guard ()
 include (${CMAKE_CURRENT_LIST_DIR}/InitProject.cmake)
 
 # Check for CPM
+# set (CPM_DOWNLOAD_VERSION 0.40.5)
+set(CPM_DOWNLOAD_VERSION 0.40.5)
 file (GLOB CPM_MODULE_LOCATIONS ${CMAKE_BINARY_DIR}/cmake/CPM*.cmake)
 
-if (NOT CPM_MODULE_LOCATIONS)
-	set (CPM_DOWNLOAD_VERSION 0.37.0)
+# get the version from the last element in the list
+list (GET CPM_MODULE_LOCATIONS -1 CPM_MODULE_LOCATION)
+string (REGEX REPLACE ".*CPM_([0-9]+\\.[0-9]+\\.[0-9]+)\\.cmake" "\\1" CPM_MODULE_VERSION ${CPM_MODULE_LOCATION})
+
+if (NOT CPM_MODULE_LOCATIONS OR CPM_MODULE_VERSION VERSION_LESS CPM_DOWNLOAD_VERSION)
 	set (CPM_MODULE_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
 
 	message (STATUS "Downloading CPM.cmake")