0

I am compiling the plugins on the ros:humble-desktop docker.

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.8)
project(my_plugins)

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

set(PLUGIN_LIB my_plugins_lib)
set(PACKAGE_BASENAME "my-rviz-plugins")

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rviz_common REQUIRED)
find_package(rviz_rendering REQUIRED)
find_package(rviz_default_plugins REQUIRED)
find_package(rviz_ogre_vendor REQUIRED)
find_package(my_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core)
find_package(Git)

# Generate ROS2 package and underlying interfaces
set(COMPONENT_NAME "rviz-plugins")
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "${COMPONENT_NAME}")

if (GIT_FOUND)
    execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags
            WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
            OUTPUT_VARIABLE PLUGIN_GIT_TAG
            OUTPUT_STRIP_TRAILING_WHITESPACE
            )

    if (PLUGIN_GIT_TAG MATCHES "^v([0-9]+)[.]([0-9]+)[.]([0-9]+)(-[0-9]+)?$" )
        set(PLUGIN_MAJOR_VERSION ${CMAKE_MATCH_1})
        set(PLUGIN_MINOR_VERSION ${CMAKE_MATCH_2})
        set(PLUGIN_PATCH_VERSION ${CMAKE_MATCH_3})
        set(PLUGIN_RC_VERSION    ${CMAKE_MATCH_4})
    else()
        message("--- Git tag isn't a valid semantic version: [${PLUGIN_GIT_TAG}], default to 1.0.0")
        set(PLUGIN_MAJOR_VERSION 1)
        set(PLUGIN_MINOR_VERSION 0)
        set(PLUGIN_PATCH_VERSION 0)
        set(PLUGIN_RC_VERSION    0)
    endif()
endif (GIT_FOUND)


set(PLUGIN_VERSION
    "${PLUGIN_MAJOR_VERSION}.${PLUGIN_MINOR_VERSION}.${PLUGIN_PATCH_VERSION}${PLUGIN_RC_VERSION}")

message( "version: ${PLUGIN_GIT_TAG}  ${PLUGIN_VERSION}")


# Adds shallow folders containing ogre_media such as meshes and scripts to Rviz
# so that they can be found at runtime. Requires rviz_rendering.
register_rviz_ogre_media_exports(
  DIRECTORIES
  "assets"
  "assets/policy_img"
)

set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/my_plugins)
set(PLUGIN_LIB_HEADERS
  ${INCLUDE_DIR}/displays/h1.hpp
  ${INCLUDE_DIR}/displays/h2.hpp
  ${INCLUDE_DIR}/displays/h3.hpp
  ${INCLUDE_DIR}/displays/h4.hpp

)

message(${PLUGIN_LIB_HEADERS})

foreach(header "${PLUGIN_LIB_HEADERS}")
  qt5_wrap_cpp(PLUGIN_LIB_FILES "${header}")
endforeach()

set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(PLUGIN_LIB_SRC
  ${SRC_DIR}/displays/h1.cpp
  ${SRC_DIR}/displays/h2.cpp
  ${SRC_DIR}/displays/h3.cpp
  ${SRC_DIR}/displays/h4.cpp

)

add_library(${PLUGIN_LIB} SHARED
  ${PLUGIN_LIB_FILES}
  ${PLUGIN_LIB_SRC}
)

target_include_directories(${PLUGIN_LIB} PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include/${PLUGIN_LIB}>
  ${Qt5Widgets_INCLUDE_DIRS}
)

#[[ TODO: add function for returning rosidl_get_type_support_target() ]]
set(typesupport_target "my_msgs::my_msgs__rosidl_typesupport_cpp")

target_include_directories(${PLUGIN_LIB} PUBLIC ${include_directories})

target_link_libraries(${PLUGIN_LIB} PUBLIC
  rviz_ogre_vendor::OgreMain
  rviz_ogre_vendor::OgreOverlay
  ${typesupport_target}
)

# prevent pluginlib from using boost
target_compile_definitions(${PLUGIN_LIB} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

pluginlib_export_plugin_description_file(rviz_common plugins_description.xml)

ament_target_dependencies(${PLUGIN_LIB}
  PUBLIC
  rclcpp
  resource_retriever
  rviz_common
  rviz_rendering
  rviz_ogre_vendor
  )

ament_export_include_directories(include)
ament_export_targets(${PLUGIN_LIB} HAS_LIBRARY_TARGET)
ament_export_dependencies(
  rviz_common
  rclcpp
  resource_retriever
  rviz_ogre_vendor
  rosidl_default_runtime
)
ament_package()

# get - git sha
execute_process(COMMAND  git log -1 --pretty=tformat:"%H" OUTPUT_VARIABLE PLUGIN_GIT_SHA ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
set(VERSION_FILE "${CMAKE_BINARY_DIR}/${PACKAGE_BASENAME}.txt")

file(WRITE ${VERSION_FILE}
                "Version:\t${PLUGIN_VERSION}\n" )
file(APPEND ${VERSION_FILE}
                "Git-SHA:\t${PLUGIN_GIT_SHA}\n" )

set(CONFIG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/config/config1.rviz
                 ${CMAKE_CURRENT_SOURCE_DIR}/config/cnfig2.rviz  )

set(ASSETS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assets)

install(
  TARGETS ${PLUGIN_LIB}
  EXPORT ${PLUGIN_LIB}
  ARCHIVE DESTINATION lib COMPONENT ${COMPONENT_NAME}
)

install (FILES ${CONFIG_FILES} DESTINATION /opt/ros/humble/config/${PROJECT_NAME})

install (DIRECTORY ${ASSETS_DIR}  DESTINATION /opt/ros/humble/share/${PROJECT_NAME})

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../prebuilts.txt DESTINATION /opt/ros/humble/version/${PROJECT_NAME}   COMPONENT ${COMPONENT_NAME})
install(FILES ${VERSION_FILE}  DESTINATION /opt/ros/humble/version/${PROJECT_NAME} COMPONENT ${COMPONENT_NAME})

set(CPACK_PACKAGE_VENDOR  "package")
set(CPACK_PACKAGE_CONTACT "my@gmail.com")
set(CPACK_PACKAGE_VERSION_MAJOR "${PLUGIN_MAJOR_VERSION}")
set(CPACK_PACKAGE_VERSION_MINOR "${PLUGIN_MINOR_VERSION}")
set(CPACK_PACKAGE_VERSION_PATCH "${PLUGIN_PATCH_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "my-rviz-plugins-v${PLUGIN_VERSION}")

set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_DEBIAN_FILE_NAME    "${PACKAGE_BASENAME}-v${PLUGIN_VERSION}_amd64.deb")
set(CPACK_DEBIAN_PACKAGE_NAME "${PACKAGE_BASENAME}")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "my-RViz-Plugins")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_SECTION "util")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
set(CPACK_DEBIAN_RVIZ-PLUGINS_PACKAGE_DEPENDS "ros-humble-fastrtps, ros-humble-rmw-fastrtps-cpp, ros-humble-rviz-common, ros-humble-rclcpp, ros-humble-resource-retriever, ros-humble-rviz-ogre-vendor,  ros-humble-rosidl-default-runtime  ")

set(CPACK_DEBIAN_RVIZ-PLUGINS_PACKAGE_SHLIBDEPS ON)

set(CPACK_GENERATOR "DEB")

include(CPack)
cpack_add_component(${COMPONENT_NAME}    DISPLAY_NAME "my  : RViz-plugins")


find_package(GTest REQUIRED)

add_subdirectory(tests)

my compile commands are :

source /opt/ros/humble/local_setup.bash
mkdir -p build && cd build
cmake -DCMAKE_PREFIX_PATH=/opt/ros/humble/share/   ../ && make -j4  DESTDIR=../install install
cpack -D CPACK_COMPONENTS_ALL=rviz-plugins  -G DEB -D CPACK_PACKAGING_INSTALL_PREFIX=/opt/ros/humble

And there are examples of errors that I am getting.

usr/include/x86_64-linux-gnu/qt5/QtWidgets/qwidget.h:673:13: error: ‘QVariant’ does not name a type
  673 |     virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;

/usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:782:97:   required from here
/usr/include/x86_64-linux-gnu/qt5/QtCore/qvariant.h:879:62: error: ‘invoke’ is not a member of ‘QtPrivate::QVariantValueHelperInterface<QtMetaTypePrivate::QSequentialIterableImpl>’
  879 |     return QtPrivate::QVariantValueHelperInterface<T>::invoke(v);


/opt/ros/humble/include/rviz_common/rviz_common/properties/ros_topic_property.hpp: In member function ‘std::string rviz_common::properties::RosTopicProperty::getTopicStd() const’:
/opt/ros/humble/include/rviz_common/rviz_common/properties/ros_topic_property.hpp:68:11: error: ‘getValue’ was not declared in this scope; did you mean ‘setValue’?
   68 |   {return getValue().toString().toStdString();}


/usr/include/x86_64-linux-gnu/qt5/QtGui/qcursor.h:83:15: error: expected ‘)’ before numeric constant
   83 |     QCursor(Qt::CursorShape shape);

/usr/include/x86_64-linux-gnu/qt5/QtWidgets/qsizepolicy.h:151:14: error: expected type-specifier before ‘QVariant’
  151 |     operator QVariant() const;

I have tried compiling example plugins Ive found on github such as https://github.com/LKSeng/rviz2_rotatable_image_plugin and it compiled successfully. Ive even tried adding the problematic headers into the example code here and it still compiled successfully.

Therefore I dont think its my environment and I dont think my code is the issue, I think its how I am compiling. Please let me know if you have any ideas what could be wrong.

0 Answers0