gollvm: add GOLLVM_EXTRA_GOCFLAGS control variable

Add new control variable GOLLVM_EXTRA_GOCFLAGS that allows
users to specify additional Go compiler options to be used
when building packages and tools.

Change-Id: If0a3019c0d174e985a6c9729cf679a6608abe6a9
Reviewed-on: https://go-review.googlesource.com/112361
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/gotools/CMakeLists.txt b/gotools/CMakeLists.txt
index efeb26c..dc1dde9 100644
--- a/gotools/CMakeLists.txt
+++ b/gotools/CMakeLists.txt
@@ -11,6 +11,10 @@
 message(STATUS "starting gotools configuration.")
+# Pick up any extra Go compiler flags specified via
+set(gotools_extra_gocflags ${GOLLVM_EXTRA_GOCFLAGS})
 # Driver for compiling *.go files.
 get_target_property(driverdir llvm-goc RUNTIME_OUTPUT_DIRECTORY)
 set(gollvm_driver "${driverdir}/llvm-goc")
@@ -83,6 +87,7 @@
       ${libgo_binroot} ${gotools_binroot}
       GOSRC ${toolfiles}
       GOLIB ${libgotool_archive}
+      GOCFLAGS ${gotools_extra_gocflags}
       ISUBDIR ${isubdir}
       GODEP libgotool libgo_shared libgo_static)
     list(APPEND allgotools ${tool_target})
diff --git a/libgo/CMakeLists.txt b/libgo/CMakeLists.txt
index 4584503..30b20d8 100644
--- a/libgo/CMakeLists.txt
+++ b/libgo/CMakeLists.txt
@@ -79,6 +79,10 @@
 set(gollvm_driver "${driverdir}/llvm-goc")
 set(gocompiler ${gollvm_driver})
+# Pick up any extra Go compiler flags specified via
+set(libgo_extra_gocflags ${GOLLVM_EXTRA_GOCFLAGS})
 # Read in list of all libgo packages
 file(STRINGS "${libgo_srcroot}/libgo-packages.txt" libpackages)
 file(STRINGS "${libgo_srcroot}/gotool-packages.txt" toolpackages)
@@ -333,7 +337,7 @@
   # Call into helper to create rules for package.
-  add_go_package("${pack}" "${libgo_binroot}" GOSRC ${packsrcs} GODEP ${packdeps} GOCFLAGS ${packopts} ${nopic})
+  add_go_package("${pack}" "${libgo_binroot}" GOSRC ${packsrcs} GODEP ${packdeps} GOCFLAGS ${packopts} ${libgo_extra_gocflags} ${nopic})
   # Accumulate libgo objects.
   if(${found} EQUAL -1)