[CMake] Unify scripts for generating VCS headers
Previously, there were two different scripts for generating VCS headers:
one used by LLVM and one used by Clang and lldb. They were both similar,
but different. They were both broken in their own ways, for example the
one used by Clang didn't properly handle monorepo resulting in an
incorrect version information reported by Clang.
This change unifies two the scripts by introducing a new script that's
used from both LLVM, Clang and lldb, ensures that the new script
supports both monorepo and standalone SVN and Git setups, and removes
the old scripts.
Differential Revision: https://reviews.llvm.org/D57063
llvm-svn: 353268
GitOrigin-RevId: 23fdd5a37ff4e0512af0b40f6ff3e6db4694e937
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index e9d8e79..51c3b54 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -15,30 +15,30 @@
endif()
endforeach()
-if(DEFINED lldb_vc)
- set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
- set(get_svn_script "${LLVM_CMAKE_PATH}/GetSVN.cmake")
+set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
+set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
- # Create custom target to generate the VC revision include.
- add_custom_command(OUTPUT "${version_inc}"
- DEPENDS "${lldb_vc}" "${get_svn_script}"
- COMMAND
- ${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLDB_SOURCE_DIR}"
- "-DFIRST_NAME=LLDB"
- "-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)
-
- # Tell Version.cpp that it needs to build with -DHAVE_SVN_VERSION_INC.
- set_property(SOURCE lldb.cpp APPEND PROPERTY
- COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
- list(APPEND lldbBase_SOURCES ${version_inc})
+if(lldb_vc)
+ set(lldb_source_dir ${LLDB_SOURCE_DIR})
endif()
+add_custom_command(OUTPUT "${version_inc}"
+ DEPENDS "${lldb_vc}" "${generate_vcs_version_script}"
+ COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
+ "-DLLDB_SOURCE_DIR=${LLDB_SOURCE_DIR}"
+ "-DHEADER_FILE=${version_inc}"
+ -P "${generate_vcs_version_script}")
+
+# Mark the generated header as being generated.
+set_source_files_properties("${version_inc}"
+ PROPERTIES GENERATED TRUE
+ HEADER_FILE_ONLY TRUE)
+
+set_property(SOURCE lldb.cpp APPEND PROPERTY
+ COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
+
+list(APPEND lldbBase_SOURCES ${version_inc})
+
if(APPLE)
set(apple_version_inc "${CMAKE_CURRENT_BINARY_DIR}/AppleVersion.inc")
set(apple_version_script "${LLDB_SOURCE_DIR}/cmake/modules/EmbedAppleVersion.cmake")
diff --git a/source/lldb.cpp b/source/lldb.cpp
index 2bf6a7a..ebf8c2e 100644
--- a/source/lldb.cpp
+++ b/source/lldb.cpp
@@ -13,8 +13,8 @@
#include "clang/Basic/Version.h"
-#ifdef HAVE_SVN_VERSION_INC
-#include "SVNVersion.inc"
+#ifdef HAVE_VCS_VERSION_INC
+#include "VCSVersion.inc"
#endif
#ifdef HAVE_APPLE_VERSION_INC