[clang] [cmake] Add LLVM_FORCE_VC_REVISION option (PR #67125)
David Truby via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 22 07:11:42 PDT 2023
https://github.com/DavidTruby updated https://github.com/llvm/llvm-project/pull/67125
>From 0690521dd83e8fae81f65bce173ed7189ff9307b Mon Sep 17 00:00:00 2001
From: David Truby <David.Truby at arm.com>
Date: Fri, 22 Sep 2023 12:22:49 +0000
Subject: [PATCH 1/2] [cmake] Add LLVM_FORCE_VC_REVISION option
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.
---
clang/lib/Basic/CMakeLists.txt | 2 ++
flang/lib/Common/CMakeLists.txt | 4 +++-
lld/Common/CMakeLists.txt | 2 ++
lldb/source/Version/CMakeLists.txt | 2 ++
llvm/CMakeLists.txt | 6 ++++++
llvm/cmake/modules/GenerateVersionFromVCS.cmake | 9 ++++++++-
llvm/include/llvm/Support/CMakeLists.txt | 4 ++++
7 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index db59d7dd96da0a4..36ccf7d0809453e 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -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.
diff --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index 81cee82e04b88ae..c6f818ad27cd19a 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -12,7 +12,7 @@ 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}"
@@ -20,6 +20,8 @@ add_custom_command(OUTPUT "${version_inc}"
"-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.
diff --git a/lld/Common/CMakeLists.txt b/lld/Common/CMakeLists.txt
index c975da2a49b6bda..4f503d04f7844f7 100644
--- a/lld/Common/CMakeLists.txt
+++ b/lld/Common/CMakeLists.txt
@@ -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.
diff --git a/lldb/source/Version/CMakeLists.txt b/lldb/source/Version/CMakeLists.txt
index c1393b5dd6e6b62..90fe53d52cc5d05 100644
--- a/lldb/source/Version/CMakeLists.txt
+++ b/lldb/source/Version/CMakeLists.txt
@@ -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}"
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index fa39c7554de1f61..5985256498dcbb2 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -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)
diff --git a/llvm/cmake/modules/GenerateVersionFromVCS.cmake b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
index 9cd780e5aa162c0..1b3b2946e62b25c 100644
--- a/llvm/cmake/modules/GenerateVersionFromVCS.cmake
+++ b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
@@ -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)
diff --git a/llvm/include/llvm/Support/CMakeLists.txt b/llvm/include/llvm/Support/CMakeLists.txt
index b6be96525c744a3..76c382bfc644f2e 100644
--- a/llvm/include/llvm/Support/CMakeLists.txt
+++ b/llvm/include/llvm/Support/CMakeLists.txt
@@ -28,6 +28,8 @@ 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}"
@@ -35,6 +37,8 @@ else()
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()
>From b18fc28a9c899266dfc304fe1d9e51735c531164 Mon Sep 17 00:00:00 2001
From: David Truby <David.Truby at arm.com>
Date: Fri, 22 Sep 2023 14:11:14 +0000
Subject: [PATCH 2/2] Add new options to CMake.rst
---
llvm/docs/CMake.rst | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 67f740447ed7bfb..70ab95555d14716 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -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.
More information about the cfe-commits
mailing list