google-cloud-cpp icon indicating copy to clipboard operation
google-cloud-cpp copied to clipboard

Support installing test libraries that are not header only

Open dbolduc opened this issue 1 year ago • 0 comments

In #13546 we made bigtable_mocks header only. We did this to work around a problem.

CMake complained when we tried to export google_cloud_cpp_bigtable_mocks because it cannot find the linked library: GTest::gmock_main. This problem does not come up with interface (header only) libraries.

Finding GTest/GMock can be complicated. We have a helper that defines missing targets, but note that it only does anything if (BUILD_TESTING). Also, we don't really want to Find(GTest) when building our libraries normally.

https://github.com/googleapis/google-cloud-cpp/blob/48644a71701a5f7c8cd19b658b0356b51bfe5398/cmake/FindGMockWithTargets.cmake#L98-L100

Also, we decided[^1] that we always want to install the mocks (vs. adding another parameter to the CMake configuration). Regardless, we know BUILD_TESTING should not determine whether the mocks are installed. BUILD_TESTING is more for building our unit tests, integration tests, etc.

Part of the problem is that in our cmake-install build, we build with -DBUILD_TESTING=OFF. Of course, this is what most customers will be doing.

[^1]: This decision may be worth revisiting, although I already released a version of google-cloud-cpp that installs mocks without heeding some extra flag :shrug:

dbolduc avatar Feb 02 '24 19:02 dbolduc