[CMake] Generate LLDB_REVISION at build time
Summary: This alters the generation of LLDB_REVISION to be heavily based on how clang generates its version header. There are two benefits of this aproach. (1) The LLDB_REVISION is generated at build time, so it will be updated after an SCM pull/update even if CMake doesn't re-run (2) This works on Windows As noted this code is a simplified implementation of the code from clang. Reviewers: tfiala, zturner Subscribers: beanz, mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D24846 llvm-svn: 282314
This commit is contained in:
parent
a638fe057c
commit
aa098de715
|
@ -40,6 +40,41 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
|||
DEPENDS ${LLDB_VERS_GENERATED_FILE})
|
||||
endif()
|
||||
|
||||
foreach(file
|
||||
"${LLDB_SOURCE_DIR}/.git/logs/HEAD" # Git
|
||||
"${LLDB_SOURCE_DIR}/.svn/wc.db" # SVN 1.7
|
||||
"${LLDB_SOURCE_DIR}/.svn/entries" # SVN 1.6
|
||||
)
|
||||
if(EXISTS "${file}")
|
||||
set(lldb_vc "${file}")
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(DEFINED lldb_vc)
|
||||
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
|
||||
set(get_svn_script "${LLVM_MAIN_SRC_DIR}/cmake/modules/GetSVN.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_source_files_properties(lldb.cpp
|
||||
PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
|
||||
list(APPEND lldbBase_SOURCES ${version_inc})
|
||||
endif()
|
||||
|
||||
add_lldb_library(lldbBase
|
||||
${lldbBase_SOURCES}
|
||||
)
|
||||
|
@ -64,29 +99,3 @@ add_subdirectory(Utility)
|
|||
# Build API last. Since liblldb needs to link against every other target, it needs
|
||||
# those targets to have already been created.
|
||||
add_subdirectory(API)
|
||||
|
||||
# Determine LLDB revision and repository. GetSourceVersion and GetRepositoryPath are shell-scripts, and as
|
||||
# such will not work on Windows.
|
||||
if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
|
||||
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLDB_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE LLDB_REVISION)
|
||||
if ( LLDB_REVISION )
|
||||
string(REGEX REPLACE "(\r?\n)+$" "" LLDB_REVISION ${LLDB_REVISION})
|
||||
endif()
|
||||
|
||||
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLDB_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE LLDB_REPOSITORY)
|
||||
if ( LLDB_REPOSITORY )
|
||||
# Replace newline characters with spaces
|
||||
string(REGEX REPLACE "(\r?\n)+" " " LLDB_REPOSITORY ${LLDB_REPOSITORY})
|
||||
|
||||
# Remove trailing spaces
|
||||
string(REGEX REPLACE "(\ )+$" "" LLDB_REPOSITORY ${LLDB_REPOSITORY})
|
||||
endif()
|
||||
|
||||
set_property(
|
||||
SOURCE lldb.cpp
|
||||
PROPERTY COMPILE_DEFINITIONS "LLDB_REVISION=\"${LLDB_REVISION}\"" "LLDB_REPOSITORY=\"${LLDB_REPOSITORY}\"")
|
||||
endif ()
|
||||
# FIXME: implement svn/git revision and repository parsing solution on Windows. There is an SVN-only
|
||||
# revision parsing solution in tools/clang/lib/Basic/CMakelists.txt.
|
||||
|
|
|
@ -18,6 +18,10 @@ extern "C" const unsigned char liblldb_coreVersionString[];
|
|||
|
||||
#include "clang/Basic/Version.h"
|
||||
|
||||
#ifdef HAVE_SVN_VERSION_INC
|
||||
# include "SVNVersion.inc"
|
||||
#endif
|
||||
|
||||
static const char *GetLLDBRevision() {
|
||||
#ifdef LLDB_REVISION
|
||||
return LLDB_REVISION;
|
||||
|
|
Loading…
Reference in New Issue