Skip to content

Commit 247b7d0

Browse files
authored
[cmake] Add LLVM_FORCE_VC_REVISION option (#67125)
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.
1 parent 5bfd5c6 commit 247b7d0

File tree

8 files changed

+36
-2
lines changed

8 files changed

+36
-2
lines changed

clang/lib/Basic/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ add_custom_command(OUTPUT "${version_inc}"
3939
"-DHEADER_FILE=${version_inc}"
4040
"-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
4141
"-DLLVM_VC_REVISION=${llvm_vc_revision}"
42+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
43+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
4244
-P "${generate_vcs_version_script}")
4345

4446
# Mark the generated header as being generated.

flang/lib/Common/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ endif()
1212
if(flang_vc AND LLVM_APPEND_VC_REV)
1313
set(flang_source_dir ${FLANG_SOURCE_DIR})
1414
endif()
15-
15+
1616
# Create custom target to generate the VC revision include.
1717
add_custom_command(OUTPUT "${version_inc}"
1818
DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
1919
COMMAND ${CMAKE_COMMAND} "-DNAMES=\"LLVM;FLANG\""
2020
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
2121
"-DFLANG_SOURCE_DIR=${flang_source_dir}"
2222
"-DHEADER_FILE=${version_inc}"
23+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
24+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
2325
-P "${generate_vcs_version_script}")
2426

2527
# Mark the generated header as being generated.

lld/Common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ add_custom_command(OUTPUT "${version_inc}"
1313
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
1414
"-DLLD_SOURCE_DIR=${lld_source_dir}"
1515
"-DHEADER_FILE=${version_inc}"
16+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
17+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
1618
-P "${generate_vcs_version_script}")
1719

1820
# Mark the generated header as being generated.

lldb/source/Version/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ add_custom_command(OUTPUT "${vcs_version_inc}"
1717
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
1818
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
1919
"-DHEADER_FILE=${vcs_version_inc}"
20+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
21+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
2022
-P "${generate_vcs_version_script}")
2123

2224
set_source_files_properties("${vcs_version_inc}"

llvm/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,12 @@ include(VersionFromVCS)
325325
option(LLVM_APPEND_VC_REV
326326
"Embed the version control system revision in LLVM" ON)
327327

328+
set(LLVM_FORCE_VC_REVISION
329+
"" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")
330+
331+
set(LLVM_FORCE_VC_REPOSITORY
332+
"" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")
333+
328334
option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" OFF)
329335

330336
set(PACKAGE_NAME LLVM)

llvm/cmake/modules/GenerateVersionFromVCS.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ function(append_info name revision repository)
3636
endfunction()
3737

3838
foreach(name IN LISTS NAMES)
39-
if(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
39+
if(LLVM_FORCE_VC_REVISION AND LLVM_FORCE_VC_REPOSITORY)
40+
set(revision ${LLVM_FORCE_VC_REVISION})
41+
set(repository ${LLVM_FORCE_VC_REPOSITORY})
42+
elseif(LLVM_FORCE_VC_REVISION)
43+
set(revision ${LLVM_FORCE_VC_REVISION})
44+
elseif(LLVM_FORCE_VC_REPOSITORY)
45+
set(repository ${LLVM_FORCE_VC_REPOSITORY})
46+
elseif(${name}_VC_REPOSITORY AND ${name}_VC_REVISION)
4047
set(revision ${${name}_VC_REVISION})
4148
set(repository ${${name}_VC_REPOSITORY})
4249
elseif(DEFINED ${name}_SOURCE_DIR)

llvm/docs/CMake.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ enabled sub-projects. Nearly all of these variable names begin with
334334
need revision info can disable this option to avoid re-linking most binaries
335335
after a branch switch. Defaults to ON.
336336

337+
**LLVM_FORCE_VC_REVISION**:STRING
338+
Force a specific Git revision id rather than calling to git to determine it.
339+
This is useful in environments where git is not available or non-functional
340+
but the VC revision is available through other means.
341+
342+
**LLVM_FORCE_VC_REPOSITORY**:STRING
343+
Set the git repository to include in version info rather than calling git to
344+
determine it.
345+
337346
**LLVM_BUILD_32_BITS**:BOOL
338347
Build 32-bit executables and libraries on 64-bit systems. This option is
339348
available only on some 64-bit Unix systems. Defaults to OFF.

llvm/include/llvm/Support/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ if (fake_version_inc)
2828
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
2929
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
3030
"-DHEADER_FILE=${version_inc}"
31+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
32+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
3133
-P "${generate_vcs_version_script}")
3234
else()
3335
add_custom_command(OUTPUT "${version_inc}"
3436
DEPENDS "${llvm_vc}" "${generate_vcs_version_script}"
3537
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLVM"
3638
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
3739
"-DHEADER_FILE=${version_inc}"
40+
"-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
41+
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
3842
-P "${generate_vcs_version_script}")
3943
endif()
4044

0 commit comments

Comments
 (0)