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 when included with cmake_add_subdirectory #32

Open
wants to merge 5 commits into
base: rolling
Choose a base branch
from

Conversation

rotu
Copy link
Contributor

@rotu rotu commented Oct 22, 2019

Currently breaks when built as a sub-project. This fixes that.

@rotu rotu force-pushed the pr-1 branch 2 times, most recently from 8365d53 to 474fdb5 Compare October 22, 2019 20:18
@rotu rotu changed the title Fix build when included with cmake_add_subdirectory WIP: Fix build when included with cmake_add_subdirectory Oct 23, 2019
@rotu
Copy link
Contributor Author

rotu commented Oct 23, 2019

still broken:

-- Build files have been written to: /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted
[100%] Built target googletest
-- Found PythonInterp: /usr/bin/python3 (found version "3.6.8") 
CMake Error at /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/cmake/internal_utils.cmake:149 (add_library):
  add_library cannot create target "gtest" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory "/opt/ros/master/install/src/gtest_vendor".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/cmake/internal_utils.cmake:172 (cxx_library_with_type)
  /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/CMakeLists.txt:90 (cxx_library)


CMake Error at /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/cmake/internal_utils.cmake:149 (add_library):
  add_library cannot create target "gtest_main" because another target with
  the same name already exists.  The existing target is a static library
  created in source directory "/opt/ros/master/install/src/gtest_vendor".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/cmake/internal_utils.cmake:172 (cxx_library_with_type)
  /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/CMakeLists.txt:91 (cxx_library)


CMake Error at /tmp/cmake-build-eloquent-debug/src/osrf/osrf_testing_tools_cpp/osrf_testing_tools_cpp/googletest-1.8.0-extracted/googletest-1.8.0-src/googletest/CMakeLists.txt:92 (target_link_libraries):
  Attempt to add link library "gtest" to target "gtest_main" which is not
  built in this directory.

  This is allowed only when policy CMP0079 is set to NEW.

@rotu
Copy link
Contributor Author

rotu commented Oct 23, 2019

@nuclearsandwich why do both both this and https://github.com/ament/googletest provide googletest?

@nuclearsandwich
Copy link
Member

@nuclearsandwich why do both both this and ament/googletest provide googletest?

I haven't the foggiest idea.

Working backwards from what I do know, I don't believe this package "provides" googletest but rather keeps its own copy as this is a pure CMake package not an ament_cmake package and so does not use the ament set of packages for testing. A quick browse through the package CMake code suggests that this is how googletest upstream recommends that source be included into consuming projects.

@rotu rotu changed the title WIP: Fix build when included with cmake_add_subdirectory Fix build when included with cmake_add_subdirectory Oct 24, 2019
@wjwwood
Copy link
Member

wjwwood commented Apr 21, 2020

@rotu this package was meant to be used outside of ROS 2 as well as within it, and therefore doesn't depend on ament or the ament mechanisms for googletest. It would be possible for ament to use this, but it's currently not the case.

@wjwwood
Copy link
Member

wjwwood commented Apr 21, 2020

I just came across this when cleaning up some other issues, I'll see about incorporating this in the next release.

@rotu
Copy link
Contributor Author

rotu commented Apr 21, 2020

Thanks, @wjwwood. For your convenience, I've resolved merge conflicts.

Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

@rotu sorry for the delay, but I had one question after re-reviewing it.

@@ -45,6 +45,9 @@ set(OSRF_TESTING_TOOLS_CPP_REQUIRE_GOOGLETEST_VERSION_SETUP)
# @public
#
macro(osrf_testing_tools_cpp_require_googletest)
if (TARGET gtest OR TARGET gtest_main)
return()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? I assume there was a duplicate target, but honestly I'm not sure this is the right way to handle it. If the target already exists then either osrf_testing_tools_cpp_require_googletest() was called more than once (which is explicitly not allowed) or it was created by another piece of CMake logic, which is also bad, since it might not have the version osrf_testing_tools_cpp_require_googletest() would have given.

@clalancette clalancette changed the base branch from master to rolling March 8, 2023 21:56
@clalancette clalancette requested a review from gbiggs as a code owner March 8, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants