Debian Codegraph @

cmake/clone-repo.cmake

raw
1 # Checkout remote repository
2 macro(clone_repo name url tag)
3 string(TOLOWER ${name} name_lower)
4 string(TOUPPER ${name} name_upper)
5
6 if(NOT ${name_upper}_REPOSITORY)
7 set(${name_upper}_REPOSITORY ${url})
8 endif()
9 if(NOT ${name_upper}_TAG)
10 set(${name_upper}_TAG ${tag})
11 endif()
12
13 message(STATUS "Fetching ${name} ${${name_upper}_REPOSITORY} ${${name_upper}_TAG}")
14
15 # Check for FetchContent cmake support
16 if(${CMAKE_VERSION} VERSION_LESS "3.11")
17 message(FATAL_ERROR "CMake 3.11 required to fetch ${name}")
18 else()
19 include(FetchContent)
20
21 FetchContent_Declare(${name}
22 GIT_REPOSITORY ${${name_upper}_REPOSITORY}
23 GIT_TAG ${${name_upper}_TAG}
24 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/${name_lower})
25
26 FetchContent_GetProperties(${name} POPULATED ${name_lower}_POPULATED)
27
28 if(NOT ${name_lower}_POPULATED)
29 FetchContent_Populate(${name})
30 endif()
31
32 set(${name_upper}_SOURCE_DIR ${${name_lower}_SOURCE_DIR})
33 set(${name_upper}_BINARY_DIR ${${name_lower}_BINARY_DIR})
34 endif()
35 endmacro()