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 # Handle strange terminals
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")
36 append_info(${FIRST_NAME} "${FIRST_SOURCE_DIR}")
37 if(DEFINED SECOND_SOURCE_DIR)
38 append_info(${SECOND_NAME} "${SECOND_SOURCE_DIR}")
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")