diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 1a220cc..ada9ac4 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -1,6 +1,19 @@ - - -set(ICUB_MODELS_MODELS_PATH ${CMAKE_INSTALL_PREFIX}/share/iCub/robots) +# Handle relocatability via reloc-cpp +option(ICUB_MODELS_USE_SYSTEM_RELOC_CPP "Use system reloc-cpp" OFF) +mark_as_advanced(ICUB_MODELS_USE_SYSTEM_RELOC_CPP) +if(ICUB_MODELS_USE_SYSTEM_RELOC_CPP) + find_package(reloc-cpp REQUIRED) +else() + include(FetchContent) + FetchContent_Declare( + reloc-cpp + GIT_REPOSITORY https://github.com/ami-iit/reloc-cpp.git + GIT_TAG v0.1.0 + ) + FetchContent_MakeAvailable(reloc-cpp) +endif() + +set(ICUB_MODELS_MODELS_RELATIVE_PATH share/iCub/robots) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/iCubModels.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/autogenerated/iCubModels.cpp @ONLY) @@ -30,6 +43,11 @@ target_include_directories(${LIBRARY_TARGET_NAME} PUBLIC "$ +#include +#include + #include namespace iCubModels { std::string getModelsPath() { - std::string retstr = "@ICUB_MODELS_MODELS_PATH@"; - // Sometimes the relocation of the C++ library in conda or similar systems is not working correctly - // and is leaving at the end of the retstr many \0 characters. To be sure not to return a faulty - // string, we remove all the trailing \0 - // See https://github.com/ami-iit/bipedal-locomotion-framework/pull/526 - retstr.erase(std::find(retstr.begin(), retstr.end(), '\0'), retstr.end()); - return retstr; + std::filesystem::path ret = std::filesystem::path(iCubModels::getInstallPrefix().value()) / std::filesystem::path("@ICUB_MODELS_MODELS_RELATIVE_PATH@"); + return ret.string(); } std::unordered_set getRobotNames()