CMakeList for Tests should link against gtest
Closed this issue · 6 comments
Dear maintainers,
on my Ubuntu 18.04 I had to change this line
Line 36 in 23ae27b
to
target_link_libraries(mariadbpp_tests mariadbclientpp gtest_main gtest)
since gtest is not linked into gtest_main on my system (cf. https://stackoverflow.com/a/42191014); else linking would quit with a noteworth amount of "undefined reference to `testing::internal::"-errors.
I am not sure if this introduces issues when gtest was already linked into gtest_main, though (and can't test it). If not, would it be possible to add it in this repo, too?
Thanks
Sebastian
What's your CMake command line? When building with $ cmake -DGTEST_SRC_DIR=/usr/src/googletest/
it's working fine for me on Ubuntu 18.04.
I see. I was using "cmake ." without any further arguments. Is there any reason why to use the Define as a command line option instead of just linking to GTest?
I'm using add_subdirectory for mariadb in my main project and that would require me to put the directory hardcoded in my main CMakeList, I guess?
The find-script tries to detect a global googletest binary installation. As Ubuntu (and other distributions) only provide sources of googletest but no compiled binaries, the script cannot find googletest, so you need to specify a source directory explicitly. The script will then add the sources as an additional CMake subdirectory.
I am wondering why the script detects a binary installation on your system. Did you install googletest manually (in e.g. /usr/local
)?
I'm using add_subdirectory for mariadb in my main project and that would require me to put the directory hardcoded in my main CMakeList, I guess?
No, you do not need to hardcode it in a CMakeLists.txt
. You can also specify it on the CMake command line of the outer project. However, explicitly specifying the path somewhere is necessary.
For googletest I basically followed instructions similiar to these: https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
The outer project currently expects pre-compiled libraries but I can try to rework that to the find-script, too, I guess?
Yes, you can. All you need is adding include(FindOrBuildGTest)
and linking against the gtest targets.
Well, that seems to work (even without manually defining the gtest source directory). Thanks for your help.