diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 19728920..f7a2d400 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -46,6 +46,13 @@ set(CURRENT_CPM_VERSION 1.0.0-development-version) get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH) if(CPM_DIRECTORY) + if(${CMAKE_VERSION} VERSION_LESS "3.17.0") + get_directory_property(hasParent PARENT_DIRECTORY) + if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY OR ${hasParent}) + include(FetchContent) + endif() + endif() + if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY) if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION) message( @@ -56,9 +63,6 @@ It is recommended to upgrade CPM to the most recent version. \ See https://github.com/cpm-cmake/CPM.cmake for more information." ) endif() - if(${CMAKE_VERSION} VERSION_LESS "3.17.0") - include(FetchContent) - endif() return() endif()