Salome HOME
Merge branch 'agr/medcoupling_tool'
[tools/medcoupling.git] / cmake_files / FindMetis.cmake
1 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # ------
21
22 MESSAGE(STATUS "Check for metis ...")
23
24 SET(METIS_ROOT_DIR $ENV{METIS_ROOT_DIR} CACHE PATH "Path to the METIS.")
25 IF(METIS_ROOT_DIR)
26   LIST(APPEND CMAKE_LIBRARY_PATH "${METIS_ROOT_DIR}")
27   LIST(APPEND CMAKE_LIBRARY_PATH "${METIS_ROOT_DIR}/lib")
28   LIST(APPEND CMAKE_INCLUDE_PATH "${METIS_ROOT_DIR}/Lib")
29   LIST(APPEND CMAKE_INCLUDE_PATH "${METIS_ROOT_DIR}/include")
30 ENDIF(METIS_ROOT_DIR)
31
32 FIND_LIBRARY(METIS_LIBRARIES metis)
33 FIND_PATH(METIS_INCLUDE_DIRS metis.h)
34
35 IF(NOT METIS_LIBRARIES OR NOT METIS_INCLUDE_DIRS)
36   MESSAGE(FATAL_ERROR "Metis not found; please set METIS_ROOT_DIR and check target directory.")
37 ENDIF()
38
39 INCLUDE(FindPackageHandleStandardArgs)
40 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Metis REQUIRED_VARS METIS_INCLUDE_DIRS METIS_LIBRARIES)
41 FILE(READ ${METIS_INCLUDE_DIRS}/metis.h metis_h_content)
42 STRING(REPLACE "\n" ";" list_metis_h_content ${metis_h_content})
43 FOREACH(ln ${list_metis_h_content})
44   IF("${ln}" MATCHES "^#define METIS_VER_MAJOR")
45     STRING(REPLACE "#define METIS_VER_MAJOR" "" metis_major_version "${ln}")
46     STRING(STRIP "${metis_major_version}" metis_major_version)
47   ENDIF("${ln}" MATCHES "^#define METIS_VER_MAJOR")
48 ENDFOREACH(ln ${list_metis_h_content})
49 IF(metis_major_version STREQUAL 5)
50   SET(MEDCOUPLING_METIS_V5 1)
51   MESSAGE(STATUS "Metis maj version 5 detected.")
52 ELSE(metis_major_version STREQUAL 5)
53    MESSAGE(STATUS "Metis maj version 4 detected.")
54 ENDIF(metis_major_version STREQUAL 5)