Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build if no gtest is installed #77

Open
wants to merge 1 commit into
base: kinetic-devel
Choose a base branch
from

Conversation

dreuter
Copy link

@dreuter dreuter commented May 9, 2022

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 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.
@ahcorde ahcorde added the ros1 label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants