diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 56f856a5..a519ff4f 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -611,18 +611,15 @@ function(CPMAddPackage) return() endif() - # Check for ENV overide for local package-source when not already defined. NOTE: Uses a recursive - # CPMAddPackage call where `CPM_${CPM_ARGS_NAME}_SOURCE` == "" which causes first if-case to stop - # recusrion - if(CPM_${CPM_ARGS_NAME}_SOURCE) - file(TO_CMAKE_PATH "${CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE) - elseif(DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) - file(TO_CMAKE_PATH "$ENV{CPM_${CPM_ARGS_NAME}_SOURCE}" PACKAGE_SOURCE) + # @TODO Allow this as from a user-extension point for locating package source e.g. Check for ENV overide for local package-source + if(NOT DEFINED CPM_${CPM_ARGS_NAME}_SOURCE AND DEFINED ENV{CPM_${CPM_ARGS_NAME}_SOURCE}) + file(TO_CMAKE_PATH $ENV{CPM_${CPM_ARGS_NAME}_SOURCE} CPM_${CPM_ARGS_NAME}_SOURCE) endif() # Check for manual overrides - if(NOT CPM_ARGS_FORCE AND NOT "${PACKAGE_SOURCE}" STREQUAL "") - set(CPM_${CPM_ARGS_NAME}_SOURCE "") # Assign empty to prevent recursion + if(NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "") + set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE}) + set(CPM_${CPM_ARGS_NAME}_SOURCE "") CPMAddPackage( NAME "${CPM_ARGS_NAME}" SOURCE_DIR "${PACKAGE_SOURCE}"