diff --git a/third-party/unittest/UnitTestMain/CMakeLists.txt b/third-party/unittest/UnitTestMain/CMakeLists.txt
--- a/third-party/unittest/UnitTestMain/CMakeLists.txt
+++ b/third-party/unittest/UnitTestMain/CMakeLists.txt
@@ -1,3 +1,8 @@
+set(BUILDTREE_ONLY BUILDTREE_ONLY)
+if (LLVM_INSTALL_GTEST)
+  set(BUILDTREE_ONLY "")
+endif ()
+
 add_llvm_library(llvm_gtest_main
   TestMain.cpp
 
@@ -7,6 +12,5 @@
   LINK_COMPONENTS
   Support # Depends on llvm::cl
 
-  # This library is not meant to be in the install tree, only the build tree.
-  BUILDTREE_ONLY
+  ${BUILDTREE_ONLY}
   )