]> granicus.if.org Git - clang/commitdiff
[CMake] Always include the Clang repo version, just like the autoconf build.
authorJordan Rose <jordan_rose@apple.com>
Wed, 19 Nov 2014 22:03:48 +0000 (22:03 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 19 Nov 2014 22:03:48 +0000 (22:03 +0000)
Now that LLVM's helper script GetSVN.cmake actually works consistently,
there's no reason not to use it. We avoid having to regenerate SVNVersion.inc
every time by marking it as dependent on Git's reflog or SVN's entries file.

This should end most of the issues of the AST format changing and breaking
old module files: CMake-Clang should now detect that the version changed just
like Autoconf-Clang has.

Based on r190557. Depends on LLVM r222391.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222393 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/CMakeLists.txt

index 3bcbc89f8ca4c95df1b6f68e0c2cea6fcbbbe22b..62748a08e51c98d5aa7386e7125eb1f6d94796ba 100644 (file)
@@ -4,6 +4,48 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
+# Figure out if we can track VC revisions.
+function(find_first_existing_file out_var)
+  foreach(file ${ARGN})
+    if(EXISTS "${file}")
+      set(${out_var} "${file}" PARENT_SCOPE)
+      return()
+    endif()
+  endforeach()
+endfunction()
+
+find_first_existing_file(llvm_vc
+  "${LLVM_MAIN_SRC_DIR}/.git/logs/HEAD"
+  "${LLVM_MAIN_SRC_DIR}/.svn/entries")
+find_first_existing_file(clang_vc
+  "${CLANG_SOURCE_DIR}/.git/logs/HEAD"
+  "${CLANG_SOURCE_DIR}/.svn/entries")
+
+if(DEFINED llvm_vc AND DEFINED clang_vc)
+  # Create custom target to generate the VC revision include.
+  add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc"
+    DEPENDS "${llvm_vc}" "${clang_vc}"
+    COMMAND
+    ${CMAKE_COMMAND} "-DFIRST_SOURCE_DIR=${LLVM_MAIN_SRC_DIR}"
+                     "-DFIRST_NAME=LLVM"
+                     "-DSECOND_SOURCE_DIR=${CLANG_SOURCE_DIR}"
+                     "-DSECOND_NAME=SVN"
+                     "-DHEADER_FILE=${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc"
+                     -P "${LLVM_MAIN_SRC_DIR}/cmake/modules/GetSVN.cmake")
+
+  # Mark the generated header as being generated.
+  set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.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(Version.cpp
+    PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
+  set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
+else()
+  set(version_inc)
+endif()
+
 add_clang_library(clangBasic
   Attributes.cpp
   Builtins.cpp
@@ -29,30 +71,6 @@ add_clang_library(clangBasic
   VersionTuple.cpp
   VirtualFileSystem.cpp
   Warnings.cpp
+  ${version_inc}
   )
 
-# Determine Subversion revision.
-# FIXME: This only gets updated when CMake is run, so this revision number
-# may be out-of-date!
-if( NOT IS_SYMLINK "${CLANG_SOURCE_DIR}" )  # See PR 8437
-  find_package(Subversion)
-endif()
-if (Subversion_FOUND AND EXISTS "${CLANG_SOURCE_DIR}/.svn")
-  set(FIRST_SOURCE_DIR ${LLVM_MAIN_SRC_DIR})
-  set(FIRST_REPOSITORY LLVM_REPOSITORY)
-  set(SECOND_SOURCE_DIR ${CLANG_SOURCE_DIR})
-  set(SECOND_REPOSITORY SVN_REPOSITORY)
-  set(HEADER_FILE ${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc)
-  include(GetSVN)
-
-  # Mark the generated header as being generated.
-  message(STATUS "Expecting header to go in ${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.inc")
-  set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/SVNVersion.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(Version.cpp
-    PROPERTIES COMPILE_DEFINITIONS "HAVE_SVN_VERSION_INC")
-
-endif()