Commit 014c737f authored by Praetorius, Simon's avatar Praetorius, Simon

updated PETSc cmake configuration

parent e2507373
......@@ -157,11 +157,23 @@ endif (AMDIS_NEED_CXX11)
#load mpi-compiler for use with parmetis and parallel_domain
if(AMDIS_HAS_PARALLEL_DOMAIN)
find_package(MPI REQUIRED)
if(MPI_FOUND)
list(APPEND AMDIS_LIBRARIES ${MPI_LIBRARIES})
list(APPEND AMDIS_COMPILEFLAGS ${MPI_COMPILE_FLAGS})
list(APPEND AMDIS_INCLUDE_DIRS ${MPI_INCLUDE_PATH})
endif(MPI_FOUND)
list(APPEND AMDIS_LIBRARIES ${MPI_LIBRARIES})
list(APPEND AMDIS_COMPILEFLAGS ${MPI_COMPILE_FLAGS})
list(APPEND AMDIS_INCLUDE_DIRS ${MPI_INCLUDE_PATH})
find_library(PARMETIS_LIB parmetis)
if(PARMETIS_LIB)
list(APPEND AMDIS_LIBRARIES ${PARMETIS_LIB})
else(PARMETIS_LIB)
message(FATAL_ERROR "could not find the parmetis libraries needed by amdis")
endif(PARMETIS_LIB)
find_library(METIS_LIB metis)
if(METIS_LIB)
list(APPEND AMDIS_LIBRARIES ${METIS_LIB})
else(METIS_LIB)
message(FATAL_ERROR "could not find the metis libraries needed by amdis")
endif(METIS_LIB)
if(AMDIS_HAS_PARALLEL_DOMAIN STREQUAL "PETSC")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${AMDIS_DIR})
set(PETSC_EXECUTABLE_RUNS ON)
......@@ -175,18 +187,6 @@ if(AMDIS_HAS_PARALLEL_DOMAIN)
elseif(AMDIS_HAS_PARALLEL_DOMAIN STREQUAL "PMTL")
find_package(MTL REQUIRED)
list(APPEND AMDIS_LIBRARIES ${MTL_LIBRARIES})
find_library(PARMETIS_LIB parmetis)
if(PARMETIS_LIB)
list(APPEND AMDIS_LIBRARIES ${PARMETIS_LIB})
else(PARMETIS_LIB)
message(FATAL_ERROR "could not find the parmetis libraries needed by amdis")
endif(PARMETIS_LIB)
find_library(METIS_LIB metis)
if(METIS_LIB)
list(APPEND AMDIS_LIBRARIES ${METIS_LIB})
else(METIS_LIB)
message(FATAL_ERROR "could not find the metis libraries needed by amdis")
endif(METIS_LIB)
endif()
elseif(AMDIS_NEED_SEQ_PETSC)
......
# CorrectWindowsPaths - this module defines one macro
#
# CONVERT_CYGWIN_PATH( PATH )
# This uses the command cygpath (provided by cygwin) to convert
# unix-style paths into paths useable by cmake on windows
macro (CONVERT_CYGWIN_PATH _path)
if (WIN32)
EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}}
OUTPUT_VARIABLE ${_path})
string (STRIP ${${_path}} ${_path})
endif (WIN32)
endmacro (CONVERT_CYGWIN_PATH)
......@@ -21,7 +21,14 @@
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
# endif (NOT foo_current)
#
# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE)
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale. The LANGUAGE
# variable is either C or CXX indicating which compiler the test should
# use.
# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS)
# DEPRECATED! This is only included for backwards compatability. Use
# the more general MULTIPASS_SOURCE_RUNS instead.
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale.
......@@ -39,7 +46,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
# The name of the stored value for the given state
set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state})
if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
set (_states_current "NO")
set (_states_current "NO")
endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE)
list (REMOVE_AT _args 0)
......@@ -61,7 +68,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
if (_cmd STREQUAL "DEPENDENTS")
list (REMOVE_AT _args 0)
foreach (dep ${_args})
set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
endforeach (dep)
endif (_cmd STREQUAL "DEPENDENTS")
set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
......@@ -70,9 +77,9 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
endmacro (FIND_PACKAGE_MULTIPASS)
macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
include (CheckCSourceRuns)
# This is a ridiculous hack. CHECK_C_SOURCE_* thinks that if the
macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language)
include (Check${language}SourceRuns)
# This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the
# *name* of the return variable doesn't change, then the test does
# not need to be re-run. We keep an internal count which we
# increment to guarantee that every test name is unique. If we've
......@@ -86,6 +93,14 @@ macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs})
set (CMAKE_REQUIRED_INCLUDES ${includes})
set (CMAKE_REQUIRED_LIBRARIES ${libraries})
check_c_source_runs ("${source}" ${testname})
if(${language} STREQUAL "C")
check_c_source_runs ("${source}" ${testname})
elseif(${language} STREQUAL "CXX")
check_cxx_source_runs ("${source}" ${testname})
endif()
set (${runs} "${${testname}}")
endmacro (MULTIPASS_SOURCE_RUNS)
macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C")
endmacro (MULTIPASS_C_SOURCE_RUNS)
......@@ -38,23 +38,34 @@
#
# assuming both directories exist.
# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
include (CorrectWindowsPaths)
macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll))" _all_tokens "${LINK_LINE}")
set (_libs_found)
set (_directory_list)
string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))" _all_tokens "${LINK_LINE}")
set (_libs_found "")
set (_directory_list "")
foreach (token ${_all_tokens})
if (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
# If it's a library path, add it to the list
string (REGEX REPLACE "^-L" "" token ${token})
string (REGEX REPLACE "//" "/" token ${token})
convert_cygwin_path(token)
list (APPEND _directory_list ${token})
elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll))")
elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))")
# It's a library, resolve the path by looking in the list and then (by default) in system directories
string (REGEX REPLACE "^-l" "" token ${token})
set (_root)
if (token MATCHES "^/") # We have an absolute path, add root to the search path
set (_root "/")
if (WIN32) #windows expects "libfoo", linux expects "foo"
string (REGEX REPLACE "^-l" "lib" token ${token})
else (WIN32)
string (REGEX REPLACE "^-l" "" token ${token})
endif (WIN32)
set (_root "")
if (token MATCHES "^/") # We have an absolute path
#separate into a path and a library name:
string (REGEX MATCH "[^/]*\\.(a|so|dll|lib)$" libname ${token})
string (REGEX MATCH ".*[^${libname}$]" libpath ${token})
convert_cygwin_path(libpath)
set (_directory_list ${_directory_list} ${libpath})
set (token ${libname})
endif (token MATCHES "^/")
set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
find_library (_lib ${token} HINTS ${_directory_list} ${_root})
......@@ -78,10 +89,11 @@ endmacro (RESOLVE_LIBRARIES)
macro (RESOLVE_INCLUDES INCS COMPILE_LINE)
string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}")
set (_incs_found)
set (_incs_found "")
foreach (token ${_all_tokens})
string (REGEX REPLACE "^-I" "" token ${token})
string (REGEX REPLACE "//" "/" token ${token})
convert_cygwin_path(token)
if (EXISTS ${token})
list (APPEND _incs_found ${token})
else (EXISTS ${token})
......
......@@ -40,77 +40,120 @@ if (ENABLE_PARALLEL_DOMAIN)
${MPI_CXX_LINK_FLAGS_} ${MPI_CXX_LIBRARIES})
# PETSc library is required
set(PETSC_EXECUTABLE_RUNS ON)
include(find_petsc)
find_package(petsc QUIET)
if (PETSc_FOUND)
target_include_directories(amdis_parallel INTERFACE
${PETSC_DIR}/include
${PETSC_DIR}/${PETSC_ARCH}/include)
# parmetis is required
find_file(PARMETIS_HEADER_FILE "parmetis.h" HINTS ${PETSC_DIR}/include ${PARMETIS_DIR}/include )
if (PARMETIS_HEADER_FILE)
get_filename_component(PARMETIS_INCLUDE_PATH "${PARMETIS_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${PARMETIS_INCLUDE_PATH})
set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDES})
set(PETSC_LIBRARY_DIRS ${PETSC_LIB_DIR})
message(STATUS " Found PETSc, version ${PETSC_VERSION}")
else (PETSc_FOUND)
include(FindPkgConfig)
find_file(PETSC_PKG_CONFIG "PETSc.pc"
HINTS ${PETSC_DIR}/lib/pkgconfig
${PETSC_ROOT}/lib/pkgconfig
/usr/lib/petsc/lib/pkgconfig
/usr/lib/petsc/linux-gnu-cxx-opt/lib/pkgconfig
/usr/lib/petsc/linux-gnu-c-opt/lib/pkgconfig)
if (PETSC_PKG_CONFIG-NOTFOUND)
message(FATAL_ERROR "PETSc PKG-Config file 'PETSc.pc' could not be found. Set variable PETSC_DIR to the directory where this file is located!")
endif (PETSC_PKG_CONFIG-NOTFOUND)
get_filename_component(PETSC_PKG_CONFIG_PATH "${PETSC_PKG_CONFIG}" PATH CACHE)
set(ENV{PKG_CONFIG_PATH} ${PETSC_PKG_CONFIG_PATH})
pkg_check_modules(PETSC REQUIRED PETSc>=3.3)
set(PETSC_DEFINITIONS ${PETSC_CFLAGS} ${PETSC_CFLAGS_OTHER})
endif (PETSc_FOUND)
target_include_directories(amdis_parallel INTERFACE
${PETSC_INCLUDE_DIRS})
# parmetis is required
find_file(PARMETIS_HEADER_FILE "parmetis.h"
HINTS ${PARMETIS_DIR}/include ${PETSC_INCLUDE_DIRS})
if (PARMETIS_HEADER_FILE)
get_filename_component(PARMETIS_INCLUDE_PATH "${PARMETIS_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${PARMETIS_INCLUDE_PATH})
else()
message(FATAL_ERROR "Could not find ParMetis header file 'parmetis.h'!")
endif (PARMETIS_HEADER_FILE)
# blas library is required
find_library(BLAS_LIB
NAMES blas fblas openblas
HINTS ${BLAS_DIR}/lib ${PETSC_LIBRARY_DIRS} /usr/lib/openblas-base /usr/lib/atlas-base)
if (BLAS_LIB)
set(BLAS_LIBRARIES ${BLAS_LIB})
else (BLAS_LIB)
find_package(BLAS REQUIRED)
endif (BLAS_LIB)
# lapack library is required
find_library(LAPACK_LIB
NAMES lapack flapack
HINTS ${LAPACK_DIR}/lib ${PETSC_LIBRARY_DIRS} ${PETSC_DIR}/lib)
if (LAPACK_LIB)
set(LAPACK_LIBRARIES ${LAPACK_LIB})
else (LAPACK_LIB)
find_package(LAPACK REQUIRED)
endif (LAPACK_LIB)
# add support for the zoltan library
if (ENABLE_ZOLTAN)
find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_INCLUDE_DIRS})
if (ZOLTAN_HEADER_FILE)
get_filename_component(ZOLTAN_HEADER_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${ZOLTAN_HEADER_DIR})
else()
message(FATAL_ERROR "Could not find ParMetis header file 'parmetis.h'!")
endif (PARMETIS_HEADER_FILE)
# add support for the zoltan library
if (ENABLE_ZOLTAN)
find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_DIR}/include)
if (ZOLTAN_HEADER_FILE)
get_filename_component(ZOLTAN_HEADER_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${ZOLTAN_HEADER_DIR})
else()
message(FATAL_ERROR "Could not find Zoltan include file 'zoltan_cpp.h'!")
endif(ZOLTAN_HEADER_FILE)
target_compile_definitions(amdis_parallel INTERFACE HAVE_ZOLTAN=1)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/ZoltanPartitioner.cc)
endif (ENABLE_ZOLTAN)
if (ENABLE_BDDCML)
target_compile_definitions(amdis_parallel INTERFACE HAVE_BDDCML=1)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/BddcMlSolver.cc)
endif (ENABLE_BDDCML)
# add some more source-files that need petsc
message(FATAL_ERROR "Could not find Zoltan include file 'zoltan_cpp.h'!")
endif(ZOLTAN_HEADER_FILE)
target_compile_definitions(amdis_parallel INTERFACE HAVE_ZOLTAN=1)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/MatrixNnzStructure.cc
${SOURCE_DIR}/parallel/ParallelCoarseSpaceSolver.cc
${SOURCE_DIR}/parallel/PetscHelper.cc
${SOURCE_DIR}/parallel/PetscSolver.cc
${SOURCE_DIR}/parallel/PetscSolverGlobalMatrix.cc
${SOURCE_DIR}/parallel/PetscSolverGlobalBlockMatrix.cc
${SOURCE_DIR}/solver/PetscTypes.cc
)
${SOURCE_DIR}/parallel/ZoltanPartitioner.cc)
endif (ENABLE_ZOLTAN)
if (ENABLE_BDDCML)
target_compile_definitions(amdis_parallel INTERFACE HAVE_BDDCML=1)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/BddcMlSolver.cc)
endif (ENABLE_BDDCML)
if (ENABLE_PARALLEL_SOLVERS)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/PetscSolverFeti.cc
${SOURCE_DIR}/parallel/PetscSolverFetiDebug.cc
${SOURCE_DIR}/parallel/PetscSolverFetiMonitor.cc
${SOURCE_DIR}/parallel/PetscSolverFetiOperators.cc
${SOURCE_DIR}/parallel/PetscSolverFetiTimings.cc
${SOURCE_DIR}/parallel/PetscSolverNavierStokes.cc
${SOURCE_DIR}/parallel/PetscSolverNSCH.cc
${SOURCE_DIR}/parallel/PetscSolverCahnHilliard2.cc
${SOURCE_DIR}/parallel/PetscSolverCahnHilliard.cc
${SOURCE_DIR}/parallel/PetscSolverSchur.cc
)
target_compile_definitions(amdis_parallel INTERFACE
HAVE_PARALLEL_SOLVERS=1)
endif (ENABLE_PARALLEL_SOLVERS)
# add some more source-files that need petsc
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/MatrixNnzStructure.cc
${SOURCE_DIR}/parallel/ParallelCoarseSpaceSolver.cc
${SOURCE_DIR}/parallel/PetscHelper.cc
${SOURCE_DIR}/parallel/PetscSolver.cc
${SOURCE_DIR}/parallel/PetscSolverGlobalMatrix.cc
${SOURCE_DIR}/parallel/PetscSolverGlobalBlockMatrix.cc
${SOURCE_DIR}/solver/PetscTypes.cc
)
if (ENABLE_PARALLEL_SOLVERS)
target_sources(amdis PRIVATE
${SOURCE_DIR}/parallel/PetscSolverFeti.cc
${SOURCE_DIR}/parallel/PetscSolverFetiDebug.cc
${SOURCE_DIR}/parallel/PetscSolverFetiMonitor.cc
${SOURCE_DIR}/parallel/PetscSolverFetiOperators.cc
${SOURCE_DIR}/parallel/PetscSolverFetiTimings.cc
${SOURCE_DIR}/parallel/PetscSolverNavierStokes.cc
${SOURCE_DIR}/parallel/PetscSolverNSCH.cc
${SOURCE_DIR}/parallel/PetscSolverCahnHilliard2.cc
${SOURCE_DIR}/parallel/PetscSolverCahnHilliard.cc
${SOURCE_DIR}/parallel/PetscSolverSchur.cc
)
target_compile_definitions(amdis_parallel INTERFACE
HAVE_PARALLEL_PETSC=1
PETSC_VERSION=${PETSC_VERSION})
HAVE_PARALLEL_SOLVERS=1)
endif (ENABLE_PARALLEL_SOLVERS)
target_link_libraries(amdis amdis_parallel ${PETSC_LIBRARIES} blas lapack)
endif (PETSc_FOUND)
target_compile_definitions(amdis_parallel INTERFACE
HAVE_PARALLEL_PETSC=1
PETSC_VERSION=${PETSC_VERSION})
target_compile_options(amdis_parallel INTERFACE
${PETSC_DEFINITIONS})
target_link_libraries(amdis amdis_parallel ${PETSC_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
# specify how to install this target:
# -----------------------------------
......@@ -121,6 +164,7 @@ if (ENABLE_PARALLEL_DOMAIN)
install(FILES
${BASE_DIR}/cmake3/ResolveCompilerPaths.cmake
${BASE_DIR}/cmake3/FindPackageMultipass.cmake
${BASE_DIR}/cmake3/find_petsc.cmake
${BASE_DIR}/cmake3/CorrectWindowsPaths.cmake
${BASE_DIR}/cmake3/FindPETSc.cmake
DESTINATION share/amdis/)
endif (ENABLE_PARALLEL_DOMAIN)
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