Skip to content

Commit

Permalink
[cmake] Add LLVM_FORCE_VC_REVISION option (#67125)
Browse files Browse the repository at this point in the history
This patch adds a LLVM_FORCE_VC_REVISION option to force a custom
VC revision to be included instead of trying to fetch one from a
git command. This is helpful in environments where git is not
available or is non-functional but the vc revision is available
through some other means.
  • Loading branch information
DavidTruby committed Sep 25, 2023
1 parent 5bfd5c6 commit 247b7d0
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_custom_command(OUTPUT "${version_inc}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
"-DLLVM_VC_REVISION=${llvm_vc_revision}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")

# Mark the generated header as being generated.
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ endif()
if(flang_vc AND LLVM_APPEND_VC_REV)
set(flang_source_dir ${FLANG_SOURCE_DIR})
endif()

# Create custom target to generate the VC revision include.
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;FLANG\""
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
"-DFLANG_SOURCE_DIR=${flang_source_dir}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")

# Mark the generated header as being generated.
Expand Down
2 changes: 2 additions & 0 deletions lld/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ add_custom_command(OUTPUT "${version_inc}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
"-DLLD_SOURCE_DIR=${lld_source_dir}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")

# Mark the generated header as being generated.
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Version/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ add_custom_command(OUTPUT "${vcs_version_inc}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
"-DHEADER_FILE=${vcs_version_inc}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")

set_source_files_properties("${vcs_version_inc}"
Expand Down
6 changes: 6 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ include(VersionFromVCS)
option(LLVM_APPEND_VC_REV
"Embed the version control system revision in LLVM" ON)

set(LLVM_FORCE_VC_REVISION
"" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")

set(LLVM_FORCE_VC_REPOSITORY
"" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")

option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)

set(PACKAGE_NAME LLVM)
Expand Down
9 changes: 8 additions & 1 deletion llvm/cmake/modules/GenerateVersionFromVCS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ function(append_info name revision repository)
endfunction()

foreach(name IN LISTS NAMES)
if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
if(LLVM_FORCE_VC_REVISION AND LLVM_FORCE_VC_REPOSITORY)
set(revision ${LLVM_FORCE_VC_REVISION})
set(repository ${LLVM_FORCE_VC_REPOSITORY})
elseif(LLVM_FORCE_VC_REVISION)
set(revision ${LLVM_FORCE_VC_REVISION})
elseif(LLVM_FORCE_VC_REPOSITORY)
set(repository ${LLVM_FORCE_VC_REPOSITORY})
elseif(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
set(revision ${${name}_VC_REVISION})
set(repository ${${name}_VC_REPOSITORY})
elseif(DEFINED ${name}_SOURCE_DIR)
Expand Down
9 changes: 9 additions & 0 deletions llvm/docs/CMake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,15 @@ enabled sub-projects. Nearly all of these variable names begin with
need revision info can disable this option to avoid re-linking most binaries
after a branch switch. Defaults to ON.

**LLVM_FORCE_VC_REVISION**:STRING
Force a specific Git revision id rather than calling to git to determine it.
This is useful in environments where git is not available or non-functional
but the VC revision is available through other means.

**LLVM_FORCE_VC_REPOSITORY**:STRING
Set the git repository to include in version info rather than calling git to
determine it.

**LLVM_BUILD_32_BITS**:BOOL
Build 32-bit executables and libraries on 64-bit systems. This option is
available only on some 64-bit Unix systems. Defaults to OFF.
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ if (fake_version_inc)
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")
else()
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")
endif()

Expand Down

0 comments on commit 247b7d0

Please sign in to comment.