From c8580cd01c5276d96526f505444815944436c01b Mon Sep 17 00:00:00 2001 From: Markus Blatt <markus@dr-blatt.de> Date: Tue, 24 Feb 2015 19:02:30 +0100 Subject: [PATCH] Adds a find module for PT-Scotch. This is e.g. needed for dune-alugrid and might be a first step for getting rid off the ParMETIS dependency. --- cmake/modules/AddPTScotchFlags.cmake | 25 +++++++++ cmake/modules/CMakeLists.txt | 2 + cmake/modules/FindPTScotch.cmake | 83 ++++++++++++++++++++++++++++ cmake/modules/Makefile.am | 2 + config.h.cmake | 3 + 5 files changed, 115 insertions(+) create mode 100644 cmake/modules/AddPTScotchFlags.cmake create mode 100644 cmake/modules/FindPTScotch.cmake diff --git a/cmake/modules/AddPTScotchFlags.cmake b/cmake/modules/AddPTScotchFlags.cmake new file mode 100644 index 000000000..57376bc00 --- /dev/null +++ b/cmake/modules/AddPTScotchFlags.cmake @@ -0,0 +1,25 @@ +# Module providing convenience functions for using PT-Scotch +# +# Provides the following functions: +# +# add_dune_parmetis_flags(target1 target2 ...) +# +# Adds the necessary flags to compile and link the targets with PT-Scotch support. +# +function(add_dune_ptscotch_flags _targets) + if(PTSCOTCH_FOUND) + foreach(_target ${_targets}) + message("pt-scotch target_link_libraries(${_target} ${PTSCOTCH_LIBRARY} ${PTSCOTCHERR_LIBRARY}") + target_link_libraries(${_target} ${PTSCOTCH_LIBRARY} ${PTSCOTCHERR_LIBRARY}) + GET_TARGET_PROPERTY(_props ${_target} INCLUDE_DIRECTORIES) + string(REPLACE "_props-NOTFOUND" "" _props "${_props}") + SET_TARGET_PROPERTIES(${_target} PROPERTIES INCLUDE_DIRECTORIES + "${_props};${PTSCOTCH_INCLUDE_DIRS}") + GET_TARGET_PROPERTY(_props ${_target} COMPILE_DEFINITIONS) + string(REPLACE "_props-NOTFOUND" "" _props "${_props}") + SET_TARGET_PROPERTIES(${_target} PROPERTIES COMPILE_DEFINITIONS + "${_props};") + endforeach(_target ${_targets}) + add_dune_mpi_flags(${_targets}) + endif(PTSCOTCH_FOUND) +endfunction(add_dune_ptscotch_flags) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 4d29804b2..f788ed2ee 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -2,6 +2,7 @@ set(modules AddGMPFlags.cmake AddMETISFlags.cmake AddParMETISFlags.cmake + AddPTScotchFlags.cmake AddUMFPackFlags.cmake CheckCXX11Features.cmake DuneBoost.cmake @@ -22,6 +23,7 @@ set(modules FindMETIS.cmake FindMProtect.cmake FindParMETIS.cmake + FindPTScotch.cmake FindUMFPack.cmake Headercheck.cmake LanguageSupport.cmake diff --git a/cmake/modules/FindPTScotch.cmake b/cmake/modules/FindPTScotch.cmake new file mode 100644 index 000000000..2aa9895c6 --- /dev/null +++ b/cmake/modules/FindPTScotch.cmake @@ -0,0 +1,83 @@ +# Module that checks whether PT-Scotch is available. +# +# Accepts the following variables: +# +# PTSCOTCH_ROOT: Prefix where PT-Scotch is installed. +# PTSCOTCH_SUFFIX: Scotch might be compiled using different +# integer sizes (int32, int32, long). When +# this is is set the headers and libaries +# are search under the suffix +# include/scotch-${PTSCOTCH_SUFFIX, and +# lib/scotch-${PTSCOTCH_SUFFIX}, respectively. +# Sets the following variables: +# PTSCOTCH_INCLUDE_DIRS: All include directories needed to compile PT-Scotch programs. +# PTSCOTCH_LIBRARIES: Alle libraries needed to link PT-Scotch programs. +# PTSCOTCH_FOUND: True if PT-Scotch was found. +# +# Provides the following macros: +# +# find_package(PTScotch) + +include(DuneMPI) +macro(_search_pt_lib libvar libname doc) + find_library(${libvar} ${libname} + PATHS${PTSCOTCH_ROOT} PATH_SUFFIXES ${PATH_SUFFIXES} + NO_DEFAULT_PATH + DOC "${doc}") + find_library(${libvar} ${libname}) +endmacro(_search_pt_lib) + +if(PTSCOTCH_SUFFIX) + set(PATH_SUFFIXES "scotch-${PTSCOTCH_SUFFIX}") +else(PTSCOTCH_SUFFIX) + set(PATH_SUFFIXES "scotch") +endif(PTSCOTCH_SUFFIX) + +include(CMakePushCheckState) +cmake_push_check_state() # Save variables +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${MPI_DUNE_INCLUDE_PATH}) +set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${MPI_DUNE_COMPILE_FLAGS}") + +find_path(PTSCOTCH_INCLUDE_DIR ptscotch.h + PATHS ${PTSCOTCH_ROOT} + PATH_SUFFIXES ${PATH_SUFFIXES} + NO_DEFAULT_PATH + DOC "Include directory of PT-Scotch") +find_path(PTSCOTCH_INCLUDE_DIR ptscotch.h + PATH_SUFFIXES ${PATH_SUFFIXES}) + +_search_pt_lib(PTSCOTCH_LIBRARY ptscotch "The main PT-Scotch library.") +_search_pt_lib(PTSCOTCHERR_LIBRARY ptscotcherr "The PT-Scotch error library.") + +# behave like a CMake module is supposed to behave +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + "PTScotch" + DEFAULT_MSG + PTSCOTCH_INCLUDE_DIR + PTSCOTCH_LIBRARY + PTSCOTCHERR_LIBRARY +) +#restore old values +cmake_pop_check_state() + +if(PTSCOTCH_FOUND) + set(PTSCOTCH_INCLUDE_DIRS ${PTSCOTCH_INCLUDE_DIR}) + set(PTSCOTCH_LIBRARIES ${PTSCOTCH_LIBRARY} ${PTSCOTCHERR_LIBRARY} ${MPI_DUNE_LIBRARIES} + CACHE FILEPATH "All libraries needed to link programs using PT-Scotch") + set(PTSCOCH_LINK_FLAGS "${DUNE_MPI_LINK_FLAGS}" + CACHE STRING "PT-Scotch link flags") + set(HAVE_PTSCOTCH 1) + # log result + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determing location of PT-Scotch succeded:\n" + "Include directory: ${PTSCOTCH_INCLUDE_DIRS}\n" + "Library directory: ${PTSCOTCH_LIBRARIES}\n\n") + + foreach(dir ${PTSCOCTH_INCLUDE_DIRS}) + set_property(GLOBAL APPEND PROPERTY ALL_PKG_FLAGS "-I${dir}") + endforeach() + set_property(GLOBAL APPEND PROPERTY ALL_PKG_LIBS "${PTSCOTCH_LIBRARIES}") +endif(PTSCOTCH_FOUND) + +mark_as_advanced(PTSCOTCH_INCLUDE_DIR PTSCOTCH_LIBRARIES HAVE_PTSCOTCH) diff --git a/cmake/modules/Makefile.am b/cmake/modules/Makefile.am index a78a1271e..1b7de34e1 100644 --- a/cmake/modules/Makefile.am +++ b/cmake/modules/Makefile.am @@ -2,6 +2,7 @@ MODULES = \ AddGMPFlags.cmake \ AddMETISFlags.cmake \ AddParMETISFlags.cmake \ + AddPTScotchFlags.cmake \ AddUMFPackFlags.cmake \ CheckCXX11Features.cmake \ DuneBoost.cmake \ @@ -22,6 +23,7 @@ MODULES = \ FindMETIS.cmake \ FindMProtect.cmake \ FindParMETIS.cmake \ + FindPTScotch.cmake \ FindUMFPack.cmake \ Headercheck.cmake \ LanguageSupport.cmake \ diff --git a/config.h.cmake b/config.h.cmake index 6e2874935..df66f2466 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -124,6 +124,9 @@ by configure _and_ if the application uses the PARMETIS_CPPFLAGS */ #cmakedefine HAVE_PARMETIS ENABLE_PARMETIS +/* Define to 1 if PT-Scotch is available */ +#cmakedefine HAVE_PTSCOTCH 1 + /* Include always useful headers */ #include "FC.h" #define FC_FUNC FC_GLOBAL_ -- GitLab