Repository: SofaDefrost/ModelOrderReduction (language: python)

Issue:
FIX and CLEAN for out-of-tree build
A few fixes needed to build MOR out of SOFA.
Also a bit of cleaning because I'm a nice guy :smile: 

To be squashed and backported into v21.06 branch.

FIX and CLEAN for out-of-tree build
A few fixes needed to build MOR out of SOFA.
Also a bit of cleaning because I'm a nice guy :smile: 

To be squashed and backported into v21.06 branch.



Discussion / hints:
@VannesteFelix should these changes be merged ? 

Thanks a lot @guparan !
It's ok on my side. 
@VannesteFelix should these changes be merged ? 

Thanks a lot @guparan !
It's ok on my side. 

Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3fae4be..10c6d5d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,8 @@
-cmake_minimum_required(VERSION 3.1)
+cmake_minimum_required(VERSION 3.12)
 
 project(ModelOrderReduction VERSION 1.0)
 
+include(CMakeDependentOption)
 include(cmake/environment.cmake)
 
 # Specify all required packages
@@ -116,8 +117,10 @@ sofa_create_package_with_targets(
     RELOCATABLE "plugins"
     )
 
-# if(SOFA_BUILD_TESTS)
-#     add_subdirectory(${MOR_SRC}/component/ModelOrderReduction_test)
-# endif()
+# If SOFA_BUILD_TESTS exists and is OFF, then these tests will be auto-disabled
+cmake_dependent_option(MODELORDERREDUCTION_BUILD_TESTS "Compile the tests" ON "SOFA_BUILD_TESTS OR NOT DEFINED SOFA_BUILD_TESTS" OFF)
+if(MODELORDERREDUCTION_BUILD_TESTS)
+    add_subdirectory(ModelOrderReduction_test)
+endif()
 
 include(cmake/packaging.cmake)
diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl
index 264d6fc7..53d0e387 100644
--- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl
+++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.inl
@@ -20,10 +20,10 @@
 #include "HyperReducedRestShapeSpringsForceField.h"
 #include <sofa/core/visual/VisualParams.h>
 #include <sofa/core/MechanicalParams.h>
+#include <sofa/core/behavior/MultiMatrixAccessor.h>
 #include <sofa/helper/config.h>
 #include <sofa/defaulttype/VecTypes.h>
 #include <sofa/defaulttype/RigidTypes.h>
-
 #include <sofa/defaulttype/RGBAColor.h>
 
 #include <assert.h>


Test patch:
diff --git a/ModelOrderReduction_test/CMakeLists.txt b/ModelOrderReduction_test/CMakeLists.txt
index 88fe5df3..6d7db48d 100644
--- a/ModelOrderReduction_test/CMakeLists.txt
+++ b/ModelOrderReduction_test/CMakeLists.txt
@@ -1,12 +1,15 @@
-include(${SOFA_CMAKE_DIR}/preProject.cmake)
+cmake_minimum_required(VERSION 3.12)
 
-set(SOURCE_FILES
+project(ModelOrderReduction_test)
+
+sofa_find_package(ModelOrderReduction REQUIRED)
+sofa_find_package(SofaTest REQUIRED)
+sofa_find_package(SofaSimulationGraph REQUIRED)
 
+set(SOURCE_FILES
     ModelOrderReduction_test.cpp
 )
-add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${RC_FILES})
 
-AddCompilerDefinitions("ModelOrderReduction_test_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
-AddLinkerDependencies(ModelOrderReduction SofaTest)
+add_executable(${PROJECT_NAME} ${SOURCE_FILES})
 
-include(${SOFA_CMAKE_DIR}/postProject.cmake)
+target_link_libraries(${PROJECT_NAME} ModelOrderReduction SofaTest Sofa.Testing SofaSimulationGraph)
diff --git a/ModelOrderReduction_test/ModelOrderReduction_test.cpp b/ModelOrderReduction_test/ModelOrderReduction_test.cpp
index a16f8031..027e01f6 100644
--- a/ModelOrderReduction_test/ModelOrderReduction_test.cpp
+++ b/ModelOrderReduction_test/ModelOrderReduction_test.cpp
@@ -1,6 +1,5 @@
-#include <plugins/SofaTest/Sofa_test.h>
-#include <sofa/component/init.h>
-#include <sofa/simulation/graph/DAGSimulation.h>
+#include <SofaTest/Sofa_test.h>
+#include <SofaSimulationGraph/DAGSimulation.h>
 
 namespace sofa {
 
@@ -19,7 +18,6 @@ namespace sofa {
         typedef typename DataTypes::CPos CPos;
         typedef typename DataTypes::VecCoord VecCoord;
         typedef typename DataTypes::VecDeriv VecDeriv;
-        typedef container::MechanicalObject<DataTypes> MechanicalObject;
 
         /// Root of the scene graph
         simulation::Node::SPtr root;
@@ -29,8 +27,6 @@ namespace sofa {
         /// Create the context for the scene
         void SetUp()
         {
-            // Init simulation
-            sofa::component::init();
             sofa::simulation::setSimulation(simulation = new sofa::simulation::graph::DAGSimulation());
 
             root = simulation::getSimulation()->createNewGraph("root");
@@ -53,7 +49,7 @@ namespace sofa {
     };
 
     // Define the list of DataTypes to instantiate
-    using testing::Types;
+    using ::testing::Types;
     typedef Types<
         Vec3Types
     > DataTypes; // the types to instantiate.