Skip to content

Conversation

@olivier-roussel
Copy link
Contributor

@olivier-roussel olivier-roussel commented Oct 17, 2023

This aims to tackle one point of #4221 . Required for the conda-forge package (conda-forge/staged-recipes#23085).
This PR propose to replace tinyxml embedded library, which is unmaintained now for a long time, by tinyxml2 (https://github.com/leethomason/tinyxml2/tree/master, under Z-lib license) which looks to be its successor and best candidate, as it is maintened, well packaged with cmake and available on conda-forge.
Also, it is compatible for a future "find package or fetch content" mechanism in cmake. I don't know if we want to split the implementation of this additional feature for this package in another PR because if we do so, current code would need an additional required dependency to tinyxml2.
The "find or fetch" cmake mechanism for this package, avoiding the requirement for this dependency to be installed, can be implemented as it:

# find or fetch TinyXML2
include(FetchContent)
FetchContent_Declare(
  tinyxml2
  URL https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz
  FIND_PACKAGE_ARGS NAMES TinyXML2
)
FetchContent_GetProperties(tinyxml2)
if(NOT tinyxml2_POPULATED)
  FetchContent_Populate(tinyxml2)

  set(tinyxml2_SHARED_LIBS ON CACHE INTERNAL "")

  add_subdirectory(${tinyxml2_SOURCE_DIR} ${tinyxml2_BINARY_DIR})
endif()

However, this would required cmake >=3.24 and this call to be at a toplevel cmake (duplicating this code to replace all current calls to find_package(TinyXML2) does not seem desirable neither, so we might think also about how we can implement that in the cmake chain).


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@olivier-roussel olivier-roussel changed the title Replace tinyxml by external tinyxml2. [all] Replace tinyxml by external tinyxml2 Oct 17, 2023
@olivier-roussel olivier-roussel added the pr: status to review To notify reviewers to review this pull-request label Oct 17, 2023
@alxbilger
Copy link
Contributor

alxbilger commented Oct 17, 2023

CMake has the version 3.16.3 on the CI. It will not configure if you use the find_or_fetch feature

Comment on lines -23 to -27

foreach(target ${EXTLIBS_TARGETS})
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX "_d")
set_target_properties(${target} PROPERTIES FOLDER "SofaExtlibs")
endforeach()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it only related to tinyxml?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me, yes, as it related to

set(EXTLIBS_TARGETS
tinyxml
)
.
${EXTLIBS_TARGETS} is defined here only with the embedded version of tinyxml (contains all targets linked for embedded libraries). It is then empty and should not be used in the future to me as we are moving out non-header only embedded libraries.

@olivier-roussel olivier-roussel added the pr: clean Cleaning the code label Oct 17, 2023
@olivier-roussel
Copy link
Contributor Author

In addition to my initial comment, this version of "find or fetch" using FetchContent_MakeAvailable() (available from version 3.14) should be prefered:

# find or fetch TinyXML2
include(FetchContent)
FetchContent_Declare(
  tinyxml2
  URL https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz
  FIND_PACKAGE_ARGS NAMES TinyXML2
)
set(tinyxml2_SHARED_LIBS ON)
FetchContent_MakeAvailable(tinyxml2)

@olivier-roussel
Copy link
Contributor Author

Alternatively, we could have a naive custom "find or fetch" mechanism such as

# find or fetch TinyXML2
find_package(TinyXML2)
if(NOT TinyXML2_FOUND)
  include(FetchContent)
  FetchContent_Declare(
    tinyxml2
    URL https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz
    URL_HASH MD5=afecd941107a8e74d3d1b4363cf52bd7
    )
  set(tinyxml2_SHARED_LIBS ON)
  FetchContent_MakeAvailable(tinyxml2)
endif()

But, we typically want to avoid this call at each dependency requirement (so here replacing the current find_package(TinyXML2) calls, especially in the fetch case.
We could have these lines in a top-level CMakeLists instead, but this go in the opposite direction of our CMake dependencies management where it seems that we search the specific dependency on each target CMakeLists.
I believe (to be confirmed) that this can be avoid with the new mechanism introduced in cmake v3.24, by calling once the FetchContent_Declare (so in a kind of top-level cmake) and calling FetchContent_MakeAvailable for each target that needs it.

@alxbilger
Copy link
Contributor

# find or fetch TinyXML2
find_package(TinyXML2)
if(NOT TinyXML2_FOUND)
  include(FetchContent)
  FetchContent_Declare(
    tinyxml2
    URL https://github.com/leethomason/tinyxml2/archive/refs/tags/9.0.0.tar.gz
    URL_HASH MD5=afecd941107a8e74d3d1b4363cf52bd7
    )
  set(tinyxml2_SHARED_LIBS ON)
  FetchContent_MakeAvailable(tinyxml2)
endif()

Can it be written in our own FindTinyXML2.cmake file?

@olivier-roussel
Copy link
Contributor Author

I guess so. What you have in mind is that it could be a way to avoid multiple fetches in case of multiple calls to find_package by each target ? Not yet sure on how this could be implemented through

@hugtalbot
Copy link
Contributor

hugtalbot commented Oct 18, 2023

As a conclusion, what is needed:

  • Upgrade CMake >= 3.24 (@bakpaul is working on it)
  • Then use find_or_fetch

@fredroy fredroy added the pr: breaking Change possibly inducing a compilation error label Oct 18, 2023
@hugtalbot hugtalbot added the pr: status postponed To keep in mind that this PR was interesting but no one has time to make it mergeable now. label Oct 23, 2023
@olivier-roussel
Copy link
Contributor Author

Following our recent discussions, the "find or fetch" is replaced by a more classical find package strategy. The package management is fully left to the user.
As some package managers were not providing cmake config files for tinyxml2 (at least APT), this PR also provides a cmake find module to look for a config file first, and if none found, look manually for the tinyxml2 library.
Tested with:

  • APT package libtinyxml2-dev (v9.0.0), no cmake config file provided
  • conda package tinyxml2 (v9.0.0), cmake config file provided
  • vcpkg package tinyxml2 (v9.0.0), cmake config file provided.

@hugtalbot hugtalbot added the pr: backport todo This PR will be backported into the release preceeding its milestone. label Nov 22, 2023
@hugtalbot hugtalbot added this to the v23.12 milestone Nov 22, 2023
@bakpaul
Copy link
Contributor

bakpaul commented Feb 12, 2024

Tested and compiled on VS22/Ubuntu22.04 and it works.

@bakpaul bakpaul merged commit 867f455 into sofa-framework:master Feb 15, 2024
bakpaul added a commit that referenced this pull request Feb 19, 2024
* Replace tinyxml by external tinyxml2.

* Customize TinyXML2 cmake module to use a find _package or fetch content mechanism.

* Replace find or fetch mechanism by classical cmake find module.

* Fix missed cmake target name change

* Handle error if tinyxml2 package not found but required

* Fix compilation with Dump Visitor activated

* Install libtinyxml

* FIX error checking

* Actually fix...

* FIX error loading VTU xml files

* FIX scene test

---------

Co-authored-by: bakpaul <bakpaul@hotmail.fr>
Co-authored-by: Paul Baksic <30337881+bakpaul@users.noreply.github.com>
@bakpaul bakpaul added pr: backport done This PR has been backported into the release before its milestone. and removed pr: backport todo This PR will be backported into the release preceeding its milestone. labels Feb 20, 2024
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Feb 20, 2024
@bakpaul bakpaul removed the pr: status postponed To keep in mind that this PR was interesting but no one has time to make it mergeable now. label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: backport done This PR has been backported into the release before its milestone. pr: breaking Change possibly inducing a compilation error pr: clean Cleaning the code pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants