Skip to content

Commit acaec06

Browse files
committed
cppad: Fix unit tests and example
1 parent 0d1e2eb commit acaec06

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

examples/codegen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)
77
ADD_PINOCCHIO_CPP_EXAMPLE(codegen-crba)
88
SET_PROPERTY(TARGET example-cpp-codegen-crba PROPERTY CXX_STANDARD 11)
99
TARGET_LINK_LIBRARIES(example-cpp-codegen-crba PUBLIC ${CMAKE_DL_LIBS} ${cppad_LIBRARY})
10+
TARGET_COMPILE_DEFINITIONS(example-cpp-codegen-crba PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
1011
ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)
1112

examples/codegen/codegen-crba.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main(int argc, const char ** argv)
2828

2929
// Generate the lib if it does not exist and load it afterwards.
3030
crba_code_gen.initLib();
31-
crba_code_gen.loadLib();
31+
crba_code_gen.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);
3232

3333
// Use it with a random configuration samples in the bounds of the joint limits
3434
VectorXd q = randomConfiguration(model);

include/pinocchio/codegen/code-generator-base.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ namespace pinocchio
8383
CppAD::cg::ModelCSourceGen<Scalar> & codeGenerator()
8484
{ return *cgen_ptr; }
8585

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

102+
void compileAndLoadLib(const std::string& gccPath)
103+
{
104+
compileLib(gccPath);
105+
loadLib(false);
106+
}
107+
102108
void loadLib(const bool generate_if_not_exist = true)
103109
{
104110
if(!existLib() && generate_if_not_exist)

unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ MACRO(ADD_CPPADCG_UNIT_TEST name)
197197
ADD_DEPENDENCIES(test-cppadcg test-cpp-${name})
198198
SET_PROPERTY(TARGET test-cpp-${name} PROPERTY CXX_STANDARD 11)
199199
TARGET_LINK_LIBRARIES(test-cpp-${name} PUBLIC ${cppad_LIBRARY} ${CMAKE_DL_LIBS})
200+
TARGET_COMPILE_DEFINITIONS(test-cpp-${name} PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
200201
ENDMACRO()
201202

202203
IF(BUILD_WITH_AUTODIFF_SUPPORT)

unittest/cppadcg-algo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
8282
// compile source code
8383
CppAD::cg::DynamicModelLibraryProcessor<Scalar> p(libcgen);
8484

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

8888
// save to files (not really required)

unittest/cppadcg-basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
189189
// compile source code
190190
DynamicModelLibraryProcessor<double> p(libcgen);
191191

192-
GccCompiler<double> compiler;
192+
GccCompiler<double> compiler(PINOCCHIO_CXX_COMPILER);
193193
std::unique_ptr<DynamicLib<double>> dynamicLib = p.createDynamicLibrary(compiler);
194194

195195
// save to files (not really required)

unittest/cppadcg-joint-configurations.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
3535
//Integrate
3636
CodeGenIntegrate<double> cg_integrate(model);
3737
cg_integrate.initLib();
38-
cg_integrate.loadLib();
38+
cg_integrate.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);
3939

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

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

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

0 commit comments

Comments
 (0)