-
Hi @jnbrunet,
hence I received the following error during the generate of the cmake-gui. I even tried to delete the line and build again but the same mistake happen every time..
Do you have an idea ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @Ziemnono , Here's two examples to create a cmake project that depends on Caribou and Sofacaribou. Let's suppose I have the following environment variable set: $ export SOFA_ROOT=/opt/sofa/build/install
$ export CARIBOU_ROOT=/opt/caribou/build/install Note here that both variables point to the installation directory of both SOFA and caribou, and not the build directory. Hence if you have built them instead of downloading the binaries, you have to execute Linking a test executable against CaribouCMakeLists.txt cmake_minimum_required(VERSION 3.20)
project(test)
find_package(Caribou REQUIRED)
find_package(Eigen3 REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test Caribou::Config Caribou::Geometry Eigen3::Eigen) main.cpp #include <Eigen/Dense>
#include <Caribou/constants.h>
#include <Caribou/Geometry/Triangle.h>
#include <iostream>
int main() {
using namespace caribou;
using Triangle = caribou::geometry::Triangle<_2D, Linear>;
using LocalCoordinates = Triangle::LocalCoordinates;
using WordCoordinates = Triangle::WorldCoordinates;
Triangle t (
WordCoordinates({50, 50}),
WordCoordinates({60, 50}),
WordCoordinates({55, 55})
);
auto center = t.center();
std::cout << "(" << center[0] << ", " << center[1] << ")" << std::endl;
return 0;
} Compilation $ cmake -S /tmp/test -B /tmp/test/build -DCMAKE_PREFIX_PATH=$CARIBOU_ROOT/lib/cmake
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Performing Test HAS_FLTO_THIN
-- Performing Test HAS_FLTO_THIN - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test/build $ cmake --build /tmp/test/build
[ 50%] Building CXX object CMakeFiles/test.dir/main.cpp.o
[100%] Linking CXX executable test
[100%] Built target test $ /tmp/test/build/test
(55, 51.6667) Linking a test plugin against SofaCaribouThis plugin contains an empty hyperelastic material. cmake_minimum_required(VERSION 3.20)
project(MyCoolMaterial)
find_package(SofaCaribou REQUIRED)
find_package(SofaFramework REQUIRED)
find_package(Sofa.Config REQUIRED)
find_package(Sofa.Core REQUIRED)
find_package(Eigen3 REQUIRED)
add_library(${PROJECT_NAME} SHARED init.cpp MyCoolMaterial.cpp)
target_link_libraries(${PROJECT_NAME} Eigen3::Eigen Sofa.Config Sofa.Core SofaCaribou) init.cpp extern "C" {
void initExternalModule();
const char* getModuleName();
const char* getModuleVersion();
const char* getModuleLicense();
const char* getModuleDescription();
const char* getModuleComponentList();
}
void initExternalModule() {}
const char* getModuleName() { return "test"; }
const char* getModuleVersion() { return "alpha 1.0"; }
const char* getModuleLicense() { return "TBD"; }
const char* getModuleDescription() { return ""; }
const char* getModuleComponentList() { return ""; } MyCoolMaterial.cpp #include <SofaCaribou/Material/HyperelasticMaterial.h>
#include <sofa/core/ObjectFactory.h>
class MyCoolMaterial : public SofaCaribou::material::HyperelasticMaterial<sofa::defaulttype::Vec3Types> {
using Coord = typename sofa::defaulttype::Vec3Types::Coord;
using Real = typename Coord::value_type;
public:
SOFA_CLASS(MyCoolMaterial, SofaCaribou::material::HyperelasticMaterial<sofa::defaulttype::Vec3Types>);
/**
* This is called just before the material is updated on every points (usually just before a Newton step).
* It can be used to update some coefficients that will be used on material points (for example, compute
* the parameters mu and lambda from the young modulus and poisson ratio given as data arguments).
*/
void before_update() override {}
/**
* Get the strain energy density Psi from the right Cauchy-Green strain tensor C.
*
* Psi(E) = lambda/2 (tr(E))^2 + mu tr(E*E)
*
*/
Real
strain_energy_density(const Real & /*J*/, const Eigen::Matrix<Real, 3, 3> & /*C*/) const override {
return 0;
}
/** Get the second Piola-Kirchhoff stress tensor from the right Cauchy-Green strain tensor C. */
Eigen::Matrix<Real, 3, 3>
PK2_stress(const Real & /*J*/, const Eigen::Matrix<Real, 3, 3> & /*C*/) const override {
static const auto Id = Eigen::Matrix<Real, 3, 3, Eigen::RowMajor>::Identity();
return Id;
}
/** Get the jacobian of the second Piola-Kirchhoff stress tensor w.r.t the right Cauchy-Green strain tensor C. */
Eigen::Matrix<Real, 6, 6>
PK2_stress_jacobian(const Real & /*J*/, const Eigen::Matrix<Real, 3, 3> & /*C*/) const override {
static const auto Id = Eigen::Matrix<Real, 6, 6, Eigen::RowMajor>::Identity();
return Id;
}
};
static int MyCoolMaterialClass = sofa::core::RegisterObject("A very cool hyperelastic material")
.add< MyCoolMaterial >(); test.scn <Node>
<MyCoolMaterial template="Vec3d"/>
</Node> Compilation $ cmake -S /tmp/test -B /tmp/test/build -DCMAKE_PREFIX_PATH=$CARIBOU_ROOT/lib/cmake
- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Performing Test HAS_FLTO_THIN
-- Performing Test HAS_FLTO_THIN - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/test/build $ cmake --build /tmp/test/build
[33%] Building CXX object CMakeFiles/MyCoolMaterial.dir/init.cpp.o
[ 66%] Building CXX object CMakeFiles/MyCoolMaterial.dir/MyCoolMaterial.cpp.o
[100%] Linking CXX shared library libMyCoolMaterial.dylib
[100%] Built target MyCoolMaterial $ SOFA_ROOT/bin/runSofa -l /tmp/test/build/libMyCoolMaterial.dylib /tmp/test/test.scn
(...)
[INFO] [PluginManager] Loaded plugin: /tmp/test/build/libMyCoolMaterial.dylib
(...) Let me know if you hit any difficulties. |
Beta Was this translation helpful? Give feedback.
-
Hi @jnbrunet , Thank you very much for the 2 examples, really helpful and nicely explained!
I think by default, SofaCaribou is built with MKL but couldn't be found by CMake, any idea ? UPDATE: By deactivating MKL option in the Caribou compilation, it is working :) But it still needs to be fixed for MKL, if you have any idea |
Beta Was this translation helpful? Give feedback.
Hey @Ziemnono ,
Here's two examples to create a cmake project that depends on Caribou and Sofacaribou.
Let's suppose I have the following environment variable set:
Note here that both variables point to the installation directory of both SOFA and caribou, and not the build directory. Hence if you have built them instead of downloading the binaries, you have to execute
make install
inside the build directory.Linking a test executable against Caribou
CMakeLists.txt