[ROS2] cmake can't find ament_gtest
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>