I want to use gtest within a CMake project. Previously, I had built gtest and copied the headers and libraries into a location where they could be found in order to overcome the lack of an Ubuntu package to provide the same.
The approach recommended by the gtest developers is to build gtest inside the project that is using it.
However, I would also like to use the functions gtest_add_tests
and gtest_discover_tests
, which are defined in CMake's GoogleTest module.
But find_package(GTest REQUIRED)
fails because the library hasn't been built yet:
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
So it seems like it has to be a two stage process, and there is no way to guarantee compliance with the 'One-Definition Rule'. Do I need to write a custom FindGTest.cmake that defines the functions but doesn't look for the libraries, so that they will only become available after cmake completes and make builds them?