diff --git a/cmake/modules/AddPTScotchFlags.cmake b/cmake/modules/AddPTScotchFlags.cmake new file mode 100644 index 0000000000000000000000000000000000000000..57376bc00597906607ec8da352f57c621417d6a3 --- /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 4d29804b2b21437570a7bfc5ad6fce2035f1ae2c..f788ed2ee2c11b324b26c2ae7798b1a9dc6cb605 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 0000000000000000000000000000000000000000..2aa9895c6640889efd784f19aed1a966855678f3 --- /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 a78a1271ec811c43b6d24265f9af05856b847ed3..1b7de34e170c618782c6fb828f9bb29e700d436c 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 6e28749351c900e7d7bafb4f6ceef2551bfe1293..df66f246638368847ca08aa1db16dc17c90705f1 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_