diff --git a/examples/codegen/CMakeLists.txt b/examples/codegen/CMakeLists.txt index 446676d639..e009da0a3c 100644 --- a/examples/codegen/CMakeLists.txt +++ b/examples/codegen/CMakeLists.txt @@ -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) diff --git a/examples/codegen/codegen-crba.cpp b/examples/codegen/codegen-crba.cpp index 7c4f43e5db..ac427bca6e 100644 --- a/examples/codegen/codegen-crba.cpp +++ b/examples/codegen/codegen-crba.cpp @@ -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); diff --git a/include/pinocchio/codegen/code-generator-base.hpp b/include/pinocchio/codegen/code-generator-base.hpp index a996afcc15..a6417dc1c8 100644 --- a/include/pinocchio/codegen/code-generator-base.hpp +++ b/include/pinocchio/codegen/code-generator-base.hpp @@ -83,9 +83,9 @@ namespace pinocchio CppAD::cg::ModelCSourceGen & codeGenerator() { return *cgen_ptr; } - void compileLib() + void compileLib(const std::string& gccPath = "/usr/bin/gcc") { - CppAD::cg::GccCompiler compiler; + CppAD::cg::GccCompiler compiler(gccPath); std::vector compile_options = compiler.getCompileFlags(); compile_options[0] = "-Ofast"; compiler.setCompileFlags(compile_options); @@ -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) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 795bb33c84..15a17417a8 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -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) diff --git a/unittest/cppadcg-algo.cpp b/unittest/cppadcg-algo.cpp index 7ebe73b334..bb9ed9e845 100644 --- a/unittest/cppadcg-algo.cpp +++ b/unittest/cppadcg-algo.cpp @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) // compile source code CppAD::cg::DynamicModelLibraryProcessor p(libcgen); - CppAD::cg::GccCompiler compiler; + CppAD::cg::GccCompiler compiler(PINOCCHIO_CXX_COMPILER); std::unique_ptr> dynamicLib = p.createDynamicLibrary(compiler); // save to files (not really required) diff --git a/unittest/cppadcg-basic.cpp b/unittest/cppadcg-basic.cpp index fc17323ecc..e0c0a872f5 100644 --- a/unittest/cppadcg-basic.cpp +++ b/unittest/cppadcg-basic.cpp @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) // compile source code DynamicModelLibraryProcessor p(libcgen); - GccCompiler compiler; + GccCompiler compiler(PINOCCHIO_CXX_COMPILER); std::unique_ptr> dynamicLib = p.createDynamicLibrary(compiler); // save to files (not really required) diff --git a/unittest/cppadcg-joint-configurations.cpp b/unittest/cppadcg-joint-configurations.cpp index df58859ae0..39ced3cfd4 100644 --- a/unittest/cppadcg-joint-configurations.cpp +++ b/unittest/cppadcg-joint-configurations.cpp @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation) //Integrate CodeGenIntegrate 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]); @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation) //Difference CodeGenDifference 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]); @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation) //dDifference CodeGenDDifference cg_dDifference(model); cg_dDifference.initLib(); - cg_dDifference.loadLib(); + cg_dDifference.compileAndLoadLib(PINOCCHIO_CXX_COMPILER); //ARG0 std::vector results_J(2,Eigen::MatrixXd::Zero(model.nv,model.nv));