diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bda918a2c..3a673548c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 1874c9ab18..3cd9f00571 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -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" ) diff --git a/include/mc_rtc/config.h.cmake.in b/include/mc_rtc/config.h.cmake.in index 8aad610fe9..734c0a6890 100644 --- a/include/mc_rtc/config.h.cmake.in +++ b/include/mc_rtc/config.h.cmake.in @@ -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}/"; } diff --git a/include/mc_rtc/fmt_formatters.h b/include/mc_rtc/fmt_formatters.h new file mode 100644 index 0000000000..0eac2693c3 --- /dev/null +++ b/include/mc_rtc/fmt_formatters.h @@ -0,0 +1,79 @@ +#include +#include +#include +#include + +// 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 +# include +# include +# include +# include + +// Formatter for Eigen dense types (like Eigen::Matrix, Eigen::Array) +template +struct fmt::formatter, T> + && (fmt::range_format_kind::value == fmt::range_format::disabled)>> +: fmt::ostream_formatter +{ +}; + +// Formatter for boost::filesystem::path +template<> +struct fmt::formatter : fmt::formatter +{ + template + auto format(const boost::filesystem::path & p, FormatContext & ctx) + { + return fmt::formatter::format(p.string(), ctx); + } +}; + +#else +# define MC_FMT_STREAMED(X) X +#endif + +template<> +struct fmt::formatter> : fmt::formatter +{ + int precision = 3; /// default precision + + template + auto format(const sva::PTransform & 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} + ); + } +}; diff --git a/include/mc_rtc/logging.h b/include/mc_rtc/logging.h index becbbc4455..3cab206bd5 100644 --- a/include/mc_rtc/logging.h +++ b/include/mc_rtc/logging.h @@ -6,46 +6,12 @@ #include -#include +#include #include #include #include -// 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 -# include -# include -# include -# include - -// Formatter for Eigen dense types (like Eigen::Matrix, Eigen::Array) -template -struct fmt::formatter, T> - && (fmt::range_format_kind::value == fmt::range_format::disabled)>> -: fmt::ostream_formatter -{ -}; - -// Formatter for boost::filesystem::path -template<> -struct fmt::formatter : fmt::formatter -{ - template - auto format(const boost::filesystem::path & p, FormatContext & ctx) - { - return fmt::formatter::format(p.string(), ctx); - } -}; - -#else -# define MC_FMT_STREAMED(X) X -#endif - #define BOOST_STACKTRACE_LINK #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 988aceb112..be190b62d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/mc_rtcMacros.in.cmake b/src/mc_rtcMacros.in.cmake index 0f20e5fc7f..7f00029468 100644 --- a/src/mc_rtcMacros.in.cmake +++ b/src/mc_rtcMacros.in.cmake @@ -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@") @@ -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) @@ -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 --