Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Nov 15, 2022
1 parent 79feef8 commit e1f3266
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
24 changes: 21 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -30,6 +43,11 @@ target_include_directories(${LIBRARY_TARGET_NAME} PUBLIC "$<BUILD_INTERFACE:${CM

target_compile_features(${LIBRARY_TARGET_NAME} PUBLIC cxx_std_11)

reloc_cpp_generate(${LIBRARY_TARGET_NAME}
GENERATED_HEADER ${CMAKE_CURRENT_BINARY_DIR}/iCubModelsGetInstallPrefix.h
GENERATED_FUNCTION iCubModels::getInstallPrefix)
target_include_directories(${LIBRARY_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

install(TARGETS ${LIBRARY_TARGET_NAME}
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
Expand Down
12 changes: 5 additions & 7 deletions cpp/src/iCubModels.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@

#include <iCubModels/iCubModels.h>

#include <iCubModelsGetInstallPrefix.h>
#include <filesystem>

#include <algorithm>

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<std::string> getRobotNames()
Expand Down

0 comments on commit e1f3266

Please sign in to comment.