1 # CMake project that writes Subversion revision information to a header.
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
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.
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)
19 function(append_info name path)
20 execute_process(COMMAND "${LLVM_DIR}/utils/GetSourceVersion" "${path}"
21 OUTPUT_VARIABLE revision)
22 string(STRIP "${revision}" revision)
23 execute_process(COMMAND "${LLVM_DIR}/utils/GetRepositoryPath" "${path}"
24 OUTPUT_VARIABLE repository
25 OUTPUT_STRIP_TRAILING_WHITESPACE)
26 string(STRIP "${repository}" repository)
27 file(APPEND "${HEADER_FILE}.txt"
28 "#define ${name}_REVISION \"${revision}\"\n")
29 file(APPEND "${HEADER_FILE}.txt"
30 "#define ${name}_REPOSITORY \"${repository}\"\n")
33 append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
34 if(DEFINED SECOND_SOURCE_DIR)
35 append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
38 # Copy the file only if it has changed.
39 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
40 "${HEADER_FILE}.txt" "${HEADER_FILE}")
41 file(REMOVE "${HEADER_FILE}.txt")