This is an archive of the discontinued LLVM Phabricator instance.

cmake: Install gtest lib&headers, to use in stand-alone builds
AbandonedPublic

Authored by mgorny on Aug 27 2016, 7:22 AM.

Details

Summary

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

Diff Detail

Event Timeline

mgorny updated this revision to Diff 69487.Aug 27 2016, 7:22 AM
mgorny retitled this revision from to cmake: Install gtest lib&headers, to use in stand-alone builds.
mgorny updated this object.
mgorny added reviewers: delcypher, Bigcheese, vsk, chapuni.
mgorny added a subscriber: llvm-commits.
mgorny updated this object.Aug 27 2016, 7:26 AM

Turns out it's not that simple. For example, compiler-rt uses LLVM-provided gtest sources to build gtest with different -D flags. I don't know if we would be able to come up with a common gtest build that would satisfy all the projects.

mgorny planned changes to this revision.Sep 11 2016, 12:00 AM
mgorny abandoned this revision.Oct 25 2016, 12:10 PM