catkin_add_gtest will not define a target if gtest is not installed,
but not fail the compile.
Unfortunately the target_link_libraries will then fail the build, i.e:
CMake Warning at /home/dreuter/ros/noetic/install_isolated/share/catkin/cmake/test/gtest.cmake:160 (message):
skipping gtest 'resource_retriever_utest' in project 'resource_retriever'
because gtest was not found
Call Stack (most recent call first):
/home/dreuter/ros/noetic/install_isolated/share/catkin/cmake/test/gtest.cmake:89 (_catkin_add_executable_with_google_test)
/home/dreuter/ros/noetic/install_isolated/share/catkin/cmake/test/gtest.cmake:37 (_catkin_add_google_test)
test/CMakeLists.txt:3 (catkin_add_gtest)
CMake Error at test/CMakeLists.txt:4 (target_link_libraries):
Cannot specify link libraries for target "resource_retriever_utest" which
is not built by this project.
By checking if the target exists before calling target_link_libraries,
we can restore the intended behavior of catkin_add_gtest to "silently"
fail.
catkin_add_gtest
will not define a target ifgtest
is not installed, but not fail the compile. Unfortunately thetarget_link_libraries
will then fail the build, i.e:By checking if the target exists before calling
target_link_libraries
, we can restore the intended behavior ofcatkin_add_gtest
to "silently" fail.