Skip to content

Commit fea2dbe

Browse files
author
Federico Giovanardi
committed
Support discovery of TinyXML2 by pkgconfig
Allow to discovery TinyXML2 by pkg-config is a `-config.cmake` file is not available. Since tinyxml2 is built with meson in Yocto it's configuration gets deployed by `pkg-config` (because meson cannot generate CMake target files). In this case, the current `FindTinyXML2.cmake` will find out the path of `tinyxml2.h` and of `tinyxml2.so` by looking into the `recipe-sysroot` folder, which path in going to get expanded into the `fastrtps-target.cmake` generated when fastdds is built. The end result is that we're going to have a system-wide deployed config mode package that points to a directory that won't (probably) not exist anymore when other dependent targets are built. Since it's not possible to force meson to produce a `tinyxml2-target.cmake` file, the most reasonable solution is trying to look for the library by pkg-config. With this patch applied, the generated `fastrtps-target.cmake` will have a reference to the target `PkgConfig::TinyXML2` instead of a full path.
1 parent 53bf6ab commit fea2dbe

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cmake/modules/FindTinyXML2.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ endif()
1515

1616
if(NOT (TINYXML2_FROM_SOURCE OR TINYXML2_FROM_THIRDPARTY))
1717
find_package(TinyXML2 CONFIG QUIET)
18+
if(NOT TinyXML2_FOUND)
19+
find_package(PkgConfig REQUIRED)
20+
pkg_check_modules(TinyXML2 REQUIRED IMPORTED_TARGET tinyxml2)
21+
if(TARGET PkgConfig::TinyXML2)
22+
add_library(tinyxml2::tinyxml2 ALIAS PkgConfig::TinyXML2)
23+
endif()
24+
endif()
1825
endif()
1926

2027
if(TinyXML2_FOUND AND NOT TINYXML2_FROM_THIRDPARTY)

cmake/packaging/Config.cmake.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")
2525
find_package(fastcdr REQUIRED)
2626
find_package(foonathan_memory REQUIRED)
2727
find_package(TinyXML2 QUIET)
28+
if(NOT TinyXML2_FOUND)
29+
find_package(PkgConfig REQUIRED)
30+
pkg_check_modules(TinyXML2 IMPORTED_TARGET tinyxml2)
31+
if(TARGET PkgConfig::TinyXML2)
32+
add_library(tinyxml2::tinyxml2 ALIAS PkgConfig::TinyXML2)
33+
endif()
34+
endif()
2835
@FASTDDS_INSTALLER_DEPS_ANCILLARY@
2936
@FASTDDS_PACKAGE_UNIX_OPT_DEPS@
3037

0 commit comments

Comments
 (0)