gollvm: minor cmake cleanup

Rework the cmake rules that handle the GMP/MPC/MPFR dependencies
so as to eliminate the need for a "prebuild" step when building
gollvm (you can now just do cmake then ninja). Remove the obsolete
'Parser' unit test directory; this was originally intended to
have separate tests of frontend machinery, but this is not practical
(and the test themselves were incomplete).

Change-Id: I22af6cdc950e693cfb3fe71411e0364d41030894
Reviewed-on: https://go-review.googlesource.com/85640
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8546431..af330e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,17 +19,14 @@
 set(MCONF2 "LDFLAGS=-L/usr/local/lib")
 endif()
 
-# FIXME: add in URL args for the projects below.
-# URL ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2
-# URL ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
-# URL ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
-
 # Open issue: should the configure cmds below be run with
 # "CC=${CMAKE_BINARY_DIR}/bin/clang"
 
 set(MPCINSTALL ${CMAKE_CURRENT_BINARY_DIR}/external/build-mpc)
+set(MPCLIBDIR "${MPCINSTALL}/lib")
 externalproject_add(libmpc
   URL ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
+  URL_MD5 d6a1d5f8ddea3abd2cc3e98f58352d26
   DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
   BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpc
   CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${MPCINSTALL} ${MCONF1} ${MCONF2}
@@ -41,8 +38,10 @@
   )
 
 set(MPFRINSTALL ${CMAKE_CURRENT_BINARY_DIR}/external/build-mpfr)
+set(MPFRLIBDIR "${MPFRINSTALL}/lib")
 externalproject_add(libmpfr
   URL ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
+  URL_MD5 b8a2f6b0e68bef46e53da2ac439e1cf4
   DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
   BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpfr
   CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${MPFRINSTALL} ${MCONF1} ${MCONF2}
@@ -54,8 +53,10 @@
   )
 
 set(GMPINSTALL ${CMAKE_CURRENT_BINARY_DIR}/external/build-gmp)
+set(GMPLIBDIR "${GMPINSTALL}/lib")
 externalproject_add(libgmp
   URL ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2
+  URL_MD5 86ee6e54ebfc4a90b643a65e402c4048
   DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
   BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/gmp
   CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${GMPINSTALL} ${MCONF1} ${MCONF2}
@@ -105,10 +106,10 @@
 # Record the fact that llvm-goparse depends on these libs
 add_dependencies(llvm-goparse libmpfr libmpc libgmp)
 
-# Add in the archives for the llvm-goparse dependencies.
+# Add in llvm-goparse dependencies.
 target_link_libraries(llvm-goparse
-  ${MPCINSTALL}/lib/libmpc.a
-  ${MPFRINSTALL}/lib/libmpfr.a
-  ${GMPINSTALL}/lib/libgmp.a
-  )
+  "-L${MPCLIBDIR}" "-lmpc"
+  "-L${MPFRLIBDIR}" "-lmpfr"
+  "-L${GMPLIBDIR}" "-lgmp")
+
 
diff --git a/unittests/BackendCore/CMakeLists.txt b/unittests/BackendCore/CMakeLists.txt
index a19d83f..fc15f3f 100644
--- a/unittests/BackendCore/CMakeLists.txt
+++ b/unittests/BackendCore/CMakeLists.txt
@@ -1,14 +1,4 @@
 
-# FIXME: this is a hack way to locate the include dirs
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../llvm-gofrontend)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../llvm-gofrontend/gofrontend/go)
-
-# Note:
-# - at the moment these unit tests only exercise code in Llvm_backend
-#   and related classes, so although we're linking in the gofrontend,
-#   we don't need any of the gofrontend deps (e.g. libgmp etc). If
-#   shared linkage were used, this would have to change.
-
 set(LLVM_LINK_COMPONENTS
   CppGoFrontEnd
   CodeGen
@@ -48,7 +38,7 @@
 
 # Add in the archives for the llvm-goparse dependencies.
 target_link_libraries(GoBackendCoreTests
-  ${MPCINSTALL}/lib/libmpc.a
-  ${MPFRINSTALL}/lib/libmpfr.a
-  ${GMPINSTALL}/lib/libgmp.a
-  )
+  "-L${MPCLIBDIR}" "-lmpc"
+  "-L${MPFRLIBDIR}" "-lmpfr"
+  "-L${GMPLIBDIR}" "-lgmp")
+
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
index f0f90a2..2026079 100644
--- a/unittests/CMakeLists.txt
+++ b/unittests/CMakeLists.txt
@@ -1,5 +1,6 @@
-add_custom_target(GobackendUnitTests)
-set_target_properties(GobackendUnitTests PROPERTIES FOLDER "Tests")
+
+add_custom_target(GoBackendUnitTests)
+set_target_properties(GoBackendUnitTests PROPERTIES FOLDER "Tests")
 
 if (APPLE)
   set(CMAKE_INSTALL_RPATH "@executable_path/../../lib")
@@ -8,8 +9,14 @@
 endif()
 
 function(add_gobackend_unittest test_dirname)
-  add_unittest(GobackendUnitTests ${test_dirname} ${ARGN})
+  add_unittest(GoBackendUnitTests ${test_dirname} ${ARGN})
 endfunction()
 
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../llvm-gofrontend)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../llvm-gofrontend/gofrontend/go)
+
+include_directories(${MPCINSTALL}/include)
+include_directories(${MPFRINSTALL}/include)
+include_directories(${GMPINSTALL}/include)
+
 add_subdirectory(BackendCore)
-add_subdirectory(Parser)
diff --git a/unittests/Parser/CMakeLists.txt b/unittests/Parser/CMakeLists.txt
deleted file mode 100644
index e453d99..0000000
--- a/unittests/Parser/CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-
-# FIXME: this is a hacky way to locate the include dirs
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../llvm-gofrontend)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../llvm-gofrontend/gofrontend/go)
-
-set(LLVM_LINK_COMPONENTS
-  CppGoFrontEnd
-  CodeGen
-  Core
-  Support
-  )
-
-set(ParserTestSources
-  ParserTest.cpp
-  )
-
-add_gobackend_unittest(GoParserTests
-  ${ParserTestSources}
-  )
-
-include_directories(${MPCINSTALL}/include)
-include_directories(${MPFRINSTALL}/include)
-include_directories(${GMPINSTALL}/include)
-
-# Record the fact that llvm-goparse depends on these libs
-add_dependencies(GoBackendCoreTests libmpfr libmpc libgmp)
-
-# Add in the archives for the llvm-goparse dependencies.
-target_link_libraries(GoParserTests
-  ${MPCINSTALL}/lib/libmpc.a
-  ${MPFRINSTALL}/lib/libmpfr.a
-  ${GMPINSTALL}/lib/libgmp.a
-  )
diff --git a/unittests/Parser/ParserTest.cpp b/unittests/Parser/ParserTest.cpp
deleted file mode 100644
index 271e5a0..0000000
--- a/unittests/Parser/ParserTest.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-//===- llvm/tools/gollvm/unittests/BackendCore/BackendCoreTests.cpp -----===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "TestUtils.h"
-#include "gtest/gtest.h"
-#include "go-llvm-backend.h"
-
-using namespace llvm;
-
-namespace {
-
-TEST(ParserTests, ParseFile) {
-  LLVMContext C;
-  std::unique_ptr<Backend> makeit(go_get_backend(C));
-}
-
-}