Commit 299a07ab authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

FindMetis now checks for the correct version of Metis

parent d742e577
......@@ -25,7 +25,7 @@
##
############################################################################################################################
CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
CMAKE_MINIMUM_REQUIRED (VERSION 3.14)
PROJECT ( walberla )
......
# METIS Find Module for MSTK
# Shamelessly stolen from Amanzi open source code https://software.lanl.gov/ascem/trac
#
# Usage:
# Control the search through METIS_DIR or setting environment variable
# METIS_ROOT to the METIS installation prefix.
#
# This module does not search default paths!
#
# Following variables are set:
# METIS_FOUND (BOOL) Flag indicating if METIS was found
# METIS_INCLUDE_DIR (PATH) Path to the METIS include file
# METIS_INCLUDE_DIRS (LIST) List of all required include files
# METIS_LIBRARY_DIR (PATH) Path to the METIS library
# METIS_LIBRARY (FILE) METIS library
# METIS_LIBRARIES (LIST) List of all required METIS libraries
#
# #############################################################################
#[=======================================================================[.rst:
FindMETIS
-------
# Standard CMake modules see CMAKE_ROOT/Modules
include(FindPackageHandleStandardArgs)
# Amanzi CMake functions see <root>/tools/cmake for source
#include(PrintVariable)
if ( METIS_LIBRARIES AND METIS_INCLUDE_DIRS )
# Do nothing. Variables are set. No need to search again
else(METIS_LIBRARIES AND METIS_INCLUDE_DIRS)
# Cache variables
if(METIS_DIR)
set(METIS_DIR "${METIS_DIR}" CACHE PATH "Path to search for METIS include and library files")
else()
if( DEFINED ENV{METIS_ROOT} )
set(METIS_DIR "$ENV{METIS_ROOT}" CACHE PATH "Path to search for METIS include and library files")
endif()
endif()
if(METIS_INCLUDE_DIR)
set(METIS_INCLUDE_DIR "${METIS_INCLUDE_DIR}" CACHE PATH "Path to search for METIS include files")
endif()
if(METIS_LIBRARY_DIR)
set(METIS_LIBRARY_DIR "${METIS_LIBRARY_DIR}" CACHE PATH "Path to search for METIS library files")
endif()
# Search for include files
# Search order preference:
# (1) METIS_INCLUDE_DIR - check existence of path AND if the include files exist
# (2) METIS_DIR/<include>
# (3) Default CMake paths See cmake --html-help=out.html file for more information.
#
set(metis_inc_names "metis.h")
if (METIS_INCLUDE_DIR)
if (EXISTS "${METIS_INCLUDE_DIR}")
find_path(metis_test_include_path
NAMES ${metis_inc_names}
HINTS ${METIS_INCLUDE_DIR}
NO_DEFAULT_PATH)
set(METIS_INCLUDE_DIR "${metis_test_include_path}")
Finds the METIS library.
else()
message(SEND_ERROR "METIS_INCLUDE_DIR=${METIS_INCLUDE_DIR} does not exist")
set(METIS_INCLUDE_DIR "METIS_INCLUDE_DIR-NOTFOUND")
endif()
Result Variables
^^^^^^^^^^^^^^^^
else()
This will define the following variables:
# Metis sometimes puts the include files in a subdir called Lib
``METIS_FOUND``
True if the system has the METIS library.
``METIS_INCLUDE_DIRS``
Include directories needed to use METIS.
``METIS_LIBRARIES``
Libraries needed to link to METIS.
set(metis_inc_suffixes "include" "Lib")
if(METIS_DIR)
Cache Variables
^^^^^^^^^^^^^^^
if (EXISTS "${METIS_DIR}" )
The following cache variables may also be set:
find_path(METIS_INCLUDE_DIR
NAMES ${metis_inc_names}
HINTS ${METIS_DIR}
PATH_SUFFIXES ${metis_inc_suffixes}
NO_DEFAULT_PATH)
``METIS_INCLUDE_DIR``
The directory containing ``METIS.h``.
``METIS_LIBRARY``
The path to the METIS library.
else()
message(SEND_ERROR "METIS_DIR=${METIS_DIR} does not exist")
set(METIS_INCLUDE_DIR "METIS_INCLUDE_DIR-NOTFOUND")
endif()
#]=======================================================================]
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_path(METIS_INCLUDE_DIR
NAMES metis.h
)
set(CMAKE_FIND_DEBUG_MODE FALSE)
find_library(METIS_LIBRARY
NAMES metis
)
else()
find_path(METIS_INCLUDE_DIR
NAMES ${metis_inc_names}
PATH_SUFFIXES ${metis_inc_suffixes})
endif()
endif()
# Search for libraries
# Search order preference:
# (1) METIS_LIBRARY_DIR - check existence of path AND if the library file exists
# (2) METIS_DIR/<lib,Lib>
# (3) Default CMake paths See cmake --html-help=out.html file for more information.
#
set(metis_lib_names "metis")
if (METIS_LIBRARY_DIR)
if (EXISTS "${METIS_LIBRARY_DIR}")
find_library(METIS_LIBRARY
NAMES ${metis_lib_names}
HINTS ${METIS_LIBRARY_DIR}
NO_DEFAULT_PATH)
else()
message(SEND_ERROR "METIS_LIBRARY_DIR=${METIS_LIBRARY_DIR} does not exist")
set(METIS_LIBRARY "METIS_LIBRARY-NOTFOUND")
endif()
else()
list(APPEND metis_lib_suffixes "lib" "Lib")
if(METIS_DIR)
if (EXISTS "${METIS_DIR}" )
find_library(METIS_LIBRARY
NAMES ${metis_lib_names}
HINTS ${METIS_DIR}
PATH_SUFFIXES ${metis_lib_suffixes}
NO_DEFAULT_PATH)
else()
message(SEND_ERROR "METIS_DIR=${METIS_DIR} does not exist")
set(METISLIBRARY "METIS_LIBRARY-NOTFOUND")
endif()
else()
find_library(METIS_LIBRARY
NAMES ${metis_lib_names}
PATH_SUFFIXES ${metis_lib_suffixes})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Metis
FOUND_VAR METIS_FOUND
REQUIRED_VARS
METIS_LIBRARY
METIS_INCLUDE_DIR
VERSION_VAR METIS_VERSION
)
if(METIS_FOUND)
# Build and run test program
try_compile(METIS_TEST_RUNS
"${CMAKE_BINARY_DIR}"
"${CMAKE_SOURCE_DIR}/cmake/TestMetis.cpp"
CXX_STANDARD 14
OUTPUT_VARIABLE METIS_ERROR
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${METIS_INCLUDE_DIR}")
if (NOT METIS_TEST_RUNS)
message(FATAL_ERROR "Metis not build with 64-bit integer and 64-bit float. (${METIS_INCLUDE_DIR})")
endif()
# Define prerequisite packages
set(METIS_LIBRARIES ${METIS_LIBRARY})
set(METIS_INCLUDE_DIRS ${METIS_INCLUDE_DIR})
set(METIS_LIBRARIES ${METIS_LIBRARY})
endif(METIS_LIBRARIES AND METIS_INCLUDE_DIRS )
# Send useful message if everything is found
find_package_handle_standard_args(METIS DEFAULT_MSG
METIS_LIBRARIES
METIS_INCLUDE_DIRS)
# find_package_handle_standard_args should set METIS_FOUND but it does not!
if ( METIS_LIBRARIES AND METIS_INCLUDE_DIRS)
set(METIS_FOUND TRUE)
else()
set(METIS_FOUND FALSE)
endif()
# Define the version
mark_as_advanced(
METIS_INCLUDE_DIR
METIS_INCLUDE_DIRS
METIS_LIBRARY
METIS_LIBRARIES
METIS_LIBRARY_DIR
)
\ No newline at end of file
METIS_INCLUDE_DIR
METIS_LIBRARY
)
#include <metis.h>
int main( int argc, char* argv[] )
{
static_assert(IDXTYPEWIDTH==64, "Metis has to be build with 64-bit integer support!");
static_assert(REALTYPEWIDTH==64, "Metis has to be build with 64-bit floating point precision!");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment