File: import.cmake

package info (click to toggle)
node-websocket 1.0.35%2B~cs11.0.30-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,132 kB
  • sloc: cpp: 5,584; javascript: 3,787; ansic: 107; makefile: 15; sh: 7
file content (48 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
set(dep_root "${IS_UTF8_SOURCE_DIR}/dependencies/.cache")
if(DEFINED ENV{IS_UTF8_DEPENDENCY_CACHE_DIR})
  set(dep_root "$ENV{IS_UTF8_DEPENDENCY_CACHE_DIR}")
endif()

function(import_dependency NAME GITHUB_REPO COMMIT)
  message(STATUS "Importing ${NAME} (${GITHUB_REPO}@${COMMIT})")
  set(target "${dep_root}/${NAME}")

  # If the folder exists in the cache, then we assume that everything is as
  # should be and do nothing
  if(EXISTS "${target}")
    set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE)
    return()
  endif()

  set(zip_url "https://github.com/${GITHUB_REPO}/archive/${COMMIT}.zip")
  set(archive "${dep_root}/archive.zip")
  set(dest "${dep_root}/_extract")

  file(DOWNLOAD "${zip_url}" "${archive}")
  file(MAKE_DIRECTORY "${dest}")
  execute_process(
          WORKING_DIRECTORY "${dest}"
          COMMAND "${CMAKE_COMMAND}" -E tar xf "${archive}")
  file(REMOVE "${archive}")

  # GitHub archives only ever have one folder component at the root, so this
  # will always match that single folder
  file(GLOB dir LIST_DIRECTORIES YES "${dest}/*")

  file(RENAME "${dir}" "${target}")

  set("${NAME}_SOURCE_DIR" "${target}" PARENT_SCOPE)
endfunction()

# Delegates to the dependency
macro(add_dependency NAME)
  if(NOT DEFINED "${NAME}_SOURCE_DIR")
    message(FATAL_ERROR "Missing ${NAME}_SOURCE_DIR variable")
  endif()

  add_subdirectory("${${NAME}_SOURCE_DIR}" "${PROJECT_BINARY_DIR}/_deps/${NAME}")
endmacro()

function(set_off NAME)
  set("${NAME}" OFF CACHE INTERNAL "")
endfunction()