Skip to content

Commit

Permalink
Merge pull request #2132 from jorisv/topic/fix_cppad_boost_pre_177
Browse files Browse the repository at this point in the history
Fix build with Boost < 1.77
  • Loading branch information
jcarpent authored Jan 16, 2024
2 parents 81745db + acaec06 commit 835edd4
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Remove f-strings to fix install with python 2 ([#2110](https://github.com/stack-of-tasks/pinocchio/pull/2110))
- CMake: stop exporting CppAd/cppadcodegen & fetch submodule if not available ([#2112](https://github.com/stack-of-tasks/pinocchio/pull/2112))
- Fix malloc issue in CRBA algo ([#2126](https://github.com/stack-of-tasks/pinocchio/pull/2126))
- Fix build cppad and cppadcg with Boost < 1.77 ([#2132](https://github.com/stack-of-tasks/pinocchio/pull/2132))

## [2.6.21] - 2023-11-27

Expand Down
1 change: 1 addition & 0 deletions examples/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)
ADD_PINOCCHIO_CPP_EXAMPLE(codegen-crba)
SET_PROPERTY(TARGET example-cpp-codegen-crba PROPERTY CXX_STANDARD 11)
TARGET_LINK_LIBRARIES(example-cpp-codegen-crba PUBLIC ${CMAKE_DL_LIBS} ${cppad_LIBRARY})
TARGET_COMPILE_DEFINITIONS(example-cpp-codegen-crba PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)

2 changes: 1 addition & 1 deletion examples/codegen/codegen-crba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, const char ** argv)

// Generate the lib if it does not exist and load it afterwards.
crba_code_gen.initLib();
crba_code_gen.loadLib();
crba_code_gen.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

// Use it with a random configuration samples in the bounds of the joint limits
VectorXd q = randomConfiguration(model);
Expand Down
8 changes: 8 additions & 0 deletions include/pinocchio/autodiff/cppad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ namespace boost
return ADScalar(constant_pi<Scalar>::get(n));
}

#if BOOST_VERSION >= 107700
template <class T, T value>
static inline ADScalar get(const std::integral_constant<T, value> &n)
{
return ADScalar(constant_pi<Scalar>::get(n));
}
#else
template <class T, T value>
static inline ADScalar get(const boost::integral_constant<T, value> &n)
{
return ADScalar(constant_pi<Scalar>::get(n));
}
#endif
};
}
}
Expand Down
10 changes: 8 additions & 2 deletions include/pinocchio/codegen/code-generator-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ namespace pinocchio
CppAD::cg::ModelCSourceGen<Scalar> & codeGenerator()
{ return *cgen_ptr; }

void compileLib()
void compileLib(const std::string& gccPath = "/usr/bin/gcc")
{
CppAD::cg::GccCompiler<Scalar> compiler;
CppAD::cg::GccCompiler<Scalar> compiler(gccPath);
std::vector<std::string> compile_options = compiler.getCompileFlags();
compile_options[0] = "-Ofast";
compiler.setCompileFlags(compile_options);
Expand All @@ -99,6 +99,12 @@ namespace pinocchio
return file.good();
}

void compileAndLoadLib(const std::string& gccPath)
{
compileLib(gccPath);
loadLib(false);
}

void loadLib(const bool generate_if_not_exist = true)
{
if(!existLib() && generate_if_not_exist)
Expand Down
8 changes: 8 additions & 0 deletions include/pinocchio/codegen/cppadcg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ namespace boost
return CGScalar(constant_pi<Scalar>::get(n));
}

#if BOOST_VERSION >= 107700
template <class T, T value>
static inline CGScalar get(const std::integral_constant<T, value> &n)
{
return CGScalar(constant_pi<Scalar>::get(n));
}
#else
template <class T, T value>
static inline CGScalar get(const boost::integral_constant<T, value> &n)
{
return CGScalar(constant_pi<Scalar>::get(n));
}
#endif
};
}
}
Expand Down
1 change: 1 addition & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ MACRO(ADD_CPPADCG_UNIT_TEST name)
ADD_DEPENDENCIES(test-cppadcg test-cpp-${name})
SET_PROPERTY(TARGET test-cpp-${name} PROPERTY CXX_STANDARD 11)
TARGET_LINK_LIBRARIES(test-cpp-${name} PUBLIC ${cppad_LIBRARY} ${CMAKE_DL_LIBS})
TARGET_COMPILE_DEFINITIONS(test-cpp-${name} PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
ENDMACRO()

IF(BUILD_WITH_AUTODIFF_SUPPORT)
Expand Down
2 changes: 1 addition & 1 deletion unittest/cppadcg-algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
// compile source code
CppAD::cg::DynamicModelLibraryProcessor<Scalar> p(libcgen);

CppAD::cg::GccCompiler<Scalar> compiler;
CppAD::cg::GccCompiler<Scalar> compiler(PINOCCHIO_CXX_COMPILER);
std::unique_ptr<CppAD::cg::DynamicLib<Scalar>> dynamicLib = p.createDynamicLibrary(compiler);

// save to files (not really required)
Expand Down
2 changes: 1 addition & 1 deletion unittest/cppadcg-basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
// compile source code
DynamicModelLibraryProcessor<double> p(libcgen);

GccCompiler<double> compiler;
GccCompiler<double> compiler(PINOCCHIO_CXX_COMPILER);
std::unique_ptr<DynamicLib<double>> dynamicLib = p.createDynamicLibrary(compiler);

// save to files (not really required)
Expand Down
6 changes: 3 additions & 3 deletions unittest/cppadcg-joint-configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//Integrate
CodeGenIntegrate<double> cg_integrate(model);
cg_integrate.initLib();
cg_integrate.loadLib();
cg_integrate.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

cg_integrate.evalFunction(q1,v, results_q[0]);
pinocchio::integrate(model, q1,v,results_q[1]);
Expand All @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//Difference
CodeGenDifference<double> cg_difference(model);
cg_difference.initLib();
cg_difference.loadLib();
cg_difference.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

cg_difference.evalFunction(q1,q2, results_v[0]);
pinocchio::difference(model,q1,q2,results_v[1]);
Expand All @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//dDifference
CodeGenDDifference<double> cg_dDifference(model);
cg_dDifference.initLib();
cg_dDifference.loadLib();
cg_dDifference.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

//ARG0
std::vector<Eigen::MatrixXd> results_J(2,Eigen::MatrixXd::Zero(model.nv,model.nv));
Expand Down

0 comments on commit 835edd4

Please sign in to comment.