Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,41 @@ endmacro()
find_description_package(mc_env_description)
find_description_package(mc_int_obj_description)

# -- Helper to set the components install prefix
#
# -- NOTE: Nix passes the CMAKE_INSTALL_LIBDIR and CMAKE_INSTALL_BINDIR as absolute
# paths to the nix store. See: https://github.com/NixOS/nixpkgs/issues/144170
macro(mc_rtc_set_prefix NAME FOLDER)
set(MC_${NAME}_LIBRARY_INSTALL_PREFIX ${CMAKE_INSTALL_FULL_LIBDIR}/${FOLDER})
if(WIN32)
set(MC_${NAME}_RUNTIME_INSTALL_PREFIX ${CMAKE_INSTALL_FULL_BINDIR}/${FOLDER})
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX
${MC_RTC_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${FOLDER}
)
if(IS_ABSOLUTE "${CMAKE_INSTALL_BINDIR}")
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX "${CMAKE_INSTALL_BINDIR}/${FOLDER}")
else()
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX
"${MC_RTC_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${FOLDER}"
)
endif()
else()
set(MC_${NAME}_RUNTIME_INSTALL_PREFIX ${CMAKE_INSTALL_FULL_LIBDIR}/${FOLDER})
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX
${MC_RTC_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FOLDER}
)
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX "${CMAKE_INSTALL_LIBDIR}/${FOLDER}")
else()
set(MC_${NAME}_RUNTIME_DESTINATION_PREFIX
"${MC_RTC_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${FOLDER}"
)
endif()
endif()
# For backward compatibility
set(MC_${NAME}_INSTALL_PREFIX "${MC_${NAME}_LIBRARY_INSTALL_PREFIX}")
message(STATUS "MC_${NAME}_INSTALL_PREFIX: ${MC_${NAME}_INSTALL_PREFIX}")
message(
STATUS "MC_${NAME}_RUNTIME_INSTALL_PREFIX: ${MC_${NAME}_RUNTIME_INSTALL_PREFIX}"
)
message(
STATUS
"MC_${NAME}_RUNTIME_DESTINATION_PREFIX: ${MC_${NAME}_RUNTIME_DESTINATION_PREFIX}"
)
endmacro()

mc_rtc_set_prefix(PLUGINS mc_plugins)
Expand All @@ -263,6 +283,7 @@ mc_rtc_set_prefix(CONTROLLER mc_controller)

set(MC_RTC_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}")
set(MC_RTC_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
set(MC_RTC_JSON_SCHEMA_PATH "${CMAKE_INSTALL_DOCDIR}/json/schemas")

configure_file(
${PROJECT_SOURCE_DIR}/include/mc_rtc/config.h.cmake.in
Expand Down
5 changes: 2 additions & 3 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
#

set(JSON_DOC_INSTALL ${CMAKE_INSTALL_DOCDIR}/json)
configure_file(_plugins/doxygen.rb.in "${CMAKE_CURRENT_SOURCE_DIR}/_plugins/doxygen.rb")

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/_data/schemas
DESTINATION ${JSON_DOC_INSTALL}
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/_data/schemas/
DESTINATION ${MC_RTC_JSON_SCHEMA_PATH}
FILES_MATCHING
PATTERN "*.json"
)
1 change: 1 addition & 0 deletions include/mc_rtc/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ constexpr auto MC_CONTROLLER_INSTALL_PREFIX = "${MC_CONTROLLER_RUNTIME_DESTINATI
constexpr auto MC_PLUGINS_INSTALL_PREFIX = "${MC_PLUGINS_RUNTIME_DESTINATION_PREFIX}";
constexpr auto DATA_PATH = "${CMAKE_INSTALL_PREFIX}/share/mc_rtc/";
constexpr auto CONF_PATH = "${CMAKE_INSTALL_PREFIX}/etc/mc_rtc.yaml";
constexpr auto JSON_SCHEMA_PATH = "${MC_RTC_JSON_SCHEMA_PATH}/";

}
79 changes: 79 additions & 0 deletions include/mc_rtc/fmt_formatters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <mc_rbdyn/rpy_utils.h>
#include <mc_rtc/constants.h>
#include <SpaceVecAlg/PTransform.h>
#include <fmt/format.h>

// fmt 9.0.0 removed automated operator<< discovery we use fmt::streamed instead when needed through a macro
#if FMT_VERSION >= 9 * 10000
# define MC_FMT_STREAMED(X) fmt::streamed(X)
# include <boost/filesystem.hpp>
# include <Eigen/Core>
# include <fmt/ostream.h>
# include <fmt/ranges.h>
# include <type_traits>

// Formatter for Eigen dense types (like Eigen::Matrix, Eigen::Array)
template<typename T, typename Char>
struct fmt::formatter<T,
Char,
std::enable_if_t<std::is_base_of_v<Eigen::DenseBase<T>, T>
&& (fmt::range_format_kind<T, Char, void>::value == fmt::range_format::disabled)>>
: fmt::ostream_formatter
{
};

// Formatter for boost::filesystem::path
template<>
struct fmt::formatter<boost::filesystem::path> : fmt::formatter<std::string>
{
template<typename FormatContext>
auto format(const boost::filesystem::path & p, FormatContext & ctx)
{
return fmt::formatter<std::string>::format(p.string(), ctx);
}
};

#else
# define MC_FMT_STREAMED(X) X
#endif

template<>
struct fmt::formatter<sva::PTransform<double>> : fmt::formatter<std::string>
{
int precision = 3; /// default precision

template<typename FormatContext>
auto format(const sva::PTransform<double> & pt, FormatContext & ctx) const
{
const auto & rotation_ft = pt.rotation();
auto rotation_std = pt.rotation().transpose();

auto rpy_ft = mc_rbdyn::rpyFromMat(rotation_ft);
auto rpy_ft_deg = rpy_ft * 180. / mc_rtc::constants::PI;

auto rpy_std = mc_rbdyn::rpyFromMat(rotation_std);
auto rpy_std_deg = rpy_std * 180. / mc_rtc::constants::PI;

// Format the translation as an example
return fmt::format_to(ctx.out(),
R"(PTransform:
translation: [{0}]
rotation:
- matrix (Featherstone):
{1}
- matrix (standard):
{2}
- rpy (Featherstone): [{3:.{9}}] (rad), [{4:.{9}}] (deg)
- rpy (standard): [{5:.{9}}] (rad), [{6:.{9}}] (deg)
)",
pt.translation().transpose(), // {0}
rotation_ft, // {1}
rotation_std, // {2}
rpy_ft, // {3}
rpy_ft_deg, // {4}
rpy_std, // {5}
rpy_std_deg, // {6}
precision // {9}
);
}
};
36 changes: 1 addition & 35 deletions include/mc_rtc/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,12 @@

#include <mc_rtc/utils_api.h>

#include <iostream>
#include <mc_rtc/fmt_formatters.h>

#include <spdlog/fmt/fmt.h>
#include <spdlog/fmt/ostr.h>
#include <spdlog/logger.h>

// fmt 9.0.0 removed automated operator<< discovery we use fmt::streamed instead when needed through a macro
#if FMT_VERSION >= 9 * 10000
# define MC_FMT_STREAMED(X) fmt::streamed(X)
# include <boost/filesystem.hpp>
# include <Eigen/Core>
# include <fmt/ostream.h>
# include <fmt/ranges.h>
# include <type_traits>

// Formatter for Eigen dense types (like Eigen::Matrix, Eigen::Array)
template<typename T, typename Char>
struct fmt::formatter<T,
Char,
std::enable_if_t<std::is_base_of_v<Eigen::DenseBase<T>, T>
&& (fmt::range_format_kind<T, Char, void>::value == fmt::range_format::disabled)>>
: fmt::ostream_formatter
{
};

// Formatter for boost::filesystem::path
template<>
struct fmt::formatter<boost::filesystem::path> : fmt::formatter<std::string>
{
template<typename FormatContext>
auto format(const boost::filesystem::path & p, FormatContext & ctx)
{
return fmt::formatter<std::string>::format(p.string(), ctx);
}
};

#else
# define MC_FMT_STREAMED(X) X
#endif

#define BOOST_STACKTRACE_LINK
#include <boost/stacktrace.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ set(mc_rtc_utils_HDR
../include/mc_rtc/ConfigurationHelpers.h
../include/mc_rtc/MessagePackBuilder.h
../include/mc_rtc/logging.h
../include/mc_rtc/fmt_formatters.h
../include/mc_rtc/log/FlatLog.h
../include/mc_rtc/log/iterate_binary_log.h
../include/mc_rtc/log/Logger.h
Expand Down
37 changes: 32 additions & 5 deletions src/mc_rtcMacros.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ get_filename_component(
PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/@mc_rtc_macros_RELATIVE_PATH@" ABSOLUTE
)

# -- Library install directory --
set(MC_RTC_BINDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_BINDIR@")
set(MC_RTC_DOCDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_DOCDIR@")
set(MC_RTC_LIBDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@")

# -- Library source directory --
set(MC_RTC_SRCDIR "@MC_RTC_SOURCE_DIR@")

Expand All @@ -23,6 +18,32 @@ if(MC_RTC_HONOR_INSTALL_PREFIX)
include(GNUInstallDirs)
endif()

# -- Library install directory --
if(MC_RTC_HONOR_INSTALL_PREFIX)
set(MC_RTC_BINDIR "${CMAKE_INSTALL_FULL_BINDIR}")
set(MC_RTC_DOCDIR "${CMAKE_INSTALL_FULL_DOCDIR}")
set(MC_RTC_LIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}")
else()
# nix sets CMAKE_INSTALL_*DIR to absolute paths
if(IS_ABSOLUTE "@CMAKE_INSTALL_BINDIR@")
set(MC_RTC_BINDIR "@CMAKE_INSTALL_BINDIR@")
else()
set(MC_RTC_BINDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_BINDIR@")
endif()

if(IS_ABSOLUTE "@CMAKE_INSTALL_DOCDIR@")
set(MC_RTC_DOCDIR "@CMAKE_INSTALL_DOCDIR@")
else()
set(MC_RTC_DOCDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_DOCDIR@")
endif()

if(IS_ABSOLUTE "@CMAKE_INSTALL_LIBDIR@")
set(MC_RTC_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
else()
set(MC_RTC_LIBDIR "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@")
endif()
endif()

# -- Helper to set the components install prefix --
macro(mc_rtc_set_prefix NAME FOLDER)
if(MC_RTC_HONOR_INSTALL_PREFIX)
Expand All @@ -41,6 +62,12 @@ macro(mc_rtc_set_prefix NAME FOLDER)
endif()
# For backward compatibility
set(MC_${NAME}_INSTALL_PREFIX "${MC_${NAME}_LIBRARY_INSTALL_PREFIX}")
message(
STATUS "MC_${NAME}_LIBRARY_INSTALL_PREFIX to ${MC_${NAME}_LIBRARY_INSTALL_PREFIX}"
)
message(
STATUS "MC_${NAME}_RUNTIME_INSTALL_PREFIX to ${MC_${NAME}_RUNTIME_INSTALL_PREFIX}"
)
endmacro()

# -- Controllers --
Expand Down