Debian Codegraph @

utf-8-validate/deps/is_utf8/cmake/import.cmake

raw
1 set(dep_root "${IS_UTF8_SOURCE_DIR}/dependencies/.cache")
2 if(DEFINED ENV{IS_UTF8_DEPENDENCY_CACHE_DIR})
3 set(dep_root "$ENV{IS_UTF8_DEPENDENCY_CACHE_DIR}")
4 endif()
5
6 function(import_dependency NAME GITHUB_REPO COMMIT)
7 message(STATUS "Importing ${NAME} (${GITHUB_REPO}@${COMMIT})")
8 set(target "${dep_root}/${NAME}")
9
10 # If the folder exists in the cache, then we assume that everything is as
11 # should be and do nothing
12 if(EXISTS "${target}")
13 set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE)
14 return()
15 endif()
16
17 set(zip_url "https://github.com/${GITHUB_REPO}/archive/${COMMIT}.zip")
18 set(archive "${dep_root}/archive.zip")
19 set(dest "${dep_root}/_extract")
20
21 file(DOWNLOAD "${zip_url}" "${archive}")
22 file(MAKE_DIRECTORY "${dest}")
23 execute_process(
24 WORKING_DIRECTORY "${dest}"
25 COMMAND "${CMAKE_COMMAND}" -E tar xf "${archive}")
26 file(REMOVE "${archive}")
27
28 # GitHub archives only ever have one folder component at the root, so this
29 # will always match that single folder
30 file(GLOB dir LIST_DIRECTORIES YES "${dest}/*")
31
32 file(RENAME "${dir}" "${target}")
33
34 set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE)
35 endfunction()
36
37 # Delegates to the dependency
38 macro(add_dependency NAME)
39 if(NOT DEFINED "${NAME}_SOURCE_DIR")
40 message(FATAL_ERROR "Missing ${NAME}_SOURCE_DIR variable")
41 endif()
42
43 add_subdirectory("${${NAME}_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/${NAME}")
44 endmacro()
45
46 function(set_off NAME)
47 set("${NAME}" OFF CACHE INTERNAL "")
48 endfunction()