Googletest: Making googletest a CMake package

Created on 18 Sep 2016  路  4Comments  路  Source: google/googletest

Starting from CMake 3.0, some functionality has been made to export the targets in one build or installation tree to be imported by other CMake projects conveniently, through a config file. It seems that currently googletest has not started to take advantage of this. Could anyone help me if such additions are desired? If yes, I guess I can submit a PR for it. A side effect of this is that the minimum version of make required has to be bumped to at least 3.0. I am not quite sure if it is allowed.

Since googletest is not advised to be installed system-wide, this could possibly make it easier for users to have multiple googletest installations to be imported for different projects. Also this could be helpful to enforce certain compiler settings for things that is going to be linked against googletest.

Most helpful comment

PR #1338 should address this issue.

All 4 comments

Take a look at this fork. We already did this here to make GoogleTest work with the hunter package manager. One could simply merge this to the trunk.

This would be really nice to have. It looks like pull request #768 would resolve this.

I also think it would be really nice to have a modern CMake package (GTestConfig.cmake) provided by Google Test. If this is added to Google Test CMake could get rid of the "legacy" find module FindGTest. The latest FindGTest.cmake file shipped with CMake does not even support Google Mock, therefore I have to use a custom find module (which is horrible, imo).

I know that the suggested approach (suggested by the Google Test authors) to incorporate Google Test into a CMake project is to use the add_subdirectory command, but that forces a client to add Google Test as a submodule (a.k.a. shared subproject).

I highly suggest to support both approaches:

  1. add_subdirectory to be able to add GTest as a submodule and built it together with the using project (already supported).
  2. CMake package to be able to add GTest/GMock as a (prebuilt) dependency with a find_package(GoogleTest 1.8.0 REQUIRED CONFIG) or find_package(GTest 1.8.0 REQUIRED CONFIG) command. I would prefer the former, though that would be incompatible to the old oneGTest` - maybe use an alias.

IMO the source code linked in the answers of this issue should be sufficient to add that feature without much problems/risk.

PR #1338 should address this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robindegen picture robindegen  路  4Comments

kdawgwilk picture kdawgwilk  路  3Comments

AstralStorm picture AstralStorm  路  4Comments

marknelson picture marknelson  路  4Comments

ElectricRCAircraftGuy picture ElectricRCAircraftGuy  路  4Comments