llvm.org GIT mirror llvm / 3ab0c4f
Add SVN version to libLLVMLTO Summary: For Incremental LTO, we need to make sure that an old cache entry is not used when incrementally re-linking with a new libLTO. Adding a global LLVM_REVISION in llvm-config.h would for to rebuild/relink the world for every "git pull"/"svn update". So instead only libLTO is made dependent on the VCS and will be rebuilt (and the dependent binaries relinked, i.e. as of today: libLTO.dylib and llvm-lto). Reviewers: beanz Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18987 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266523 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
3 changed file(s) with 104 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
0 # CMake project that writes Subversion revision information to a header.
1 #
2 # Input variables:
3 # SRC - Source directory
4 # HEADER_FILE - The header file to write
5 #
6 # The output header will contain macros FIRST_REPOSITORY and FIRST_REVISION,
7 # and SECOND_REPOSITORY and SECOND_REVISION if requested, where "FIRST" and
8 # "SECOND" are substituted with the names specified in the input variables.
9
10
11
12 # Chop off cmake/modules/GetSVN.cmake
13 get_filename_component(LLVM_DIR "${CMAKE_SCRIPT_MODE_FILE}" PATH)
14 get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
15 get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
16
17 set(CMAKE_MODULE_PATH
18 ${CMAKE_MODULE_PATH}
19 "${LLVM_DIR}/cmake/modules")
20 include(VersionFromVCS)
21
22 # Handle strange terminals
23 set(ENV{TERM} "dumb")
24
25 function(append_info name path)
26 add_version_info_from_vcs(REVISION ${path})
27 string(STRIP "${REVISION}" REVISION)
28 file(APPEND "${HEADER_FILE}.txt"
29 "#define ${name} \"${REVISION}\"\n")
30 endfunction()
31
32 append_info(${NAME} "${SOURCE_DIR}")
33
34 # Copy the file only if it has changed.
35 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
36 "${HEADER_FILE}.txt" "${HEADER_FILE}")
37 file(REMOVE "${HEADER_FILE}.txt")
38
0 # Adds version control information to the variable VERS. For
11 # determining the Version Control System used (if any) it inspects the
2 # existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR.
2 # existence of certain subdirectories under SOURCE_DIR (if provided as an
3 # extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR).
34
45 function(add_version_info_from_vcs VERS)
6 SET(SOURCE_DIR ${ARGV1})
7 if("${SOURCE_DIR}" STREQUAL "")
8 SET(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 endif()
510 string(REPLACE "svn" "" result "${${VERS}}")
6 if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" )
11 if( EXISTS "${SOURCE_DIR}/.svn" )
712 set(result "${result}svn")
813 # FindSubversion does not work with symlinks. See PR 8437
9 if( NOT IS_SYMLINK "${CMAKE_CURRENT_SOURCE_DIR}" )
14 if( NOT IS_SYMLINK "${SOURCE_DIR}" )
1015 find_package(Subversion)
1116 endif()
1217 if( Subversion_FOUND )
13 subversion_wc_info( ${CMAKE_CURRENT_SOURCE_DIR} Project )
18 subversion_wc_info( ${SOURCE_DIR} Project )
1419 if( Project_WC_REVISION )
1520 set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE)
1621 set(result "${result}-r${Project_WC_REVISION}")
1924 set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE)
2025 endif()
2126 endif()
22 elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git )
27 elseif( EXISTS ${SOURCE_DIR}/.git )
2328 set(result "${result}git")
2429 # Try to get a ref-id
25 if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn )
30 if( EXISTS ${SOURCE_DIR}/.git/svn )
2631 find_program(git_executable NAMES git git.exe git.cmd)
2732 if( git_executable )
2833 set(is_git_svn_rev_exact false)
2934 execute_process(COMMAND
3035 ${git_executable} svn info
31 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
36 WORKING_DIRECTORY ${SOURCE_DIR}
3237 TIMEOUT 5
3338 RESULT_VARIABLE git_result
3439 OUTPUT_VARIABLE git_output)
4550
4651 # Determine if the HEAD points directly at a subversion revision.
4752 execute_process(COMMAND ${git_executable} svn find-rev HEAD
48 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
53 WORKING_DIRECTORY ${SOURCE_DIR}
4954 TIMEOUT 5
5055 RESULT_VARIABLE git_result
5156 OUTPUT_VARIABLE git_output)
6065 endif()
6166 execute_process(COMMAND
6267 ${git_executable} rev-parse --short HEAD
63 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
68 WORKING_DIRECTORY ${SOURCE_DIR}
6469 TIMEOUT 5
6570 RESULT_VARIABLE git_result
6671 OUTPUT_VARIABLE git_output)
72
6773 if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact )
6874 string(STRIP "${git_output}" git_ref_id)
6975 set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
0 # Figure out if we can track VC revisions.
1 function(find_first_existing_file out_var)
2 foreach(file ${ARGN})
3 if(EXISTS "${file}")
4 set(${out_var} "${file}" PARENT_SCOPE)
5 return()
6 endif()
7 endforeach()
8 endfunction()
9
10 macro(find_first_existing_vc_file out_var path)
11 find_first_existing_file(${out_var}
12 "${path}/.git/logs/HEAD" # Git
13 "${path}/.svn/wc.db" # SVN 1.7
14 "${path}/.svn/entries" # SVN 1.6
15 )
16 endmacro()
17
18 find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}")
19
20 # The VC revision include that we want to generate.
21 set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/LLVMLTORevision.h")
22
23 set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GenerateVersionFromCVS.cmake")
24
25 if(DEFINED llvm_vc)
26 # Create custom target to generate the VC revision include.
27 add_custom_command(OUTPUT "${version_inc}"
28 DEPENDS "${llvm_vc}" "${get_svn_script}"
29 COMMAND
30 ${CMAKE_COMMAND} "-DSOURCE_DIR=${LLVM_MAIN_SRC_DIR}"
31 "-DNAME=LLVM_REVISION"
32 "-DHEADER_FILE=${version_inc}"
33 -P "${get_svn_script}")
34
35 # Mark the generated header as being generated.
36 set_source_files_properties("${version_inc}"
37 PROPERTIES GENERATED TRUE
38 HEADER_FILE_ONLY TRUE)
39
40 # Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC.
41 set_source_files_properties(Version.cpp
42 PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
43 else()
44 # Not producing a VC revision include.
45 set(version_inc)
46 endif()
47
48
49 add_llvm_library(LLVMLTO
150 LTOModule.cpp
251 LTOCodeGenerator.cpp
352 UpdateCompilerUsed.cpp
453 ThinLTOCodeGenerator.cpp
54 ${version_inc}
555
656 ADDITIONAL_HEADER_DIRS
757 ${LLVM_MAIN_INCLUDE_DIR}/llvm/LTO