Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build with Boost < 1.77 #2132

Merged
merged 3 commits into from
Jan 16, 2024
Merged
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
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 @@ -197,6 +197,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
Loading