gollvm: ensure that runtime.Version contains a meaningful string

This CL is the gollvm version of CL 414734, making sure that
runtime.buildVersion has meaningful content.

Change-Id: Ie2ff8d8001a312efec63e018d3964aadc276361d
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/420217
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
diff --git a/cmake/modules/AutoGenGo.cmake b/cmake/modules/AutoGenGo.cmake
index 6bc08db..644075a 100644
--- a/cmake/modules/AutoGenGo.cmake
+++ b/cmake/modules/AutoGenGo.cmake
@@ -205,9 +205,10 @@
 #   * root of libgo source
 
 function(emitversionstring outfile srcroot)
+  string(TIMESTAMP BDATE "%Y%m%d")
   file(STRINGS "${srcroot}/../VERSION" rawver)
   string(STRIP ${rawver} ver)
-  file(APPEND ${outfile} "\"${ver} gollvm LLVM ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}\"")
+  file(APPEND ${outfile} "\"${ver} gollvm LLVM ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX} ${BDATE} (experimental)\"")
 endfunction()
 
 #----------------------------------------------------------------------
@@ -308,7 +309,8 @@
 endfunction()
 
 #----------------------------------------------------------------------
-# Emit 'goroot.go', containing the default GOROOT setting.
+# Emit 'goroot.go', containing the default GOROOT setting
+# and the build version.
 #
 # Unnamed parameters:
 #
@@ -322,6 +324,14 @@
   file(WRITE ${outfile} "package runtime\n\n")
   file(APPEND ${outfile} "var defaultGOROOT = \"${GOLLVM_INSTALL_DIR}\"\n")
 
+  # For gccgo, at the point where goroot.go is emitted, the compiler
+  # has already been built; with cmake all of this is happening well before
+  # the driver is available (refer also to the corresponding code in
+  # Driver.cpp).
+  file(APPEND ${outfile} "var buildVersion = ")
+  emitversionstring(${outfile} ${srcroot})
+  file(APPEND ${outfile} "\n")
+
 endfunction()
 
 #----------------------------------------------------------------------