| Mehdi Amini | 1d30fca | 2016-04-16 07:33:14 +0000 | [diff] [blame] | 1 | # CMake project that writes Subversion revision information to a header. | 
|  | 2 | # | 
|  | 3 | # Input variables: | 
|  | 4 | #   SRC               - Source directory | 
|  | 5 | #   HEADER_FILE       - The header file to write | 
|  | 6 | # | 
|  | 7 | # The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION, | 
|  | 8 | # and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and | 
|  | 9 | # "SECOND" are substituted with the names specified in the input variables. | 
|  | 10 |  | 
|  | 11 |  | 
|  | 12 |  | 
|  | 13 | # Chop off cmake/modules/GetSVN.cmake | 
|  | 14 | get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH) | 
|  | 15 | get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) | 
|  | 16 | get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH) | 
|  | 17 |  | 
|  | 18 | set(CMAKE_MODULE_PATH | 
|  | 19 | ${CMAKE_MODULE_PATH} | 
|  | 20 | "${LLVM_DIR}/cmake/modules") | 
|  | 21 | include(VersionFromVCS) | 
|  | 22 |  | 
|  | 23 | # Handle strange terminals | 
|  | 24 | set(ENV{TERM} "dumb") | 
|  | 25 |  | 
|  | 26 | function(append_info name path) | 
|  | 27 | add_version_info_from_vcs(REVISION ${path}) | 
|  | 28 | string(STRIP "${REVISION}" REVISION) | 
|  | 29 | file(APPEND "${HEADER_FILE}.txt" | 
|  | 30 | "#define ${name} \"${REVISION}\"\n") | 
|  | 31 | endfunction() | 
|  | 32 |  | 
|  | 33 | append_info(${NAME} "${SOURCE_DIR}") | 
|  | 34 |  | 
|  | 35 | # Copy the file only if it has changed. | 
|  | 36 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different | 
|  | 37 | "${HEADER_FILE}.txt" "${HEADER_FILE}") | 
|  | 38 | file(REMOVE "${HEADER_FILE}.txt") | 
|  | 39 |  |