From 6e3e216156ed1b5cee27e03e5a8d29c1fe83b240 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 26 Jan 2020 18:53:24 +0100 Subject: [PATCH] Polyfill fetchcontent_makeAvailable for cmake < 3.14 --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 694b3701..d5faa4a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,32 @@ option(USE_BUNDLED_TWEENY "Use the bundled version of tweeny." list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +if(${CMAKE_VERSION} VERSION_LESS "3.14.0") + message("Adding FetchContent_MakeAvailable") + # from cmakes sources + macro(FetchContent_MakeAvailable) + + foreach(contentName IN ITEMS ${ARGV}) + string(TOLOWER ${contentName} contentNameLower) + FetchContent_GetProperties(${contentName}) + if(NOT ${contentNameLower}_POPULATED) + FetchContent_Populate(${contentName}) + + # Only try to call add_subdirectory() if the populated content + # can be treated that way. Protecting the call with the check + # allows this function to be used for projects that just want + # to ensure the content exists, such as to provide content at + # a known location. + if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt) + add_subdirectory(${${contentNameLower}_SOURCE_DIR} + ${${contentNameLower}_BINARY_DIR}) + endif() + endif() + endforeach() + + endmacro() +endif() + include(GNUInstallDirs) # Include Qt basic functions