Add a new configure option: --enable-openmp

When this option is set, loops which are parallelized with tbb
are parallelized with openmp.
Due to a bug in libtool (it removes -fopenmp flag when linking),
a workaround is provided, but works only with GNU gcc.

Index: opencascade/ros/adm/make/TKMesh/Makefile.am
===================================================================
--- opencascade.orig/ros/adm/make/TKMesh/Makefile.am
+++ opencascade/ros/adm/make/TKMesh/Makefile.am
@@ -24,6 +24,8 @@
 
 lib_LTLIBRARIES=libTKMesh.la
 
+libTKMesh_la_CXXFLAGS = $(OPENMP_CXXFLAGS)
+
 libTKMesh_la_LIBADD = \
 ../TKMath/libTKMath.la \
 ../TKernel/libTKernel.la \
@@ -35,6 +37,12 @@
 ../TKTopAlgo/libTKTopAlgo.la \
 $(STLPort_LIB) $(CSF_TBB_LIB) 
 
+#  Work around an annoying bug in libtool, it removes -fopenmp flag when linking.
+#  The downside is that --enable-openmp can be used only with GNU gcc
+if ENABLE_OPENMP
+libTKMesh_la_LIBADD += -lgomp
+endif
+
 libTKMesh_la_SOURCES = \
 @top_srcdir@/drv/BRepMesh/BRepMesh_Array1OfBiPoint_0.cxx \
 @top_srcdir@/drv/BRepMesh/BRepMesh_Array1OfVertexOfDelaun_0.cxx \
Index: opencascade/ros/configure.in
===================================================================
--- opencascade.orig/ros/configure.in
+++ opencascade/ros/configure.in
@@ -564,6 +564,10 @@
 
 fi
 
+: ${enable_openmp=no}
+AC_OPENMP
+AM_CONDITIONAL( ENABLE_OPENMP, [test "xyes" = "x$enable_openmp"] )
+
 #---------------------------------------------------------------------
 #
 # Check for TBB Libraries
Index: opencascade/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx
===================================================================
--- opencascade.orig/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx
+++ opencascade/ros/src/BRepMesh/BRepMesh_FastDiscret.cxx
@@ -182,13 +182,20 @@
   }
   
   // mesh faces in parallel threads using TBB
-#ifdef HAVE_TBB
   if (Standard::IsReentrant())
+  {
+#ifdef HAVE_TBB
     tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *this);
-  else
+#else
+    int i, n = aFaces.size();
+#pragma omp parallel for private(i)
+    for (i = 0; i < n; ++i)
+      Process (aFaces[i]);
 #endif
-  for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
-    Process (*it);
+  }
+  else
+    for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
+      Process (*it);
 }
 
 
Index: opencascade/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx
===================================================================
--- opencascade.orig/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx
+++ opencascade/ros/src/BRepMesh/BRepMesh_IncrementalMesh.cxx
@@ -212,13 +212,20 @@
   }
 
   // mesh faces in parallel threads using TBB
-#ifdef HAVE_TBB
   if (Standard::IsReentrant())
+  {
+#ifdef HAVE_TBB
     tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *myMesh.operator->());
-  else
+#else
+    int i, n = aFaces.size();
+#pragma omp parallel for private(i)
+    for (i = 0; i < n; ++i)
+      myMesh->Process (aFaces[i]);
 #endif
-  for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
-    myMesh->Process (*it);
+  }
+  else
+    for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
+      myMesh->Process (*it);
 
   // maillage des edges non contenues dans les faces :
   Standard_Real f, l, defedge;
