Skip to content

Commit

Permalink
Upgrade from tinyxml to tinyxml2 (ros#186)
Browse files Browse the repository at this point in the history
* upgrade from tinyxml to tinyxml2

* Remove 'using tinyxml2'

* Update github actions.

* Add in FindTinyXML2 for systems that don't have it.

* Make sure that tinyxml2::tinyxml2 is available in downstream packages

* Update urdfdom-config.cmake.in

* Replace InsertNewChildElement with GetDocument()->NewElement.

The former doesn't exist in older TinyXML2, and is just
a convenience function anyway.

* Fix generation of CMake config files.

Use the provided CMake primitives for this, which should
make it work in all situations.

* Install the FindTinyXML2.cmake file.

This is so downstream projects can always find it.

* Backup and restore the CMAKE_MODULE_PATH.

So we don't permanently manipulate it.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Co-authored-by: Silvio Traversaro <silvio@traversaro.it>
Signed-off-by: harleylara <harley.lara@outlook.com>
  • Loading branch information
2 people authored and harleylara committed Feb 15, 2024
1 parent 134b839 commit bde3e64
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 366 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ros1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ on:
jobs:
build_ros1:
name: ROS1 CI
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- uses: ros-tooling/setup-ros@v0.2
- uses: ros-tooling/setup-ros@v0.7
with:
required-ros-distributions: melodic
- uses: ros-tooling/action-ros-ci@v0.2
required-ros-distributions: noetic
- uses: ros-tooling/action-ros-ci@v0.3
with:
package-name: urdfdom
target-ros1-distro: melodic
target-ros1-distro: noetic
14 changes: 7 additions & 7 deletions .github/workflows/ros2.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: urdfdom ROS2 CI
name: urdfdom ROS 2 CI

on:
push:
Expand All @@ -8,13 +8,13 @@ on:
jobs:

build_ros2:
name: ROS2 CI
runs-on: ubuntu-20.04
name: ROS 2 CI
runs-on: ubuntu-22.04
steps:
- uses: ros-tooling/setup-ros@v0.2
- uses: ros-tooling/setup-ros@v0.7
with:
required-ros-distributions: galactic
- uses: ros-tooling/action-ros-ci@v0.2
required-ros-distributions: rolling
- uses: ros-tooling/action-ros-ci@v0.3
with:
package-name: urdfdom
target-ros2-distro: galactic
target-ros2-distro: rolling
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
cxx: "g++",
}
- {
name: "Ubuntu Bionic GCC",
os: ubuntu-18.04,
name: "Ubuntu Focal GCC",
os: ubuntu-20.04,
build_type: "Release",
cc: "gcc",
cxx: "g++",
Expand All @@ -44,7 +44,7 @@ jobs:
run: |
sudo apt-get -qq update
sudo apt-get -qq upgrade -y
sudo apt-get -qq install -y build-essential cmake libconsole-bridge-dev liburdfdom-headers-dev libtinyxml-dev
sudo apt-get -qq install -y build-essential cmake libconsole-bridge-dev liburdfdom-headers-dev libtinyxml2-dev
cmake --version
gcc --version
Expand Down
44 changes: 27 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,9 @@ endif (MSVC OR MSVC90 OR MSVC10)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

find_package(tinyxml_vendor QUIET)
find_package(TinyXML)
# bionic has not cmake module, workaround
if (NOT TinyXML_FOUND AND UNIX)
include(FindPkgConfig)
pkg_check_modules (TinyXML tinyxml)
else()
# Make it fail in platforms without pkgconfig
find_package(TinyXML REQUIRED) # bionic has not cmake module
endif()
find_package(tinyxml2_vendor QUIET)
find_package(TinyXML2 REQUIRED)

find_package(urdfdom_headers 1.0 REQUIRED)
find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it.
find_package(console_bridge REQUIRED)
Expand All @@ -78,25 +71,42 @@ add_subdirectory(urdf_parser)

set(PKG_NAME ${PROJECT_NAME})
set(PKG_LIBRARIES urdfdom_sensor urdfdom_model_state urdfdom_model urdfdom_world)
set(PKG_DEPENDS urdfdom_headers console_bridge)
set(PKG_DEPENDS TinyXML2 urdfdom_headers console_bridge)
set(PKG_EXPORTS urdfdom)
set(cmake_conf_file "cmake/urdfdom-config.cmake")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${cmake_conf_file}.in" "${CMAKE_BINARY_DIR}/${cmake_conf_file}" @ONLY)
set(cmake_conf_file "cmake/urdfdom-config")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}Version.cmake"
VERSION ${URDF_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file("${cmake_conf_file}.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}.cmake"
INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}Version.cmake"
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR}
)

# Some operating systems (like Ubuntu 22.04) do not provide a default
# way to find TinyXML2. For that reason, this package provides it
install(FILES cmake/FindTinyXML2.cmake
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR})

install(FILES package.xml DESTINATION share/${PROJECT_NAME})
install(FILES ${CMAKE_BINARY_DIR}/${cmake_conf_file}
DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} COMPONENT cmake)

# Make the package config file
set(PKG_DESC "Unified Robot Description Format")
set(PKG_DEPENDS "urdfdom_headers console_bridge") # make the list separated by spaces instead of ;
set(PKG_DEPENDS "tinyxml2 urdfdom_headers console_bridge") # make the list separated by spaces instead of ;
set(PKG_URDF_LIBS "-lurdfdom_sensor -lurdfdom_model_state -lurdfdom_model -lurdfdom_world")
set(pkg_conf_file "cmake/pkgconfig/urdfdom.pc")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${pkg_conf_file}.in" "${CMAKE_BINARY_DIR}/${pkg_conf_file}" @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/${pkg_conf_file}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ COMPONENT pkgconfig)



# Add uninstall target
# Ref: http://www.cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
configure_file(
Expand Down
74 changes: 0 additions & 74 deletions cmake/FindTinyXML.cmake

This file was deleted.

78 changes: 78 additions & 0 deletions cmake/FindTinyXML2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# TinyXML2_FOUND
# TinyXML2_INCLUDE_DIRS
# TinyXML2_LIBRARIES

# try to find the CMake config file for TinyXML2 first
if(NOT TinyXML2_FOUND)
find_package(TinyXML2 CONFIG QUIET)
endif()
if(TinyXML2_FOUND)
message(STATUS "Found TinyXML2 via Config file: ${TinyXML2_DIR}")
if(NOT TINYXML2_LIBRARY)
# in this case, we're probably using TinyXML2 version 5.0.0 or greater
# in which case tinyxml2 is an exported target and we should use that
if(TARGET tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)
elseif(TARGET tinyxml2::tinyxml2)
set(TINYXML2_LIBRARY tinyxml2::tinyxml2)
elseif(TinyXML2_FIND_REQUIRED)
message(FATAL_ERROR "Unable to determine target for TinyXML2")
endif()
list(APPEND TinyXML2_TARGETS ${TINYXML2_LIBRARY})
else()
# Only perform that logic once
if(NOT TARGET tinyxml2::tinyxml2)
# TINYXML2_LIBRARY is composed of debug;<path\to\debug.lib>;optimized;<path\to\release.lib>
# we have to extract the appropriate component based on the current configuration.
list(LENGTH TINYXML2_LIBRARY TINYXML_LIBRARY_LIST_LENGTH)
if(NOT ${TINYXML_LIBRARY_LIST_LENGTH} EQUAL 4)
message(FATAL_ERROR "Unable to extract the library file path from ${TINYXML2_LIBRARY}")
endif()
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
list(GET TINYXML2_LIBRARY 0 ASSERT_DEBUG)
if(NOT ${ASSERT_DEBUG} STREQUAL "debug")
message(FATAL_ERROR "could not parse debug library path from ${TINYXML2_LIBRARY}")
endif()
list(GET TINYXML2_LIBRARY 1 TINYXML2_LIBRARY_PATH)
else()
list(GET TINYXML2_LIBRARY 2 ASSERT_OPTIMIZED)
if(NOT ${ASSERT_OPTIMIZED} STREQUAL "optimized")
message(FATAL_ERROR "could not parse library path from ${TINYXML2_LIBRARY}")
endif()
list(GET TINYXML2_LIBRARY 3 TINYXML2_LIBRARY_PATH)
endif()
if(NOT EXISTS ${TINYXML2_LIBRARY_PATH})
message(FATAL_ERROR "library file path ${TINYXML2_LIBRARY_PATH} does not exist")
endif()

add_library(tinyxml2::tinyxml2 UNKNOWN IMPORTED)
set_property(TARGET tinyxml2::tinyxml2 PROPERTY IMPORTED_LOCATION ${TINYXML2_LIBRARY_PATH})
set_property(TARGET tinyxml2::tinyxml2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${TINYXML2_INCLUDE_DIR})
list(APPEND TinyXML2_TARGETS tinyxml2::tinyxml2)
endif()
endif()
else()
find_path(TINYXML2_INCLUDE_DIR NAMES tinyxml2.h)

find_library(TINYXML2_LIBRARY tinyxml2)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TINYXML2_LIBRARY TINYXML2_INCLUDE_DIR)

mark_as_advanced(TINYXML2_INCLUDE_DIR TINYXML2_LIBRARY)

if(NOT TARGET tinyxml2::tinyxml2)
add_library(tinyxml2::tinyxml2 UNKNOWN IMPORTED)
set_property(TARGET tinyxml2::tinyxml2 PROPERTY IMPORTED_LOCATION ${TINYXML2_LIBRARY})
set_property(TARGET tinyxml2::tinyxml2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${TINYXML2_INCLUDE_DIR})
list(APPEND TinyXML2_TARGETS tinyxml2::tinyxml2)
endif()
endif()

# Set mixed case INCLUDE_DIRS and LIBRARY variables from upper case ones.
if(NOT TinyXML2_INCLUDE_DIRS)
set(TinyXML2_INCLUDE_DIRS ${TINYXML2_INCLUDE_DIR})
endif()
if(NOT TinyXML2_LIBRARIES)
set(TinyXML2_LIBRARIES ${TINYXML2_LIBRARY})
endif()
10 changes: 9 additions & 1 deletion cmake/urdfdom-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
@PACKAGE_INIT@

if (@PKG_NAME@_CONFIG_INCLUDED)
return()
endif()
set(@PKG_NAME@_CONFIG_INCLUDED TRUE)

set(@PKG_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@" "@TinyXML_INCLUDE_DIRS@")
set(CMAKE_MODULE_PATH_BACKUP_URDFDOM ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${@PROJECT_NAME@_DIR}")

set(@PKG_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@")

foreach(lib @PKG_LIBRARIES@)
set(onelib "${lib}-NOTFOUND")
Expand All @@ -30,6 +35,7 @@ foreach(lib @PKG_LIBRARIES@)
list(APPEND @PKG_NAME@_TARGETS @PROJECT_NAME@::${lib})
endforeach()

find_package(tinyxml2_vendor QUIET)
foreach(dep @PKG_DEPENDS@)
if(NOT ${dep}_FOUND)
find_package(${dep})
Expand All @@ -41,3 +47,5 @@ endforeach()
foreach(exp @PKG_EXPORTS@)
include(${@PROJECT_NAME@_DIR}/${exp}Export.cmake)
endforeach()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH_BACKUP_URDFDOM})
8 changes: 4 additions & 4 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

<build_depend>console_bridge_vendor</build_depend>
<build_depend>libconsole-bridge-dev</build_depend>
<build_depend>tinyxml</build_depend>
<build_depend>tinyxml_vendor</build_depend>
<build_depend>tinyxml2</build_depend>
<build_depend>tinyxml2_vendor</build_depend>
<build_depend version_gte="0.2.3">urdfdom_headers</build_depend>

<buildtool_depend>cmake</buildtool_depend>

<exec_depend>console_bridge_vendor</exec_depend>
<exec_depend>libconsole-bridge-dev</exec_depend>
<exec_depend>tinyxml</exec_depend>
<exec_depend>tinyxml_vendor</exec_depend>
<exec_depend>tinyxml2</exec_depend>
<exec_depend>tinyxml2_vendor</exec_depend>
<exec_depend version_gte="0.2.3">urdfdom_headers</exec_depend>

<test_depend>python3</test_depend>
Expand Down
5 changes: 2 additions & 3 deletions urdf_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ macro(add_urdfdom_library)

add_library(${add_urdfdom_library_LIBNAME} SHARED
${add_urdfdom_library_SOURCES})
target_include_directories(${add_urdfdom_library_LIBNAME} SYSTEM PUBLIC
${TinyXML_INCLUDE_DIRS})
target_include_directories(${add_urdfdom_library_LIBNAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_link_libraries(${add_urdfdom_library_LIBNAME} PUBLIC
${add_urdfdom_library_LINK}
${console_bridge_link_libs}
${urdfdom_headers_link_libs}
${TinyXML_LIBRARIES})
tinyxml2::tinyxml2
)
if(NOT CMAKE_CXX_STANDARD)
target_compile_features(${add_urdfdom_library_LIBNAME} PUBLIC cxx_std_14)
endif()
Expand Down
Loading

0 comments on commit bde3e64

Please sign in to comment.