ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

An error occurred while using macro to customize the timeout time of gtest in cmake

asked 2018-10-23 04:20:55 -0500

RachelRen gravatar image

Hi,

I used the following way to customize the timeout time of gtest in cmake, but an error occurred:

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  find_package(InferenceEngine REQUIRED)
  ament_lint_auto_find_test_dependencies()

  macro(custom_gtest target)
    ament_add_gtest(${target} ${ARGN})
    if(TARGET ${target})
      target_include_directories(${target} PUBLIC
        ${${PROJECT_NAME}_INCLUDE_DIRS}
      )
      ament_target_dependencies(${target}
      rclcpp
      InferenceEngine)
    endif()
  endmacro()

  macro(targets)
     custom_gtest(unit_environment
       "tests/unit_environment.cpp"
       TIMEOUT 300)
  endmacro()    
  call_for_each_rmw_implementation(targets)
endif()

The error log:

CMake Error at /home/intel/ros2_ws/install/ament_cmake_gtest/share/ament_cmake_gtest/cmake/ament_add_gtest_executable.cmake:50 (add_executable):
  add_executable cannot create target "unit_environment" because another
  target with the same name already exists.  The existing target is an
  executable created in source directory
  "/home/intel/ros2_overlay_ws/src/ros2_openvino_toolkit/sample".  See
  documentation for policy CMP0002 for more details
Call Stack (most recent call first):
  /home/intel/ros2_ws/install/ament_cmake_gtest/share/ament_cmake_gtest/cmake/ament_add_gtest_executable.cmake:37 (_ament_add_gtest_executable)
  /home/intel/ros2_ws/install/ament_cmake_gtest/share/ament_cmake_gtest/cmake/ament_add_gtest.cmake:66 (ament_add_gtest_executable)
  CMakeLists.txt:199 (ament_add_gtest)
  CMakeLists.txt:211 (custom_gtest)
  /home/intel/ros2_overlay_ws/build/dynamic_vino_sample/call_for_each_rmw_implementation.cmake:1 (targets)
  /home/intel/ros2_ws/install/rmw_implementation_cmake/share/rmw_implementation_cmake/cmake/call_for_each_rmw_implementation.cmake:64 (include)
  CMakeLists.txt:216 (call_for_each_rmw_implementation)

How can I slove this problem?

Thanks very much.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-10-23 11:42:27 -0500

jacobperron gravatar image

The error message makes it clear that the issue is multiple targets of the same name are being created:

add_executable cannot create target "unit_environment" because another target with the same name already exists.

Maybe try changing the following command:

custom_gtest(unit_environment "tests/unit_environment.cpp" TIMEOUT 300)

to

custom_gtest(${targets} "tests/unit_environment.cpp" TIMEOUT 300)

edit flag offensive delete link more
0

answered 2018-11-05 00:55:39 -0500

RachelRen gravatar image

@jacobperron

Thank you for your reply.

This problem is caused by call_for_each_rmw_implementation(targets), it calls the targets once for each DDS implementation.

Thank you.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-10-23 04:20:55 -0500

Seen: 350 times

Last updated: Nov 05 '18