1 # CMake script that writes version control information to a header.
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
21 function(append_info name path)
23 get_source_info("${path}" revision repository)
26 file(APPEND "${HEADER_FILE}.tmp"
27 "#define ${name}_REVISION \"${revision}\"\n")
29 file(APPEND "${HEADER_FILE}.tmp"
30 "#undef ${name}_REVISION\n")
33 file(APPEND "${HEADER_FILE}.tmp"
34 "#define ${name}_REPOSITORY \"${repository}\"\n")
36 file(APPEND "${HEADER_FILE}.tmp"
37 "#undef ${name}_REPOSITORY\n")
41 foreach(name IN LISTS NAMES)
42 if(NOT DEFINED ${name}_SOURCE_DIR)
43 message(FATAL_ERROR "${name}_SOURCE_DIR is not defined")
45 append_info(${name} "${${name}_SOURCE_DIR}")
48 # Copy the file only if it has changed.
49 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
50 "${HEADER_FILE}.tmp" "${HEADER_FILE}")
51 file(REMOVE "${HEADER_FILE}.tmp")