[testsuite] Allow a (custom) linker to be specified.

Differential Revision:  https://reviews.llvm.org/D88061
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 94ae042..7bdee3c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,12 @@
 
 project(test-suite C CXX)
 
+function(append value)
+  foreach(variable ${ARGN})
+    set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
+  endforeach(variable)
+endfunction()
+
 # The test-suite is designed to be built in release mode anyway and
 # falls over unless -DNDEBUG is set.
 if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -156,6 +162,11 @@
 set(CMAKE_EXE_LINKER_FLAGS
     "${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_DIAGNOSE_LINKER_FLAGS}")
 
+if (TESTSUITE_USE_LINKER)
+    append("-fuse-ld=${TESTSUITE_USE_LINKER}"
+    CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAG)
+endif()
+
 # Append extra flags. These extra flags are mainly meant for cache files that
 # want to apply flags that get not override even when the user manually
 # specifies CMAKE_C_FLAGS and similar.