Salome HOME
e2738715996f00f358b54a1ef6f9f3f1c589087f
[tools/configuration.git] / cmake / FindNetgen.cmake
1 # - Find NETGEN
2 # Sets the following variables:
3 #   NETGEN_DEFINITIONS  - compile flags
4 #   NETGEN_INCLUDE_DIRS - path to the NETGEN include directories
5 #   NETGEN_LIBRARIES    - path to the NETGEN libraries to be linked against
6 #
7
8 #########################################################################
9 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
10 #
11 # This library is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU Lesser General Public
13 # License as published by the Free Software Foundation; either
14 # version 2.1 of the License, or (at your option) any later version.
15 #
16 # This library is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 # Lesser General Public License for more details.
20 #
21 # You should have received a copy of the GNU Lesser General Public
22 # License along with this library; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24 #
25 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 #
27
28 # ------
29
30 IF(NOT Netgen_FIND_QUIETLY)
31   MESSAGE(STATUS "Check for Netgen ...")
32 ENDIF()
33
34 # ------
35
36 SET(NETGEN_ROOT_DIR $ENV{NETGEN_ROOT_DIR})
37
38 IF(NETGEN_ROOT_DIR)
39   LIST(APPEND CMAKE_PREFIX_PATH "${NETGEN_ROOT_DIR}")
40 ENDIF(NETGEN_ROOT_DIR)
41
42 # Windows specific stuff:
43 # Since netgen-5.3.1 uses zlib, try to detect it
44 IF(WIN32)
45   IF(EXISTS ${NETGEN_ROOT_DIR}/cmake/FindZlib.cmake)
46     FILE(TO_CMAKE_PATH ${NETGEN_ROOT_DIR}/cmake NETGEN_CMAKE_FILES)
47     LIST(APPEND CMAKE_MODULE_PATH ${NETGEN_CMAKE_FILES})
48     SET(ZLIB_ROOT_DIR $ENV{ZLIB_ROOT_DIR})
49     INCLUDE(FindZlib)
50   ENDIF()
51 ENDIF()
52
53 FIND_PATH(_netgen_base_inc_dir nglib.h)
54 SET(NETGEN_INCLUDE_DIRS ${_netgen_base_inc_dir} ${ZLIB_INCLUDE_DIRS})
55 FIND_PATH(_netgen_add_inc_dir1 occgeom.hpp HINTS ${_netgen_base_inc_dir} PATH_SUFFIXES share/netgen/include include)
56 IF(_netgen_add_inc_dir1)
57   LIST(APPEND NETGEN_INCLUDE_DIRS ${_netgen_add_inc_dir1})
58 ENDIF()
59 FIND_PATH(_netgen_add_inc_dir2 exception.hpp HINTS ${_netgen_base_inc_dir} PATH_SUFFIXES share/netgen/include share/netgen/include/core include include/core)
60 IF(_netgen_add_inc_dir2)
61   LIST(APPEND NETGEN_INCLUDE_DIRS ${_netgen_add_inc_dir2})
62 ENDIF()
63
64 FOREACH(_lib nglib csg gen geom2d gprim interface la mesh occ stl ngcore)
65
66   FIND_LIBRARY(NETGEN_${_lib} NAMES ${_lib})
67   IF(NETGEN_${_lib})
68     LIST(APPEND NETGEN_LIBRARIES ${NETGEN_${_lib}})
69   ENDIF()
70
71 ENDFOREACH()
72
73 INCLUDE(FindPackageHandleStandardArgs)
74 FIND_PACKAGE_HANDLE_STANDARD_ARGS(NETGEN REQUIRED_VARS NETGEN_INCLUDE_DIRS NETGEN_LIBRARIES)
75
76 INCLUDE(CheckCXXSourceCompiles)
77 INCLUDE(CMakePushCheckState)
78
79 IF(NETGEN_FOUND)
80   CMAKE_PUSH_CHECK_STATE()
81
82   # Detect NETGEN V5
83   SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES} ${NETGEN_INCLUDE_DIRS}")
84   SET(CMAKE_REQUIRED_LIBRARIES "${NETGEN_LIBRARIES}")
85   CHECK_CXX_SOURCE_COMPILES("
86     #include <meshing.hpp>
87     int main()
88     {
89       netgen::Mesh* ngMesh = 0;
90       ngMesh->CalcLocalH(1.0);
91     }
92 " NETGEN_V5
93     )
94   # Detect NETGEN V6
95   SET(CMAKE_REQUIRED_FLAGS "-std=c++17")
96   CHECK_CXX_SOURCE_COMPILES("
97     //using namespace std;
98     #include <meshing.hpp>
99     int main()
100     {
101        netgen::MeshingParameters mp;
102        return !mp.meshsizefilename.empty();
103     }
104 " NETGEN_V6
105     )
106
107   CMAKE_POP_CHECK_STATE()
108
109   IF(NOT Netgen_FIND_QUIETLY)
110     MESSAGE(STATUS "Netgen library: ${NETGEN_LIBRARIES}")
111   ENDIF()
112   SET(NETGEN_DEFINITIONS "-DOCCGEOMETRY")
113
114   #RNV:  currently on windows use netgen without thread support.
115   #TODO: check support of the multithreading on windows
116   IF(WIN32)
117    SET(NETGEN_DEFINITIONS "${NETGEN_DEFINITIONS} -DNO_PARALLEL_THREADS")
118   ENDIF(WIN32)
119 ENDIF()