From: Don Hinton Date: Tue, 25 Jul 2017 21:13:18 +0000 (+0000) Subject: [CMAKE] Speedup developer builds when passing LLVM_APPEND_VC_REV = OFF X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ed22432b47e7e11a271d0423e2f11219be36bf9;p=llvm [CMAKE] Speedup developer builds when passing LLVM_APPEND_VC_REV = OFF Make sure multiple targets don't get rebuilt unnecessarily when LLVM_APPEND_VC_REV = OFF. Differential Revision: https://reviews.llvm.org/D35377 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309031 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/CMakeLists.txt b/include/llvm/Support/CMakeLists.txt index 95752cf0185..2ae666c91f5 100644 --- a/include/llvm/Support/CMakeLists.txt +++ b/include/llvm/Support/CMakeLists.txt @@ -9,7 +9,6 @@ function(find_first_existing_file out_var) endfunction() macro(find_first_existing_vc_file out_var path) - if ( LLVM_APPEND_VC_REV ) find_program(git_executable NAMES git git.exe git.cmd) # Run from a subdirectory to force git to print an absolute path. execute_process(COMMAND ${git_executable} rev-parse --git-dir @@ -30,7 +29,6 @@ macro(find_first_existing_vc_file out_var path) "${path}/.svn/entries" # SVN 1.6 ) endif() - endif() endmacro() find_first_existing_vc_file(llvm_vc "${LLVM_MAIN_SRC_DIR}") @@ -40,7 +38,20 @@ set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSRevision.h") set(get_svn_script "${LLVM_CMAKE_PATH}/GenerateVersionFromCVS.cmake") -if(DEFINED llvm_vc) +file(WRITE "${version_inc}.empty" "") +if((DEFINED llvm_vc) AND LLVM_APPEND_VC_REV) + + execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files + "${version_inc}.empty" "${version_inc}" + RESULT_VARIABLE files_not_equal + OUTPUT_QUIET + ERROR_QUIET) + # Remove ${version_inc} if it's empty -- toggling LLMV_APPEND_VC_REV + # from OFF to ON. + if(NOT files_not_equal) + file(REMOVE "${version_inc}") + endif() + # Create custom target to generate the VC revision include. add_custom_command(OUTPUT "${version_inc}" DEPENDS "${llvm_vc}" "${get_svn_script}" @@ -49,13 +60,16 @@ if(DEFINED llvm_vc) "-DNAME=LLVM_REVISION" "-DHEADER_FILE=${version_inc}" -P "${get_svn_script}") - - # Mark the generated header as being generated. - set_source_files_properties("${version_inc}" - PROPERTIES GENERATED TRUE - HEADER_FILE_ONLY TRUE) else() - file(WRITE "${version_inc}" "") + # Make sure ${version_inc} is an empty file. + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${version_inc}.empty" "${version_inc}") endif() +file(REMOVE "${version_inc}.empty") + +# Mark the generated header as being generated. +set_source_files_properties("${version_inc}" + PROPERTIES GENERATED TRUE + HEADER_FILE_ONLY TRUE) add_custom_target(llvm_vcsrevision_h DEPENDS "${version_inc}")