582ee87
diff -rupN gmsh-2.10.1-source/CMakeLists.txt gmsh-2.10.1-source-new/CMakeLists.txt
582ee87
--- gmsh-2.10.1-source/CMakeLists.txt	2015-07-30 22:12:09.000000000 +0200
582ee87
+++ gmsh-2.10.1-source-new/CMakeLists.txt	2015-08-08 01:41:33.183881781 +0200
5dbec05
@@ -160,8 +160,7 @@ set(GMSH_API
582ee87
   contrib/MeshOptimizer/MeshOptObjectiveFunction.h contrib/MeshOptimizer/MeshOptVertexCoord.h
5dbec05
   contrib/MeshQualityOptimizer/MeshQualityObjContribIdealJac.h
5dbec05
   contrib/MeshQualityOptimizer/MeshQualityObjContribInvCond.h
5dbec05
-  contrib/MeshQualityOptimizer/MeshQualityOptimizer.h
26afebd
-  contrib/MathEx/mathex.h)
5dbec05
+  contrib/MeshQualityOptimizer/MeshQualityOptimizer.h)
26afebd
 
26afebd
 get_property(IAMCHILD DIRECTORY  PROPERTY PARENT_DIRECTORY)
26afebd
 if(IAMCHILD)
582ee87
@@ -649,7 +648,7 @@ endif(HAVE_FLTK OR HAVE_QT OR ENABLE_GRA
26afebd
 
26afebd
 if(HAVE_MESH OR HAVE_PLUGINS)
26afebd
   if(ENABLE_ANN)
26afebd
-    find_library(ANN_LIB ann PATH_SUFFIXES lib)
26afebd
+    find_library(ANN_LIB ANN PATH_SUFFIXES lib)
26afebd
     find_path(ANN_INC "ANN.h" PATH_SUFFIXES src include ANN)
26afebd
     if(ANN_LIB AND ANN_INC)
26afebd
       list(APPEND EXTERNAL_LIBRARIES ${ANN_LIB})
582ee87
@@ -664,8 +663,16 @@ if(HAVE_MESH OR HAVE_PLUGINS)
26afebd
 endif(HAVE_MESH OR HAVE_PLUGINS)
26afebd
 
26afebd
 if(ENABLE_BFGS)
26afebd
-  add_subdirectory(contrib/lbfgs)
26afebd
-  include_directories(contrib/lbfgs)
26afebd
+  find_library(BFGS_LIB lbfgs PATH_SUFFIXES lib)
26afebd
+  find_path(BFGS_INC "lbfgs.h" PATH_SUFFIXES include)
26afebd
+  if(BFGS_LIB AND BFGS_INC)
26afebd
+    list(APPEND EXTERNAL_LIBRARIES ${BFGS_LIB} -lalglib)
26afebd
+    list(APPEND EXTERNAL_INCLUDES ${BFGS_INC})
26afebd
+  else(BFGS_LIB AND BFGS_INC)
26afebd
+    message(STATUS "System libbfgs not found: using contrib/lbfgs instead")
26afebd
+    add_subdirectory(contrib/lbfgs)
26afebd
+    include_directories(contrib/lbfgs)
26afebd
+  endif(BFGS_LIB AND BFGS_INC)
26afebd
   set_config_option(HAVE_BFGS "Bfgs")
26afebd
 endif(ENABLE_BFGS)
26afebd
 
582ee87
@@ -711,8 +718,16 @@ if(ENABLE_KBIPACK)
26afebd
 endif(ENABLE_KBIPACK)
26afebd
 
26afebd
 if(ENABLE_MATHEX)
26afebd
-  add_subdirectory(contrib/MathEx)
26afebd
-  include_directories(contrib/MathEx)
26afebd
+  find_library(MATHEX_LIB mathex PATH_SUFFIXES lib)
26afebd
+  find_path(MATHEX_INC "mathex.h" PATH_SUFFIXES src include)
26afebd
+  if(MATHEX_LIB AND MATHEX_INC)
26afebd
+     list(APPEND EXTERNAL_LIBRARIES ${MATHEX_LIB})
26afebd
+     list(APPEND EXTERNAL_INCLUDES ${MATHEX_INC})
26afebd
+  else(MATHEX_LIB AND MATHEX_INC)
26afebd
+     message(STATUS "System MATHEX not found: using contrib/MathEx instead")
26afebd
+    add_subdirectory(contrib/MathEx)
26afebd
+    include_directories(contrib/MathEx)
26afebd
+  endif(MATHEX_LIB AND MATHEX_INC)
26afebd
   set_config_option(HAVE_MATHEX "MathEx")
26afebd
 endif(ENABLE_MATHEX)
26afebd
 
582ee87
@@ -743,13 +758,17 @@ endif(ENABLE_POPPLER)
26afebd
 
26afebd
 if(HAVE_MESH OR HAVE_SOLVER)
26afebd
   if(ENABLE_METIS)
26afebd
-    # Gmsh currently uses Metis 4 - we should switch to Metis 5 and use the
26afebd
-    # system lib if available
26afebd
-    add_subdirectory(contrib/Metis)
26afebd
-    include_directories(contrib/Metis)
26afebd
+    find_library(METIS_LIB metis PATH_SUFFIXES lib)
26afebd
+    find_path(METIS_INC "metis.h" PATH_SUFFIXES include)
26afebd
+    if(METIS_LIB AND METIS_INC)
26afebd
+      list(APPEND EXTERNAL_LIBRARIES ${METIS_LIB})
26afebd
+      list(APPEND EXTERNAL_INCLUDES ${METIS_INC})
26afebd
+    else(METIS_LIB AND METIS_INC)
26afebd
+      message(STATUS "System metis not found: using contrib/Metis instead")
26afebd
+      add_subdirectory(contrib/Metis)
26afebd
+      include_directories(contrib/Metis)
26afebd
+    endif(METIS_LIB AND METIS_INC)
26afebd
     set_config_option(HAVE_METIS "Metis")
26afebd
-    message(STATUS "Note: By including Metis you have to comply with Metis' "
26afebd
-            "special licensing requirements stated in contrib/Metis/README.txt.")
26afebd
   endif(ENABLE_METIS)
26afebd
 
26afebd
   if(ENABLE_CHACO)
582ee87
@@ -761,8 +780,16 @@ endif(HAVE_MESH OR HAVE_SOLVER)
26afebd
 
5dbec05
 if(HAVE_MESH)
26afebd
   if(ENABLE_VORO3D)
26afebd
-    add_subdirectory(contrib/voro++)
26afebd
-    include_directories(contrib/voro++/src)
26afebd
+    find_library(VORO3D_LIB voro++ PATH_SUFFIXES lib)
26afebd
+    find_path(VORO3D_INC "voro++.hh" PATH_SUFFIXES include/voro++)
26afebd
+    if(VORO3D_LIB AND VORO3D_INC)
26afebd
+      list(APPEND EXTERNAL_LIBRARIES ${VORO3D_LIB})
26afebd
+      list(APPEND EXTERNAL_INCLUDES ${VORO3D_INC})
26afebd
+    else(VORO3D_LIB AND VORO3D_INC)
26afebd
+      message(STATUS "System voro++ not found: using contrib/voro++ instead")
26afebd
+      add_subdirectory(contrib/voro++)
26afebd
+      include_directories(contrib/voro++)
26afebd
+    endif(VORO3D_LIB AND VORO3D_INC)
26afebd
     set_config_option(HAVE_VORO3D "Voro3D")
26afebd
   endif(ENABLE_VORO3D)
26afebd
 
582ee87
@@ -774,9 +801,22 @@ if(HAVE_MESH)
26afebd
   endif(ENABLE_BLOSSOM)
26afebd
 
26afebd
   if(ENABLE_NETGEN)
26afebd
-    add_subdirectory(contrib/Netgen)
582ee87
-    include_directories(contrib/Netgen contrib/Netgen/libsrc/include
26afebd
-                        contrib/Netgen/nglib)
26afebd
+    find_library(NETGEN_LIB nglib PATH_SUFFIXES lib)
26afebd
+    find_path(NETGEN_INC "nglib.h" PATH_SUFFIXES include/netgen-mesher)
26afebd
+    if(NETGEN_LIB AND NETGEN_INC)
26afebd
+      list(APPEND EXTERNAL_LIBRARIES ${NETGEN_LIB})
26afebd
+      list(APPEND EXTERNAL_INCLUDES ${NETGEN_INC})
26afebd
+      # Netgen private headers contain what contrib/Salome does
5dbec05
+      list(APPEND EXTERNAL_LIBRARIES -lngocc -lngcsg -lngmesh)
26afebd
+      list(APPEND EXTERNAL_INCLUDES ${NETGEN_INC}/private ${NETGEN_INC} ${NETGEN_INC}/private/include)
26afebd
+      add_definitions(-DOCCGEOMETRY)
26afebd
+      set_config_option(HAVE_SALOME "Salome")
26afebd
+    else(NETGEN_LIB AND NETGEN_INC)
26afebd
+      message(STATUS "System netgen not found: using contrib/Netgen instead")
26afebd
+      add_subdirectory(contrib/Netgen)
582ee87
+      include_directories(contrib/Netgen contrib/Netgen/libsrc/include
26afebd
+                          contrib/Netgen/nglib)
26afebd
+    endif(NETGEN_LIB AND NETGEN_INC)
26afebd
     set_config_option(HAVE_NETGEN "Netgen")
26afebd
     add_definitions(-DNO_PARALLEL_THREADS -DNOTCL)
26afebd
   endif(ENABLE_NETGEN)
582ee87
@@ -788,8 +828,8 @@ if(HAVE_MESH)
26afebd
   endif(ENABLE_BAMG)
26afebd
 
26afebd
   if(ENABLE_MMG3D)
26afebd
-    find_library(MMG3D_LIB mmg3dlib4.0 PATH_SUFFIXES lib)
26afebd
-    find_path(MMG3D_INC "libmmg3d.h" PATH_SUFFIXES src include)
26afebd
+    find_library(MMG3D_LIB mmg3d4 PATH_SUFFIXES lib)
26afebd
+    find_path(MMG3D_INC "libmmg3d4.h" PATH_SUFFIXES src include)
26afebd
     if(MMG3D_LIB AND MMG3D_INC)
26afebd
        list(APPEND EXTERNAL_LIBRARIES ${MMG3D_LIB})
26afebd
        list(APPEND EXTERNAL_INCLUDES ${MMG3D_INC})
582ee87
@@ -1131,19 +1171,6 @@ if(ENABLE_OCC)
26afebd
       endif(NOT OCC_CONFIG_H)
26afebd
     endif(OCC_INC)
26afebd
   endif(NUM_OCC_LIBS EQUAL NUM_OCC_LIBS_REQUIRED)
26afebd
-  if(HAVE_OCC)
26afebd
-    if(ENABLE_SGEOM)
26afebd
-      add_subdirectory(contrib/SGEOM)
26afebd
-      include_directories(contrib/SGEOM)
26afebd
-      add_definitions(-DSGEOMGEOMETRY)
26afebd
-      set_config_option(HAVE_SGEOM "SGEOM")
26afebd
-    elseif(ENABLE_SALOME)
26afebd
-      add_subdirectory(contrib/Salome)
26afebd
-      include_directories(contrib/Salome)
26afebd
-      add_definitions(-DOCCGEOMETRY)
26afebd
-      set_config_option(HAVE_SALOME "Salome")
26afebd
-    endif(ENABLE_SGEOM)
26afebd
-  endif(HAVE_OCC)
26afebd
 endif(ENABLE_OCC)
26afebd
 
26afebd
 if(ENABLE_ACIS)
582ee87
diff -rupN gmsh-2.10.1-source/Geo/GModelFactory.cpp gmsh-2.10.1-source-new/Geo/GModelFactory.cpp
582ee87
--- gmsh-2.10.1-source/Geo/GModelFactory.cpp	2015-06-26 10:58:42.000000000 +0200
582ee87
+++ gmsh-2.10.1-source-new/Geo/GModelFactory.cpp	2015-08-08 01:38:41.137003298 +0200
5dbec05
@@ -496,7 +496,7 @@ void GeoFactory::healGeometry(GModel *gm
26afebd
 #include <GeomAPI_PointsToBSpline.hxx>
26afebd
 #include "OCC_Connect.h"
26afebd
 #if defined(HAVE_SALOME)
26afebd
-#include "Partition_Spliter.hxx"
26afebd
+#include <occ/Partition_Spliter.hxx>
26afebd
 #endif
26afebd
 
26afebd
 GVertex *OCCFactory::addVertex(GModel *gm, double x, double y, double z, double lc)
582ee87
diff -rupN gmsh-2.10.1-source/Geo/GModelIO_OCC.cpp gmsh-2.10.1-source-new/Geo/GModelIO_OCC.cpp
582ee87
--- gmsh-2.10.1-source/Geo/GModelIO_OCC.cpp	2015-04-18 09:33:43.000000000 +0200
582ee87
+++ gmsh-2.10.1-source-new/Geo/GModelIO_OCC.cpp	2015-08-08 01:38:41.138003321 +0200
26afebd
@@ -19,7 +19,7 @@
26afebd
 #if defined(HAVE_OCC)
26afebd
 
26afebd
 #if defined(HAVE_SALOME)
26afebd
-#include "Partition_Spliter.hxx"
26afebd
+#include <occ/Partition_Spliter.hxx>
26afebd
 #endif
26afebd
 
582ee87
 #include <BRepBuilderAPI_Transform.hxx>
582ee87
diff -rupN gmsh-2.10.1-source/Mesh/CMakeLists.txt gmsh-2.10.1-source-new/Mesh/CMakeLists.txt
582ee87
--- gmsh-2.10.1-source/Mesh/CMakeLists.txt	2015-03-22 17:48:56.000000000 +0100
582ee87
+++ gmsh-2.10.1-source-new/Mesh/CMakeLists.txt	2015-08-08 01:38:41.138003321 +0200
582ee87
@@ -46,6 +46,7 @@ set(SRC
26afebd
     Field.cpp
26afebd
     CenterlineField.cpp
26afebd
     surfaceFiller.cpp
26afebd
+    nglib_gmsh.cpp
26afebd
 )
26afebd
 
26afebd
 file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 
582ee87
diff -rupN gmsh-2.10.1-source/Mesh/CMakeLists.txt.orig gmsh-2.10.1-source-new/Mesh/CMakeLists.txt.orig
582ee87
--- gmsh-2.10.1-source/Mesh/CMakeLists.txt.orig	1970-01-01 01:00:00.000000000 +0100
582ee87
+++ gmsh-2.10.1-source-new/Mesh/CMakeLists.txt.orig	2015-03-22 17:48:56.000000000 +0100
582ee87
@@ -0,0 +1,52 @@
582ee87
+# Gmsh - Copyright (C) 1997-2015 C. Geuzaine, J.-F. Remacle
582ee87
+#
582ee87
+# See the LICENSE.txt file for license information. Please report all
582ee87
+# bugs and problems to the public mailing list <gmsh@geuz.org>.
582ee87
+
582ee87
+set(SRC
582ee87
+  Generator.cpp
582ee87
+    meshGEdge.cpp 
582ee87
+      meshGEdgeExtruded.cpp
582ee87
+    meshGFace.cpp 
582ee87
+    meshGFaceElliptic.cpp
582ee87
+      meshGFaceTransfinite.cpp meshGFaceExtruded.cpp 
582ee87
+      meshGFaceBamg.cpp meshGFaceBDS.cpp meshGFaceDelaunayInsertion.cpp 
582ee87
+      meshGFaceLloyd.cpp meshGFaceOptimize.cpp 
582ee87
+      meshGFaceQuadrilateralize.cpp 
582ee87
+    meshGRegion.cpp 
582ee87
+      meshGRegionDelaunayInsertion.cpp meshGRegionTransfinite.cpp 
582ee87
+      meshGRegionExtruded.cpp  meshGRegionCarveHole.cpp 
582ee87
+      meshGRegionLocalMeshMod.cpp meshGRegionMMG3D.cpp
582ee87
+    meshMetric.cpp
582ee87
+    BackgroundMeshTools.cpp 
582ee87
+    BackgroundMesh.cpp 
582ee87
+    BGMBase.cpp 
582ee87
+    BackgroundMesh2D.cpp 
582ee87
+    BackgroundMesh3D.cpp 
582ee87
+    BackgroundMeshManager.cpp 
582ee87
+    pointInsertionRTreeTools.cpp 
582ee87
+    pointInsertion.cpp 
582ee87
+    qualityMeasures.cpp 
582ee87
+    BoundaryLayers.cpp 
582ee87
+    BDS.cpp 
582ee87
+    HighOrder.cpp 
582ee87
+    meshPartition.cpp
582ee87
+    meshRefine.cpp
582ee87
+    multiscalePartition.cpp
582ee87
+    QuadTriUtils.cpp
582ee87
+      QuadTriExtruded2D.cpp QuadTriExtruded3D.cpp QuadTriTransfinite3D.cpp
582ee87
+    simple3D.cpp
582ee87
+  DivideAndConquer.cpp
582ee87
+    Voronoi3D.cpp
582ee87
+    Levy3D.cpp
582ee87
+    periodical.cpp
582ee87
+    directions3D.cpp
582ee87
+    filterElements.cpp
582ee87
+    yamakawa.cpp
582ee87
+    Field.cpp
582ee87
+    CenterlineField.cpp
582ee87
+    surfaceFiller.cpp
582ee87
+)
582ee87
+
582ee87
+file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) 
582ee87
+append_gmsh_src(Mesh "${SRC};${HDR}")
582ee87
diff -rupN gmsh-2.10.1-source/Mesh/meshGRegionMMG3D.cpp gmsh-2.10.1-source-new/Mesh/meshGRegionMMG3D.cpp
582ee87
--- gmsh-2.10.1-source/Mesh/meshGRegionMMG3D.cpp	2015-03-22 17:48:56.000000000 +0100
582ee87
+++ gmsh-2.10.1-source-new/Mesh/meshGRegionMMG3D.cpp	2015-08-08 01:38:41.139003345 +0200
26afebd
@@ -19,7 +19,7 @@
26afebd
 #include "Context.h"
26afebd
 
26afebd
 extern "C" {
26afebd
-#include <libmmg3d.h>
26afebd
+#include <libmmg3d4.h>
26afebd
 #define M_UNUSED    (1 << 0)
26afebd
 }
26afebd