Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CMake install rules for gtest libraries and headers
- Loading branch information
Showing
1 changed file
with
8 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98d988d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My cmake project uses googletest via
add_subdirectory(external/googletest/googletest)
. I'm probably not the only one who does this.After updating to the latest googletest, my project's
make install
target is installing googletest files into /usr/include and /usr/lib. I do not want the gtest files to be installed with my project; I doubt my customers do either.Is there a reason the install code was added and is turned on by default? Could install be made optional and default to off?
Thanks.
98d988d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bundling the build system of another project into your project this way is a simple but fragile approach. Any number of valid upstream changes in the googletest CMake project could break your project. It could have defined target name that collided with a target name in your project for example.
Adding an install target is also completely valid for GTest to do. The lack of an install target until now was a bug that contributed to the rise of the add_subdirectory approach. For example: http://stackoverflow.com/questions/9689183
An install target that is disabled by default is bizarre. I've never needed to opt-in for
make install
to work. But I don't see why an option that is enabled by default couldn't be added.It will cost you a few more lines of CMake code, but the more robust way to pull in GTest is with the
ExternalProject
module. Either with a superbuild like:Or with an IMPORTED target like:
When I get a chance, I'll submit a follow up patch that installs a
GTestConfig.cmake
withIMPORTED
targets so that the superbuild+find_package approach automatically gets the same convenience of doingtarget_link_libraries(foo GTest::gtest)
.98d988d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nocnokneo Sorry for been late, but is this statement no longer true?
https://github.com/google/googletest/blob/master/googletest/Makefile.am#L305
Why cmake adding install rules, while makefiles still have install target disabled?
98d988d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't speak for the GTest team, but I can give you some background.
The opinion of the GTest team is that GTest should always be built by the consuming project so that GTest can be built with the exact same compiler, compiler flags, libraries, etc.
The case I made for adding install rules to the CMake build was that "super builds" are a common way to structure CMake-based projects which satisfies the need to compile GTest with all the same compile flags. But super builds are much simpler to use when the external projects like GTest have proper install rules setup (the super build uses the install rules to install external projects into a staging directory within the build directory)