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