1# CMake script that writes version control information to a header. 2# 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 7# 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. 11 12get_filename_component(LLVM_CMAKE_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH) 13 14list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") 15 16include(VersionFromVCS) 17 18# Handle strange terminals 19set(ENV{TERM} "dumb") 20 21function(append_info name path) 22 if(path) 23 get_source_info("${path}" revision repository) 24 endif() 25 if(revision) 26 file(APPEND "${HEADER_FILE}.tmp" 27 "#define ${name}_REVISION \"${revision}\"\n") 28 else() 29 file(APPEND "${HEADER_FILE}.tmp" 30 "#undef ${name}_REVISION\n") 31 endif() 32 if(repository) 33 file(APPEND "${HEADER_FILE}.tmp" 34 "#define ${name}_REPOSITORY \"${repository}\"\n") 35 else() 36 file(APPEND "${HEADER_FILE}.tmp" 37 "#undef ${name}_REPOSITORY\n") 38 endif() 39endfunction() 40 41foreach(name IN LISTS NAMES) 42 if(NOT DEFINED ${name}_SOURCE_DIR) 43 message(FATAL_ERROR "${name}_SOURCE_DIR is not defined") 44 endif() 45 append_info(${name} "${${name}_SOURCE_DIR}") 46endforeach() 47 48# Copy the file only if it has changed. 49execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different 50 "${HEADER_FILE}.tmp" "${HEADER_FILE}") 51file(REMOVE "${HEADER_FILE}.tmp") 52