I want to find GTest
via:
find_package(GTest REQUIRED)
But it is not found:
Error:Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
I know from this link that GTest
should be distributed via standard CMake.
Can you tell me what I did wrong?
If you're on Ubuntu, you should read /usr/share/doc/libgtest-dev/README.Debian
. It says:
The Google C++ Testing Framework uses conditional compilation for some things. Because of the C++ "One Definition Rule", gtest must be compiled with exactly the same flags as your C++ code under test. Because this is hard to manage, upstream no longer recommends using precompiled libraries
So you should compile and install your own version of the gtest
library with the exactly same Compiler Options, and set the GTEST_LIBRARY
or GTEST_ROOT
variable accordingly.
For example, I did the following:
$ mkdir -p ExternalLibs/gTest
$ cd ExternalLibs/gTest
$ cmake /usr/src/gtest
$ make
Then I added the following lines in my CMakeLists.txt
:
set (GTEST_ROOT ${CMAKE_SOURCE_DIR}/ExternalLibs/gTest)
find_package(GTest REQUIRED)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With