xref: /aosp_15_r20/external/llvm/cmake/modules/GenerateVersionFromCVS.cmake (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# CMake project that writes Subversion revision information to a header.
2*9880d681SAndroid Build Coastguard Worker#
3*9880d681SAndroid Build Coastguard Worker# Input variables:
4*9880d681SAndroid Build Coastguard Worker#   SRC               - Source directory
5*9880d681SAndroid Build Coastguard Worker#   HEADER_FILE       - The header file to write
6*9880d681SAndroid Build Coastguard Worker#
7*9880d681SAndroid Build Coastguard Worker# The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION,
8*9880d681SAndroid Build Coastguard Worker# and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and
9*9880d681SAndroid Build Coastguard Worker# "SECOND" are substituted with the names specified in the input variables.
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker# Chop off cmake/modules/GetSVN.cmake
14*9880d681SAndroid Build Coastguard Workerget_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
15*9880d681SAndroid Build Coastguard Workerget_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
16*9880d681SAndroid Build Coastguard Workerget_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Workerset(CMAKE_MODULE_PATH
19*9880d681SAndroid Build Coastguard Worker  ${CMAKE_MODULE_PATH}
20*9880d681SAndroid Build Coastguard Worker  "${LLVM_DIR}/cmake/modules")
21*9880d681SAndroid Build Coastguard Workerinclude(VersionFromVCS)
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker# Handle strange terminals
24*9880d681SAndroid Build Coastguard Workerset(ENV{TERM} "dumb")
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Workerfunction(append_info name path)
27*9880d681SAndroid Build Coastguard Worker  add_version_info_from_vcs(REVISION ${path})
28*9880d681SAndroid Build Coastguard Worker  string(STRIP "${REVISION}" REVISION)
29*9880d681SAndroid Build Coastguard Worker  file(APPEND "${HEADER_FILE}.txt"
30*9880d681SAndroid Build Coastguard Worker    "#define ${name} \"${REVISION}\"\n")
31*9880d681SAndroid Build Coastguard Workerendfunction()
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Workerappend_info(${NAME} "${SOURCE_DIR}")
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker# Copy the file only if it has changed.
36*9880d681SAndroid Build Coastguard Workerexecute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
37*9880d681SAndroid Build Coastguard Worker  "${HEADER_FILE}.txt" "${HEADER_FILE}")
38*9880d681SAndroid Build Coastguard Workerfile(REMOVE "${HEADER_FILE}.txt")
39*9880d681SAndroid Build Coastguard Worker
40