How to associate CMakeLists and Aravis

I tried to use aravis in ROS2, but despite adding paths in CMakelists, I still can’t get the library to link in. I also used the suggestion “pkg-config” at the beginning but the return report was “No such file or directory”.

Here is my CMakelists.txt, I don’t know where is the problem, I hope someone can give me some advice.

cmake_minimum_required(VERSION 3.5)
project(camera_aravis)

if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

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()

INCLUDE_DIRECTORIES(/usr/local/include/aravis-0.8 
/home/nian/Documents/Dep/glib-2.45.2/glib
/home/nian/Documents/Dep/glib-2.45.2
/home/nian/Documents/Dep/glib-2.45.2/gmodule
/opt/ros/foxy/include
/home/nian/Documents/Dep/xmlrpcpp-master/include/xmlrpcpp
/home/nian/Documents/Dep/xmlrpcpp-master/include

)
LINK_DIRECTORIES(/usr/lib /home/nian/Documents/Dep/glib-2.45.2/glib
)
ADD_EXECUTABLE(camnode src/new.cpp)
TARGET_LINK_LIBRARIES(camnode libaravis-0.8.so libglib-2.0.so libgio-2.0.so
libgobject-2.0.so)

include_directories(
 include_directories
 ${fcl_INCLUDE_DIRS}
)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(camera_info_manager REQUIRED)
find_package(image_transport REQUIRED)

                                                                                                         
                                                                                                                                          
add_executable(test_params_rclcpp src/new.cpp)
ament_target_dependencies(test_params_rclcpp
rclcpp
rclcpp_components
sensor_msgs
std_msgs
camera_info_manager
image_transport
camera_calibration_parsers)

install(TARGETS
  test_params_rclcpp
  DESTINATION lib/${PROJECT_NAME}
)

add_executable(camera_param_edit src/new.cpp)
ament_target_dependencies(camera_param_edit 
rclcpp
rclcpp_components
sensor_msgs
std_msgs
camera_info_manager
image_transport
camera_calibration_parsers)

install(TARGETS
  camera_param_edit
  DESTINATION lib/${PROJECT_NAME}
)

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

ament_package()

Hi,

I don’t know much cmake. In the past I have used something like:

find_package(PkgConfig REQUIRED)

set(DEPENDENCIES "gobject-2.0" "glib-2.0" "aravis-0.8")
pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET ${DEPENDENCIES})

Then in your case:

target_link_libraries(camnode PUBLIC PkgConfig::DEPS)

Hope it helps.

I use something like this (handles both aravis-0.8 but also older aravis-0.6):

find_package(PkgConfig REQUIRED)
pkg_check_modules(ARAVIS aravis-0.8)
if(NOT ARAVIS_FOUND)
	pkg_check_modules(ARAVIS REQUIRED aravis-0.6)
	find_library(ARAVIS_LIBRARIES aravis-0.6 REQUIRED)
else()
	find_library(ARAVIS_LIBRARIES aravis-0.8 REQUIRED)
endif()

and then for your target:

target_include_directories(target PUBLIC ${ARAVIS_INCLUDE_DIRS})
target_link_directories(target PUBLIC ${ARAVIS_LIBRARY_DIRS})
target_link_libraries(target PUBLIC ${ARAVIS_LIBRARIES})

I suppose one could create CMake target in a proper way, like this (untested):

add_library(Aravis::Aravis UNKNOWN IMPORTED)
set_target_properties(Aravis::Aravis PROPERTIES
	INTERFACE_INCLUDE_DIRECTORIES "${ARAVIS_INCLUDE_DIRS}"
	INTERFACE_LINK_LIBRARIES "${ARAVIS_LIBRARIES}"
	# how to specify linker paths? mmm...
)
# and then say just this
target_link_libraries(target PRIVATE Aravis::Aravis)

Meson has a module for exporting CMake targets; just saying :wink:

Thank you very much for your help, I will try it. Hope that solves my problem🥰

Eudoxos via Aravis Project <notifications@aravis-project.discoursemail.com>于2022年5月23日 周一12:12写道: