[CMake] Update GetSVN.cmake to use LLVM version control helper scripts.
[oota-llvm.git] / cmake / modules / GetSVN.cmake
1 # CMake project that writes Subversion revision information to a header.
2 #
3 # Input variables:
4 #   FIRST_SOURCE_DIR  - First source directory
5 #   FIRST_NAME        - The macro prefix for the first repository's info
6 #   SECOND_SOURCE_DIR - Second source directory (opt)
7 #   SECOND_NAME       - The macro prefix for the second repository's info (opt)
8 #   HEADER_FILE       - The header file to write
9 #
10 # The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION,
11 # and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and
12 # "SECOND" are substituted with the names specified in the input variables.
13
14 # Chop off cmake/modules/GetSVN.cmake 
15 get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
16 get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
17 get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
18
19 # Handle strange terminals
20 set(ENV{TERM} "dumb")
21
22 function(append_info name path)
23   execute_process(COMMAND "${LLVM_DIR}/utils/GetSourceVersion" "${path}"
24     OUTPUT_VARIABLE revision)
25   string(STRIP "${revision}" revision)
26   execute_process(COMMAND "${LLVM_DIR}/utils/GetRepositoryPath" "${path}"
27     OUTPUT_VARIABLE repository
28     OUTPUT_STRIP_TRAILING_WHITESPACE)
29   string(STRIP "${repository}" repository)
30   file(APPEND "${HEADER_FILE}.txt"
31     "#define ${name}_REVISION \"${revision}\"\n")
32   file(APPEND "${HEADER_FILE}.txt"
33     "#define ${name}_REPOSITORY \"${repository}\"\n")
34 endfunction()
35
36 append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
37 if(DEFINED SECOND_SOURCE_DIR)
38   append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
39 endif()
40
41 # Copy the file only if it has changed.
42 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
43   "${HEADER_FILE}.txt" "${HEADER_FILE}")
44 file(REMOVE "${HEADER_FILE}.txt")
45