File: GenerateVersionFromVCS.cmake

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (62 lines) | stat: -rw-r--r-- 2,104 bytes parent folder | download | duplicates (8)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# CMake script that writes version control information to a header.
#
# Input variables:
#   NAMES             - A list of names for each of the source directories.
#   <NAME>_SOURCE_DIR - A path to source directory for each name in NAMES.
#   HEADER_FILE       - The header file to write
#
# The output header will contain macros <NAME>_REPOSITORY and <NAME>_REVISION,
# where "<NAME>" is substituted with the names specified in the input variables,
# for each of the <NAME>_SOURCE_DIR given.

get_filename_component(LLVM_CMAKE_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")

include(VersionFromVCS)

# Handle strange terminals
set(ENV{TERM} "dumb")

function(append_info name revision repository)
  if(revision)
    file(APPEND "${HEADER_FILE}.tmp"
      "#define ${name}_REVISION \"${revision}\"\n")
  else()
    file(APPEND "${HEADER_FILE}.tmp"
      "#undef ${name}_REVISION\n")
  endif()
  if(repository)
    file(APPEND "${HEADER_FILE}.tmp"
      "#define ${name}_REPOSITORY \"${repository}\"\n")
  else()
    file(APPEND "${HEADER_FILE}.tmp"
      "#undef ${name}_REPOSITORY\n")
  endif()
endfunction()

foreach(name IN LISTS NAMES)
  if(LLVM_FORCE_VC_REVISION AND LLVM_FORCE_VC_REPOSITORY)
    set(revision ${LLVM_FORCE_VC_REVISION})
    set(repository ${LLVM_FORCE_VC_REPOSITORY})
  elseif(LLVM_FORCE_VC_REVISION)
    set(revision ${LLVM_FORCE_VC_REVISION})
  elseif(LLVM_FORCE_VC_REPOSITORY)
    set(repository ${LLVM_FORCE_VC_REPOSITORY})
  elseif(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
    set(revision ${${name}_VC_REVISION})
    set(repository ${${name}_VC_REPOSITORY})
  elseif(DEFINED ${name}_SOURCE_DIR)
    if (${name}_SOURCE_DIR)
      get_source_info("${${name}_SOURCE_DIR}" revision repository)
    endif()
  else()
    message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
  endif()
  append_info(${name} "${revision}" "${repository}")
endforeach()

# Copy the file only if it has changed.
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
  "${HEADER_FILE}.tmp" "${HEADER_FILE}")
file(REMOVE "${HEADER_FILE}.tmp")