Gepetto / example-robot-data

Set of robot URDFs for benchmarking and developed examples.
BSD 3-Clause "New" or "Revised" License
131 stars 48 forks source link

Recover EXAMPLE_ROBOT_DATA_MODEL_DIR in C++ #186

Closed MedericFourmy closed 9 months ago

MedericFourmy commented 9 months ago

I was using the example robot data (4.0.4) in a C++ project by including

#include <example-robot-data/path.hpp>

which was defining the EXAMPLE_ROBOT_DATA_MODEL_DIR macro. This include file was deprecated in 4.0.7 and this path seems to be only available as the property INTERFACE_COMPILE_DEFINITIONS of target example-robot-data::example-robot-data.

In my CMakeLists.txt:

find_package(example-robot-data REQUIRED)
get_target_property(dir_path_exd example-robot-data::example-robot-data INTERFACE_COMPILE_DEFINITIONS)
message("${dir_path_exd}")

prints EXAMPLE_ROBOT_DATA_MODEL_DIR="<absolute_path_to>/share/example-robot-data/robots"

What's the recommended practice to access it from C++?

nim65s commented 9 months ago

You can link your C++ project to example-robot-data, eg:

https://github.com/loco-3d/crocoddyl/blob/3de0336178e09b4296912769b494f5741705775f/unittest/CMakeLists.txt#L79

This will define the EXAMPLE_ROBOT_DATA_MODEL_DIR macro in the same way, so you can use it with eg.:

https://github.com/loco-3d/crocoddyl/blob/3de0336178e09b4296912769b494f5741705775f/unittest/factory/pinocchio_model.cpp#L63-64

nim65s commented 9 months ago

ref https://github.com/Gepetto/example-robot-data/pull/170

MedericFourmy commented 9 months ago

Thanks, it worked