1# Copyright 2018, 2019 Peter Dimov 2# Distributed under the Boost Software License, Version 1.0. 3# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 5if(NOT CMAKE_VERSION VERSION_LESS 3.10) 6 include_guard() 7endif() 8 9if(NOT COMMAND FetchContent_Populate) 10 11 if(CMAKE_VERSION VERSION_LESS 3.11) 12 13 message(STATUS "Fetching FetchContent.cmake") 14 15 file(DOWNLOAD 16 "https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent.cmake" 17 "${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake" 18 ) 19 20 file(DOWNLOAD 21 "https://gitlab.kitware.com/cmake/cmake/raw/v3.11.3/Modules/FetchContent/CMakeLists.cmake.in" 22 "${CMAKE_BINARY_DIR}/Modules/FetchContent/CMakeLists.cmake.in" 23 ) 24 25 include(${CMAKE_BINARY_DIR}/Modules/FetchContent.cmake) 26 27 else() 28 29 include(FetchContent) 30 31 endif() 32 33endif() 34 35function(boost_fetch) 36 37 cmake_parse_arguments(_ "EXCLUDE_FROM_ALL;NO_ADD_SUBDIR" "TAG" "" ${ARGN}) 38 39 if(NOT __UNPARSED_ARGUMENTS) 40 41 message(FATAL_ERROR "boost_fetch: missing required argument, repository name") 42 return() 43 44 endif() 45 46 list(GET __UNPARSED_ARGUMENTS 0 REPO) 47 list(REMOVE_AT __UNPARSED_ARGUMENTS 0) 48 49 if(__UNPARSED_ARGUMENTS) 50 51 message(AUTHOR_WARNING "boost_fetch: extra arguments ignored: ${__UNPARSED_ARGUMENTS}") 52 53 endif() 54 55 if(NOT __TAG) 56 57 set(__TAG master) 58 59 endif() 60 61 string(MAKE_C_IDENTIFIER ${REPO} NAME) 62 63 if(CMAKE_VERSION VERSION_LESS 3.6) 64 65 FetchContent_Declare(${NAME} QUIET GIT_REPOSITORY "https://github.com/${REPO}" GIT_TAG ${__TAG}) 66 67 else() 68 69 FetchContent_Declare(${NAME} QUIET GIT_REPOSITORY "https://github.com/${REPO}" GIT_TAG ${__TAG} GIT_SHALLOW 1) 70 71 endif() 72 73 FetchContent_GetProperties(${NAME}) 74 75 if(NOT ${NAME}_POPULATED) 76 77 message(STATUS "Fetching ${REPO}:${__TAG}") 78 79 FetchContent_Populate(${NAME}) 80 81 if(__NO_ADD_SUBDIR) 82 83 # Skip add_subdirectory 84 85 elseif(__EXCLUDE_FROM_ALL) 86 87 add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR} EXCLUDE_FROM_ALL) 88 89 else() 90 91 add_subdirectory(${${NAME}_SOURCE_DIR} ${${NAME}_BINARY_DIR}) 92 93 endif() 94 95 endif() 96 97endfunction(boost_fetch) 98