CMake

ROS users will recognize that a lot of the below CMake file is similar in structure to most ROS packages.

First, we use find_package to add OpenCV and the ROS dependencies that the tutorial needs. Details on the other packages that need to be built in the catkin workspace can be found in the ROS workspace section.

Afterwards, we add_executable with the source files. Then, we target_link_libraries and include_directories in order to link OpenCV and ROS dependencies against the executable.

Finally, we install the targets and supporting directories with launch files in the CATKIN_PACKAGE_LIB_DESTINATION.

The entire CMakeLists.txt below.

cmake_minimum_required(VERSION 3.14)

project(smartcapture_ros1 DESCRIPTION "Scale Smart Capture ROS1 Example")

find_package(OpenCV 4.5.0 REQUIRED)
find_package(catkin REQUIRED COMPONENTS
        roscpp
        sensor_msgs
        cv_bridge
        std_msgs
        image_transport
        darknet_ros_msgs)

catkin_package(
        CATKIN_DEPENDS
        roscpp
        sensor_msgs
        cv_bridge
        std_msgs
        image_transport
        darknet_ros_msgs)

set(SOURCES
        src/ros1_lidar.cpp
        src/main.cpp

        include/ros1_lidar.hpp)

add_executable(smartcapture_cpp_ros1_lidar ${SOURCES})

target_link_libraries(smartcapture_cpp_ros1_lidar PUBLIC smartcapture-cpp ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})

include_directories(include/ ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})

install(TARGETS
        smartcapture_cpp_ros1_lidar
        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

install(DIRECTORY
        launch
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})


Did this page help you?