[libc][NFC] Move aligned access implementations to separate header
[llvm-project.git] / llvm / cmake / modules / GenerateVersionFromVCS.cmake
blob9cd780e5aa162c03d3613843398e9693646f8dd6
1 # CMake script that writes version control information to a header.
3 # Input variables:
4 #   NAMES             - A list of names for each of the source directories.
5 #   <NAME>_SOURCE_DIR - A path to source directory for each name in NAMES.
6 #   HEADER_FILE       - The header file to write
8 # The output header will contain macros <NAME>_REPOSITORY and <NAME>_REVISION,
9 # where "<NAME>" is substituted with the names specified in the input variables,
10 # for each of the <NAME>_SOURCE_DIR given.
12 get_filename_component(LLVM_CMAKE_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
14 list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
16 include(VersionFromVCS)
18 # Handle strange terminals
19 set(ENV{TERM} "dumb")
21 function(append_info name revision repository)
22   if(revision)
23     file(APPEND "${HEADER_FILE}.tmp"
24       "#define ${name}_REVISION \"${revision}\"\n")
25   else()
26     file(APPEND "${HEADER_FILE}.tmp"
27       "#undef ${name}_REVISION\n")
28   endif()
29   if(repository)
30     file(APPEND "${HEADER_FILE}.tmp"
31       "#define ${name}_REPOSITORY \"${repository}\"\n")
32   else()
33     file(APPEND "${HEADER_FILE}.tmp"
34       "#undef ${name}_REPOSITORY\n")
35   endif()
36 endfunction()
38 foreach(name IN LISTS NAMES)
39   if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
40     set(revision ${${name}_VC_REVISION})
41     set(repository ${${name}_VC_REPOSITORY})
42   elseif(DEFINED ${name}_SOURCE_DIR)
43     if (${name}_SOURCE_DIR)
44       get_source_info("${${name}_SOURCE_DIR}" revision repository)
45     endif()
46   else()
47     message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
48   endif()
49   append_info(${name} "${revision}" "${repository}")
50 endforeach()
52 # Copy the file only if it has changed.
53 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
54   "${HEADER_FILE}.tmp" "${HEADER_FILE}")
55 file(REMOVE "${HEADER_FILE}.tmp")