Skip to content

fix build if no gtest is installed #77

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

Merged
merged 1 commit into from
Apr 22, 2025

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
@sloretz sloretz changed the base branch from kinetic-devel to noetic-devel April 2, 2025 21:20
Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

@sloretz sloretz merged commit ab3119f into ros:noetic-devel Apr 22, 2025
1 check passed
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.

3 participants