Skip to content

Commit

Permalink
[cmake] Export project for downstream use
Browse files Browse the repository at this point in the history
  • Loading branch information
arntanguy committed Mar 1, 2024
1 parent 953a898 commit c0e5e0d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 65 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ endif()

project(mc_panda_lirmm LANGUAGES CXX VERSION 1.0)
enable_testing()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

find_package(mc_panda REQUIRED)

add_subdirectory(modules)
add_subdirectory(cmake)

if(BUILD_TESTING)
add_subdirectory(tests)
Expand Down
11 changes: 11 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include(CMakePackageConfigHelpers)
set(VERSION_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(PROJECT_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
${VERSION_CONFIG}
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in" "${PROJECT_CONFIG}" INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}")
install(FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}" DESTINATION "${CONFIG_INSTALL_DIR}")
8 changes: 8 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_package(mc_panda REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/mc_panda_lirmmTargets.cmake")

check_required_components(mc_panda_lirmm)
39 changes: 35 additions & 4 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/config.h")
add_robot(PandaLIRMM module.cpp module.h)
target_link_libraries(PandaLIRMM PUBLIC mc_panda::panda)
target_include_directories(PandaLIRMM PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
# Panda robot module library
set(panda_lirmm_HDR
include/mc_panda_lirmm/panda_lirmm.h
"${CMAKE_CURRENT_SOURCE_DIR}/include/mc_panda_lirmm/panda_lirmm.h"
)

set(panda_lirmm_SRC
src/panda_lirmm.cpp
)
configure_file(include/mc_panda_lirmm/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mc_panda_lirmm/config.h")

add_library(mc_panda_lirmm SHARED ${panda_lirmm_SRC} ${panda_lirmm_HDR})
add_library(mc_panda_lirmm::panda_lirmm ALIAS mc_panda_lirmm)
set_target_properties(mc_panda_lirmm PROPERTIES EXPORT_NAME panda_lirmm)
set_target_properties(mc_panda_lirmm PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION})
target_link_libraries(mc_panda_lirmm PUBLIC mc_panda::panda)
target_include_directories(mc_panda_lirmm PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
target_include_directories(mc_panda_lirmm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_compile_definitions(mc_panda_lirmm PRIVATE -DMC_PANDA_EXPORTS)
install(FILES ${panda_lirmm_HDR} DESTINATION include/mc_panda_lirmm)

install(TARGETS mc_panda_lirmm
EXPORT mc_panda_lirmmTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(EXPORT mc_panda_lirmmTargets
FILE mc_panda_lirmmTargets.cmake
NAMESPACE mc_panda_lirmm::
DESTINATION lib/cmake/mc_panda_lirmm)

add_robot(PandaLIRMM src/module.cpp)
target_link_libraries(PandaLIRMM PUBLIC mc_panda_lirmm::panda_lirmm)
target_compile_definitions(PandaLIRMM PRIVATE -DPANDA_DESCRIPTION_PATH="${PANDA_DESCRIPTION_PATH}")

install(DIRECTORY rsdf/panda2_lirmm
DESTINATION "${PANDA_DESCRIPTION_PATH}/rsdf"
Expand Down
File renamed without changes.
20 changes: 7 additions & 13 deletions modules/module.h → modules/include/mc_panda_lirmm/panda_lirmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ static std::string pandaVariantUppercase(bool pump, bool foot, bool hand)
return v;
}

enum class Robots
enum class PandaLIRMMRobots
{
Panda2LIRMM,
Panda6LIRMM,
Panda7LIRMM
};

static std::string to_string(Robots robots)
static std::string to_string(PandaLIRMMRobots robots)
{
if(robots == Robots::Panda2LIRMM)
if(robots == PandaLIRMMRobots::Panda2LIRMM)
{
return "Panda2LIRMM";
}
else if(robots == Robots::Panda6LIRMM)
else if(robots == PandaLIRMMRobots::Panda6LIRMM)
{
return "Panda6LIRMM";
}
Expand All @@ -67,7 +67,7 @@ static std::string to_string(Robots robots)
}
}

inline static std::string NameFromParams(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
inline static std::string NameFromParams(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
{
auto name = to_string(robot) + pandaVariantUppercase(pump, foot, hand);
if(!fixSensorFrame)
Expand All @@ -84,7 +84,7 @@ static void ForAllVariants(Callback cb)
{false, false, false}, {true, false, false}, {false, true, false}, {false, false, true}};
auto fixSensorFrameOptions = {true, false};

for(auto robot : {Robots::Panda2LIRMM, Robots::Panda6LIRMM, Robots::Panda7LIRMM})
for(auto robot : {PandaLIRMMRobots::Panda2LIRMM, PandaLIRMMRobots::Panda6LIRMM, PandaLIRMMRobots::Panda7LIRMM})
{
for(auto endEffector : endEffectorOptions)
{
Expand All @@ -99,7 +99,7 @@ static void ForAllVariants(Callback cb)
struct ROBOT_MODULE_API PandaLIRMM : public mc_robots::PandaRobotModule
{
public:
PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame = true);
PandaLIRMM(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame = true);

protected:
void create_urdf();
Expand All @@ -110,10 +110,4 @@ struct ROBOT_MODULE_API PandaLIRMM : public mc_robots::PandaRobotModule
double box_mass);
};

struct ROBOT_MODULE_API Panda2LIRMM : public mc_robots::PandaLIRMM
{
public:
Panda2LIRMM(bool pump, bool foot, bool hand, bool fixSensorFrame = true);
};

} // namespace mc_robots
42 changes: 42 additions & 0 deletions modules/src/module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <mc_panda_lirmm/panda_lirmm.h>

extern "C"
{
ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector<std::string> & names)
{
using namespace mc_robots;
ForAllVariants([&names](PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
{ names.push_back(NameFromParams(robot, pump, foot, hand, fixSensorFrame)); });
}
ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule * ptr)
{
delete ptr;
}
ROBOT_MODULE_API mc_rbdyn::RobotModule * create(const std::string & n)
{
ROBOT_MODULE_CHECK_VERSION("PandaLIRMM")

static auto variant_factory = []()
{
std::map<std::string, std::function<mc_rbdyn::RobotModule *()>> variant_factory;
using namespace mc_robots;
ForAllVariants(
[&variant_factory](PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
{
variant_factory[NameFromParams(robot, pump, foot, hand, fixSensorFrame)] = [=]()
{ return new PandaLIRMM(robot, pump, foot, hand, fixSensorFrame); };
});
return variant_factory;
}();
auto it = variant_factory.find(n);
if(it != variant_factory.end())
{
return it->second();
}
else
{
mc_rtc::log::error("PandaLIRMM module Cannot create an object of type {}", n);
return nullptr;
}
}
}
53 changes: 6 additions & 47 deletions modules/module.cpp → modules/src/panda_lirmm.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "module.h"
#include <RBDyn/parsers/urdf.h>
#include "config.h"
#include <Eigen/Core>
#include <mc_panda_lirmm/config.h>
#include <mc_panda_lirmm/panda_lirmm.h>
#include <sch/S_Object/S_Box.h>

#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -52,12 +52,12 @@ Eigen::Vector3d computeBoxCenterOfMass(const Eigen::Vector3d & size, double mass
return com_vector;
}

PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
PandaLIRMM::PandaLIRMM(PandaLIRMMRobots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
: mc_robots::PandaRobotModule(pump, foot, hand)
{
this->name += "_" + pandaVariant(pump, foot, hand);

if(robot == Robots::Panda2LIRMM)
if(robot == PandaLIRMMRobots::Panda2LIRMM)
{
this->name = "panda2_lirmm_" + pandaVariant(pump, foot, hand);
auto size = Eigen::Vector3d{0.75, 1.0, 0.75};
Expand All @@ -67,7 +67,7 @@ PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSe
_default_attitude = {1, 0, 0, 0, 0, 0, size.z()};
create_urdf();
}
else if(robot == Robots::Panda6LIRMM)
else if(robot == PandaLIRMMRobots::Panda6LIRMM)
{
this->name = "panda6_lirmm_" + pandaVariant(pump, foot, hand);
double mass = 40;
Expand All @@ -78,7 +78,7 @@ PandaLIRMM::PandaLIRMM(Robots robot, bool pump, bool foot, bool hand, bool fixSe
_default_attitude = {1, 0, 0, 0, 0, 0, size.z()};
create_urdf();
}
else if(robot == Robots::Panda7LIRMM)
else if(robot == PandaLIRMMRobots::Panda7LIRMM)
{
this->name = "panda7_lirmm_" + pandaVariant(pump, foot, hand);
double mass = 10;
Expand Down Expand Up @@ -163,44 +163,3 @@ void PandaLIRMM::create_urdf()
}

} // namespace mc_robots

extern "C"
{
ROBOT_MODULE_API void MC_RTC_ROBOT_MODULE(std::vector<std::string> & names)
{
using namespace mc_robots;
ForAllVariants([&names](Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
{ names.push_back(NameFromParams(robot, pump, foot, hand, fixSensorFrame)); });
}
ROBOT_MODULE_API void destroy(mc_rbdyn::RobotModule * ptr)
{
delete ptr;
}
ROBOT_MODULE_API mc_rbdyn::RobotModule * create(const std::string & n)
{
ROBOT_MODULE_CHECK_VERSION("PandaLIRMM")

static auto variant_factory = []()
{
std::map<std::string, std::function<mc_rbdyn::RobotModule *()>> variant_factory;
using namespace mc_robots;
ForAllVariants(
[&variant_factory](Robots robot, bool pump, bool foot, bool hand, bool fixSensorFrame)
{
variant_factory[NameFromParams(robot, pump, foot, hand, fixSensorFrame)] = [=]()
{ return new PandaLIRMM(robot, pump, foot, hand, fixSensorFrame); };
});
return variant_factory;
}();
auto it = variant_factory.find(n);
if(it != variant_factory.end())
{
return it->second();
}
else
{
mc_rtc::log::error("PandaLIRMM module Cannot create an object of type {}", n);
return nullptr;
}
}
}

0 comments on commit c0e5e0d

Please sign in to comment.