Skip to content

Commit

Permalink
[CMAKE] Speedup developer builds when passing LLVM_APPEND_VC_REV = OFF
Browse files Browse the repository at this point in the history
Make sure multiple targets don't get rebuilt unnecessarily when LLVM_APPEND_VC_REV = OFF.

Differential Revision: https://reviews.llvm.org/D35377

llvm-svn: 309031
  • Loading branch information
donhinton committed Jul 25, 2017
1 parent c810bb3 commit d452126
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions llvm/include/llvm/Support/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -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}")
Expand All @@ -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}"
Expand All @@ -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}")

0 comments on commit d452126

Please sign in to comment.