Ask Your Question
0

[ROS2] cmake can't find ament_gtest

asked 2020-01-07 04:11:17 -0600

frpunzalan gravatar image

updated 2020-01-07 19:30:08 -0600

I am trying to create a new package and some unit tests for that package. In the cmake option, I put the find_package(ament_gtest REQUIRED) line to make sure that the system can use gtest. However, it looks like cmake can't find the ament_gtest package and I am getting the following error

--- stderr: configurator
CMake Error at CMakeLists.txt:43 (find_package):
  By not providing "Findament_gtest.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "ament_gtest", but CMake did not find one.

  Could not find a package configuration file provided by "ament_gtest" with
  any of the following names:

    ament_gtestConfig.cmake
    ament_gtest-config.cmake

  Add the installation prefix of "ament_gtest" to CMAKE_PREFIX_PATH or set
  "ament_gtest_DIR" to a directory containing one of the above files.  If
  "ament_gtest" provides a separate development package or SDK, be sure it
  has been installed.

the cmakelist file that i use is the following

cmake_minimum_required(VERSION 3.5)
project(configurator)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

add_executable(configurator_node src/configurator_node.cpp)
target_include_directories(configurator_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)

install(TARGETS configurator_node
  EXPORT export_${PROJECT_NAME}
  DESTINATION lib/${PROJECT_NAME})

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

  find_package(ament_gtest REQUIRED)

  # Add a gtest executables
  ament_add_gtest(${PROJECT_NAME}-test
    test/test_configurator.cpp
  )
  if(TARGET ${PROJECT_NAME}-test)
    target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
  endif()

endif() # BUILD_TESTING

ament_package()

Edit:

Here is my package.xml file

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>configurator</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="root@todo.todo">root</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  <test_depend>ament_cmake_gtest</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-07 04:34:23 -0600

marguedas gravatar image

updated 2020-01-08 01:43:06 -0600

The package providing the CMake macro ament_add_gtest is ament_cmake_gtest

This is the one to find_package in the CMakeLists and to add as a test_depend in the package.xml

Edit:

I already put the ament_cmake_gtest in the package.xml

Did you also change the name in the CMakeLists as suggested above?

Replace

find_package(ament_gtest REQUIRED)

With

find_package(ament_cmake_gtest REQUIRED)

and i still get the error.

What error do you get after the change?

maybe i have something missing in the ros install, i only installed eloquent-ros-core and eloquent-ros-base.

ros_core provides ament_cmake-gtest so there shouldnt be a need to install any additional package

edit flag offensive delete link more

Comments

Hi @marguedas, thanks for the quick reply. I also thought it was the package file but I already put the ament_cmake_gtest in the package.xml and i still get the error. maybe i have something missing in the ros install, i only installed eloquent-ros-core and eloquent-ros-base.

frpunzalan gravatar imagefrpunzalan ( 2020-01-07 19:16:21 -0600 )edit

please edit your original question instead of posting another answer to provide more information

marguedas gravatar imagemarguedas ( 2020-01-08 01:36:00 -0600 )edit

sorry I was a bit slow to pick up what your original answer meant. It now works if I change the name in the CMakeList.

frpunzalan gravatar imagefrpunzalan ( 2020-01-08 03:01:01 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-01-07 04:11:17 -0600

Seen: 40 times

Last updated: Jan 08