@@ -286,6 +286,8 @@ function(CPMAddPackage)
286286 endif ()
287287 endif ()
288288
289+ set (CPM_SKIP_FETCH FALSE )
290+
289291 if (DEFINED CPM_ARGS_GIT_TAG)
290292 list (APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG} )
291293 # If GIT_SHALLOW is explicitly specified, honor the value.
@@ -374,9 +376,15 @@ function(CPMAddPackage)
374376 set (download_directory ${CPM_SOURCE_CACHE} /${lower_case_name} /${origin_hash} )
375377 list (APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory} )
376378 if (EXISTS ${download_directory} )
377- # disable the download command to allow offline builds
378- list (APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND "${CMAKE_COMMAND} " )
379- set (PACKAGE_INFO "${download_directory} " )
379+ # avoid FetchContent modules to improve performance
380+ set (${CPM_ARGS_NAME} _BINARY_DIR ${CMAKE_BINARY_DIR} /_deps/${lower_case_name} -build )
381+ set (${CPM_ARGS_NAME} _ADDED YES )
382+ set (${CPM_ARGS_NAME} _SOURCE_DIR ${download_directory} )
383+ if (NOT CPM_ARGS_DOWNLOAD_ONLY AND EXISTS ${download_directory} /CMakeLists.txt)
384+ add_subdirectory (${download_directory} ${${CPM_ARGS_NAME} _BINARY_DIR})
385+ endif ()
386+ set (CPM_SKIP_FETCH TRUE )
387+ set (PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory} " )
380388 else ()
381389 # Enable shallow clone when GIT_TAG is not a commit hash. Our guess may not be accurate, but
382390 # it should guarantee no commit hash get mis-detected.
@@ -389,7 +397,7 @@ function(CPMAddPackage)
389397
390398 # remove timestamps so CMake will re-download the dependency
391399 file (REMOVE_RECURSE ${CMAKE_BINARY_DIR} /_deps/${lower_case_name} -subbuild)
392- set (PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory} " )
400+ set (PACKAGE_INFO "${PACKAGE_INFO} to ${download_directory} " )
393401 endif ()
394402 endif ()
395403
@@ -405,11 +413,17 @@ function(CPMAddPackage)
405413 endif ()
406414 endif ()
407415
408- cpm_declare_fetch (
409- "${CPM_ARGS_NAME} " " ${CPM_ARGS_VERSION} " " ${PACKAGE_INFO} " " ${CPM_ARGS_UNPARSED_ARGUMENTS} "
416+ message (
417+ STATUS "${CPM_INDENT} adding package ${CPM_ARGS_NAME} @ ${CPM_ARGS_VERSION} ( ${PACKAGE_INFO} ) "
410418 )
411- cpm_fetch_package("${CPM_ARGS_NAME} " "${DOWNLOAD_ONLY} " )
412- cpm_get_fetch_properties("${CPM_ARGS_NAME} " )
419+
420+ if (NOT CPM_SKIP_FETCH)
421+ cpm_declare_fetch(
422+ "${CPM_ARGS_NAME} " "${CPM_ARGS_VERSION} " "${PACKAGE_INFO} " "${CPM_ARGS_UNPARSED_ARGUMENTS} "
423+ )
424+ cpm_fetch_package("${CPM_ARGS_NAME} " "${DOWNLOAD_ONLY} " )
425+ cpm_get_fetch_properties("${CPM_ARGS_NAME} " )
426+ endif ()
413427
414428 set (${CPM_ARGS_NAME} _ADDED YES )
415429 cpm_export_variables("${CPM_ARGS_NAME} " )
@@ -503,8 +517,6 @@ endfunction()
503517
504518# declares a package in FetchContent_Declare
505519function (cpm_declare_fetch PACKAGE VERSION INFO)
506- message (STATUS "${CPM_INDENT} adding package ${PACKAGE} @${VERSION} (${INFO} )" )
507-
508520 if (${CPM_DRY_RUN} )
509521 message (STATUS "${CPM_INDENT} package not declared (dry run)" )
510522 return ()
0 commit comments