Install gtest & gtest_main libraries and the gtest headers in dedicated subdirectories to support stand-alone builds of external LLVM projects. Use dedicated subdirectories in order to clearly indicate that the files are not parts of the LLVM API and avoid collisions with other packages (and system-wide installs of gtest).
The libraries are installed to 'llvm' subdirectory of library directory, while the headers are installed to 'llvm-gtest' subdirectory of header directory. The library names are unchanged so that all existing rules in LLVM and external projects continue to work. Additional target checks are added to unittests subdirectory to prevent target collisions in
external projects adding the utils/unittest directory to their CMake build.
Full compatibility for existing builds is preserved, both for combined builds of LLVM and subprojects, and for stand-alone builds done using LLVM source directory. In the latter case, the installed gtest library will be preferred over building another one if available. Additionally, it is now possible to do unittest builds in external projects against
installed LLVM after adding the necessary include directory.
Example use in clang: https://reviews.llvm.org/D23959