Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from tinyxml to tinyxml2 #186

Merged
merged 13 commits into from
Dec 6, 2023
Merged

Conversation

felixf4xu
Copy link
Contributor

my attempt to address the issue #185

@ros-discourse
Copy link

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/upcoming-api-break-in-urdfdom/34750/1

felixf4xu and others added 2 commits November 29, 2023 15:51
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
@traversaro
Copy link
Contributor

traversaro commented Nov 29, 2023

I think we also need to modify the following line to change the reference to @TinyXML_INCLUDE_DIRS@:

set(@PKG_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@" "@TinyXML_INCLUDE_DIRS@")
. The urdfdom's CMake machinery is a relic from the past, but for users not using tinyxml-related methods everything works fine only because we manually export the tinyxml include dirs there. I can prepare a quick PR to handle this.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@clalancette
Copy link
Contributor

@traversaro You read my mind with almost all of your feedback; I've addressed most of it in 2f45917 and 06a18de.

As for your comment in #186 (comment) ; if you'd just like to post a diff of what you are thinking about here, I'm happy to merge it in.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@traversaro
Copy link
Contributor

As for your comment in #186 (comment) ; if you'd just like to post a diff of what you are thinking about here, I'm happy to merge it in.

Actually my comment was a bit outdated by your changes. I updated the modifications in felixf4xu#2, basically if tinyxml2::tinyxml2 is not a public linked library, we need to make sure that it is defined in urdfdom-config.cmake before the urdfdom::urdfdom_* libraries imported target are defined.

@traversaro
Copy link
Contributor

As for your comment in #186 (comment) ; if you'd just like to post a diff of what you are thinking about here, I'm happy to merge it in.

Actually my comment was a bit outdated by your changes. I updated the modifications in felixf4xu#2, basically if tinyxml2::tinyxml2 is not a public linked library, we need to make sure that it is defined in urdfdom-config.cmake before the urdfdom::urdfdom_* libraries imported target are defined.

Ok, this is partially outdated by 2383a0a . Adding FindTinyXML2.cmake locally does not help in systems without either tinyxml2_vendor or tinyxml2-config.cmake installed, as find_package(urdfdom) will fail if tinyxml2::tinyxml2 is not defined. A possible alternative is to also install FindTinyXML2.cmake, and temporary add it to the CMAKE_MODULE_PATH before the find_package(TinyXml2) call.

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

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@clalancette
Copy link
Contributor

Ok, this is partially outdated by 2383a0a . Adding FindTinyXML2.cmake locally does not help in systems without either tinyxml2_vendor or tinyxml2-config.cmake installed, as find_package(urdfdom) will fail if tinyxml2::tinyxml2 is not defined. A possible alternative is to also install FindTinyXML2.cmake, and temporary add it to the CMAKE_MODULE_PATH before the find_package(TinyXml2) call.

I've merged in felixf4xu#2 to this PR, though I'm not totally convinced by the find_package(tinyxml2_vendor); I think that will only exist in ROS 2 land. I'm more inclined to go with your other idea of installing FindTinyXML2.cmake and calling that, but I'm not 100% sure how to do that. I'll poke at it a bit more here.

@clalancette
Copy link
Contributor

@traversaro Relatedly, do you have a link to a non-ROS package that uses urdfdom? I'd like to have something concrete to test against.

@traversaro
Copy link
Contributor

@traversaro Relatedly, do you have a link to a non-ROS package that uses urdfdom? I'd like to have something concrete to test against.

Probably a quite relevant example of such package may be sdformat (https://github.com/gazebosim/sdformat).

@traversaro
Copy link
Contributor

Ok, this is partially outdated by 2383a0a . Adding FindTinyXML2.cmake locally does not help in systems without either tinyxml2_vendor or tinyxml2-config.cmake installed, as find_package(urdfdom) will fail if tinyxml2::tinyxml2 is not defined. A possible alternative is to also install FindTinyXML2.cmake, and temporary add it to the CMAKE_MODULE_PATH before the find_package(TinyXml2) call.

I've merged in felixf4xu#2 to this PR, though I'm not totally convinced by the find_package(tinyxml2_vendor); I think that will only exist in ROS 2 land. I'm more inclined to go with your other idea of installing FindTinyXML2.cmake and calling that, but I'm not 100% sure how to do that. I'll poke at it a bit more here.

Yes, that is correct. In the corrent form, this works:

  • If tinyxml2_vendor is installed (case in ROS)
  • If tinyxml2 is installed via cmake, and so it installs tinyxml2-config.cmake (case of tinyxml2 in conda-forge)

However, it does not work with Ubuntu with apt dependencies, where libtinyxml2-dev package does not contain any tinyxml2-config.cmake. I was not thinking to this case.

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

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@clalancette
Copy link
Contributor

With an assist from @sloretz , I updated this PR with b592bbd, which generates the necessary config file changes. I can't make this fail in any situation now; it always seems to do the right thing for me. But any additional testing @traversaro is much appreciated.

@traversaro
Copy link
Contributor

Thanks! I will check this tomorrow (European) morning.

@traversaro
Copy link
Contributor

traversaro commented Nov 30, 2023

Ok, I reproduced the problem I was referring to in earlier messages (with the example project https://gist.github.com/traversaro/c79f69e2fe5e0d2b7c1405ee973c2058, tested on Ubuntu 22.04 with apt dependencies):

sudo apt install build-essential libtinyxml2-dev liburdfdom-headers-dev
mkdir -p urdfdom_ws/src
cd urdfdom_ws/src
git clone -b tinyxml2 https://github.com/felixf4xu/urdfdom/
git clone https://gist.github.com/traversaro/c79f69e2fe5e0d2b7c1405ee973c2058 urdfdom_test
cd ..
colcon build

this fails with:

CMake Warning at /home/traversaro/urdfdom_ws/install/urdfdom/lib/urdfdom/cmake/urdfdom-config.cmake:62 (find_package):
  By not providing "FindTinyXML2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "TinyXML2",
  but CMake did not find one.

  Could not find a package configuration file provided by "TinyXML2" with any
  of the following names:

    TinyXML2Config.cmake
    tinyxml2-config.cmake

  Add the installation prefix of "TinyXML2" to CMAKE_PREFIX_PATH or set
  "TinyXML2_DIR" to a directory containing one of the above files.  If
  "TinyXML2" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  CMakeLists.txt:5 (find_package)


CMake Error at CMakeLists.txt:9 (add_executable):
  Target "dummy" links to target "tinyxml2::tinyxml2" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:9 (add_executable):
  Target "dummy" links to target "tinyxml2::tinyxml2" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:9 (add_executable):
  Target "dummy" links to target "tinyxml2::tinyxml2" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

It turns out that sdformat is not actually a great example to see this problem, as it also uses tinyxml2 internally, and so in that case tinyxml2::tinyxml2 is already defined before the find_package(urdfdom) call.

@clalancette
Copy link
Contributor

Ok, I reproduced the problem I was referring to in earlier messages (with the example project https://gist.github.com/traversaro/c79f69e2fe5e0d2b7c1405ee973c2058, tested on Ubuntu 22.04 with apt dependencies):

Ah, thanks for that. I didn't see this problem because, while I did an extremely similar test yesterday, I did it on Fedora 38. And there, the tinyxml-devel package actually provides the proper .cmake, while the Ubuntu one doesn't.

In any case, we should fix this, so I'll look at installing the FindTinyXML2.cmake file as we discussed earlier.

This is so downstream projects can always find it.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@clalancette
Copy link
Contributor

All right, 0e61d1f should fix that particular problem. I have a few other tests to run on it (like on ROS 2), but another look here is much appreciated.

@traversaro
Copy link
Contributor

Ok, I reproduced the problem I was referring to in earlier messages (with the example project https://gist.github.com/traversaro/c79f69e2fe5e0d2b7c1405ee973c2058, tested on Ubuntu 22.04 with apt dependencies):

Ah, thanks for that. I didn't see this problem because, while I did an extremely similar test yesterday, I did it on Fedora 38. And there, the tinyxml-devel package actually provides the proper .cmake, while the Ubuntu one doesn't.

Probably also fedora switched to build tinyxml2 via cmake like done in conda-forge.

@traversaro
Copy link
Contributor

All right, 0e61d1f should fix that particular problem. I have a few other tests to run on it (like on ROS 2), but another look here is much appreciated.

It seems fine. I did a small suggestion to reduce the risk of conflict shadowing with other installed FindTinyXML2.cmake files, but even that version should be working fine for now.

So we don't permanently manipulate it.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
@scpeters scpeters changed the title upgrade from tinyxml to tinyxml2 Upgrade from tinyxml to tinyxml2 Dec 1, 2023
@clalancette
Copy link
Contributor

Here's preliminary ROS 2 CI on this change:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status
  • Windows Debug Build Status
  • RHEL Build Status
  • Clang Build Status

URDFDOM_DLLAPI bool parseSensor(Sensor&, TiXmlElement*);
URDFDOM_DLLAPI bool parseModelState(ModelState&, TiXmlElement*);
URDFDOM_DLLAPI tinyxml2::XMLDocument* exportURDF(ModelInterfaceSharedPtr &model);
URDFDOM_DLLAPI tinyxml2::XMLDocument* exportURDF(const ModelInterface &model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just remembered that we had planned some changes to the public API in #178 so that tinyxml2.h wouldn't need to be included from this header file. We can address those in a separate pull request, so that this is a cleaner tinyxml -> tinyxml2 replacement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an issue for this: #189

@clalancette clalancette linked an issue Dec 6, 2023 that may be closed by this pull request
@clalancette
Copy link
Contributor

All right. With the latest reviews, I'm going to go ahead and merge this one. There is some follow-up work to do here, so I'm not going to do the 4.0.0 release right now, but I'll keep it on my list to do in the next couple of weeks.

@felixf4xu Thanks for getting this started, @traversaro thanks for the feedback, and @scpeters thanks for the review!

@clalancette clalancette merged commit 18325be into ros:master Dec 6, 2023
6 of 7 checks passed
harleylara pushed a commit to traversaro/urdfdom that referenced this pull request Feb 15, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use tinyxml2 instead of tinyxml
5 participants