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

updated PETSc cmake configuration

parent e2507373
...@@ -157,11 +157,23 @@ endif (AMDIS_NEED_CXX11) ...@@ -157,11 +157,23 @@ endif (AMDIS_NEED_CXX11)
#load mpi-compiler for use with parmetis and parallel_domain #load mpi-compiler for use with parmetis and parallel_domain
if(AMDIS_HAS_PARALLEL_DOMAIN) if(AMDIS_HAS_PARALLEL_DOMAIN)
find_package(MPI REQUIRED) find_package(MPI REQUIRED)
if(MPI_FOUND)
list(APPEND AMDIS_LIBRARIES ${MPI_LIBRARIES}) list(APPEND AMDIS_LIBRARIES ${MPI_LIBRARIES})
list(APPEND AMDIS_COMPILEFLAGS ${MPI_COMPILE_FLAGS}) list(APPEND AMDIS_COMPILEFLAGS ${MPI_COMPILE_FLAGS})
list(APPEND AMDIS_INCLUDE_DIRS ${MPI_INCLUDE_PATH}) list(APPEND AMDIS_INCLUDE_DIRS ${MPI_INCLUDE_PATH})
endif(MPI_FOUND)
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") if(AMDIS_HAS_PARALLEL_DOMAIN STREQUAL "PETSC")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${AMDIS_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${AMDIS_DIR})
set(PETSC_EXECUTABLE_RUNS ON) set(PETSC_EXECUTABLE_RUNS ON)
...@@ -175,18 +187,6 @@ if(AMDIS_HAS_PARALLEL_DOMAIN) ...@@ -175,18 +187,6 @@ if(AMDIS_HAS_PARALLEL_DOMAIN)
elseif(AMDIS_HAS_PARALLEL_DOMAIN STREQUAL "PMTL") elseif(AMDIS_HAS_PARALLEL_DOMAIN STREQUAL "PMTL")
find_package(MTL REQUIRED) find_package(MTL REQUIRED)
list(APPEND AMDIS_LIBRARIES ${MTL_LIBRARIES}) 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() endif()
elseif(AMDIS_NEED_SEQ_PETSC) 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)
# source: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
# - Try to find PETSc # - Try to find PETSc
# Once done this will define # Once done this will define
# #
...@@ -10,8 +9,10 @@ ...@@ -10,8 +9,10 @@
# PETSC_MPIEXEC - Executable for running MPI programs # PETSC_MPIEXEC - Executable for running MPI programs
# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) # PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR)
# #
# Hack: PETSC_VERSION currently decides on the version based on the # Usage:
# layout. Otherwise we need to run C code to determine the version. # find_package(PETSc COMPONENTS CXX) - required if build --with-clanguage=C++ --with-c-support=0
# find_package(PETSc COMPONENTS C) - standard behavior of checking build using a C compiler
# find_package(PETSc) - same as above
# #
# Setting these changes the behavior of the search # Setting these changes the behavior of the search
# PETSC_DIR - directory in which PETSc resides # PETSC_DIR - directory in which PETSc resides
...@@ -21,6 +22,31 @@ ...@@ -21,6 +22,31 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
# #
set(PETSC_VALID_COMPONENTS
C
CXX)
if(NOT PETSc_FIND_COMPONENTS)
set(PETSC_LANGUAGE_BINDINGS "C")
else()
# Right now, this is designed for compatability with the --with-clanguage option, so
# only allow one item in the components list.
list(LENGTH ${PETSc_FIND_COMPONENTS} components_length)
if(${components_length} GREATER 1)
message(FATAL_ERROR "Only one component for PETSc is allowed to be specified")
endif()
# This is a stub for allowing multiple components should that time ever come. Perhaps
# to also test Fortran bindings?
foreach(component ${PETSc_FIND_COMPONENTS})
list(FIND PETSC_VALID_COMPONENTS ${component} component_location)
if(${component_location} EQUAL -1)
message(FATAL_ERROR "\"${component}\" is not a valid PETSc component.")
else()
list(APPEND PETSC_LANGUAGE_BINDINGS ${component})
endif()
endforeach()
endif()
function (petsc_get_version) function (petsc_get_version)
if (EXISTS "${PETSC_DIR}/include/petscversion.h") if (EXISTS "${PETSC_DIR}/include/petscversion.h")
file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ")
...@@ -42,14 +68,21 @@ function (petsc_get_version) ...@@ -42,14 +68,21 @@ function (petsc_get_version)
endif () endif ()
endfunction () endfunction ()
if (PETSC_DIR)
file(TO_CMAKE_PATH ${PETSC_DIR} PETSC_DIR)
endif (PETSC_DIR)
find_path (PETSC_DIR include/petsc.h find_path (PETSC_DIR include/petsc.h
HINTS ${AMDIS_PETSC_DIR} $ENV{HOME}/petsc /usr/lib/petsc ENV PETSC_DIR HINTS /usr/lib/petsc ENV PETSC_DIR
PATHS
# Debian paths
/usr/lib/petscdir/3.5.1 /usr/lib/petscdir/3.5
/usr/lib/petscdir/3.4.2 /usr/lib/petscdir/3.4
/usr/lib/petscdir/3.3 /usr/lib/petscdir/3.2 /usr/lib/petscdir/3.1
/usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2
# MacPorts path
/opt/local/lib/petsc
$ENV{HOME}/petsc
DOC "PETSc Directory") DOC "PETSc Directory")
find_program (MAKE_EXECUTABLE NAMES make gmake)
if (PETSC_DIR AND NOT PETSC_ARCH) if (PETSC_DIR AND NOT PETSC_ARCH)
set (_petsc_arches set (_petsc_arches
$ENV{PETSC_ARCH} # If set, use environment variable first $ENV{PETSC_ARCH} # If set, use environment variable first
...@@ -79,25 +112,22 @@ find_package_multipass (PETSc petsc_config_current ...@@ -79,25 +112,22 @@ find_package_multipass (PETSc petsc_config_current
# Determine whether the PETSc layout is old-style (through 2.3.3) or # Determine whether the PETSc layout is old-style (through 2.3.3) or
# new-style (>= 3.0.0) # new-style (>= 3.0.0)
if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3 if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables") # > 3.5
if (EXISTS "${PETSC_DIR}/conf/rules")
set (petsc_conf_rules "${PETSC_DIR}/conf/rules")
set (petsc_conf_variables "${PETSC_DIR}/conf/variables")
else ()
set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules") set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules")
set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables") set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
endif () elseif (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3
set (petsc_conf_rules "${PETSC_DIR}/conf/rules")
set (petsc_conf_variables "${PETSC_DIR}/conf/variables")
elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3 elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3
set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules") set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules")
set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables") set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables")
elseif (PETSC_DIR) elseif (PETSC_DIR)
message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation")
else ()
message (FATAL_ERROR "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH.")
endif () endif ()
petsc_get_version()
if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current) if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current)
petsc_get_version()
# Put variables into environment since they are needed to get # Put variables into environment since they are needed to get
# configuration (petscvariables) in the PETSc makefile # configuration (petscvariables) in the PETSc makefile
set (ENV{PETSC_DIR} "${PETSC_DIR}") set (ENV{PETSC_DIR} "${PETSC_DIR}")
...@@ -112,12 +142,12 @@ if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current) ...@@ -112,12 +142,12 @@ if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current)
include ${petsc_conf_rules} include ${petsc_conf_rules}
include ${petsc_conf_variables} include ${petsc_conf_variables}
show : show :
-@echo -n \${\${VARIABLE}} \t-@echo -n \${\${VARIABLE}}
") ")
macro (PETSC_GET_VARIABLE name var) macro (PETSC_GET_VARIABLE name var)
set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
execute_process (COMMAND ${CMAKE_MAKE_PROGRAM} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name}
OUTPUT_VARIABLE ${var} OUTPUT_VARIABLE ${var}
RESULT_VARIABLE petsc_return) RESULT_VARIABLE petsc_return)
endmacro (PETSC_GET_VARIABLE) endmacro (PETSC_GET_VARIABLE)
...@@ -126,6 +156,7 @@ show : ...@@ -126,6 +156,7 @@ show :
petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line) petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line)
petsc_get_variable (PETSC_INCLUDE petsc_include) petsc_get_variable (PETSC_INCLUDE petsc_include)
petsc_get_variable (PCC petsc_cc) petsc_get_variable (PCC petsc_cc)
petsc_get_variable (PCC_FLAGS petsc_cc_flags)
petsc_get_variable (MPIEXEC petsc_mpiexec) petsc_get_variable (MPIEXEC petsc_mpiexec)
# We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid! # We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid!
file (REMOVE ${petsc_config_makefile}) file (REMOVE ${petsc_config_makefile})
...@@ -134,11 +165,39 @@ show : ...@@ -134,11 +165,39 @@ show :
# Extract include paths and libraries from compile command line # Extract include paths and libraries from compile command line
resolve_includes (petsc_includes_all "${petsc_cpp_line}") resolve_includes (petsc_includes_all "${petsc_cpp_line}")
#on windows we need to make sure we're linking against the right
#runtime library
if (WIN32)
if (petsc_cc_flags MATCHES "-MT")
set(using_md False)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
set(using_md True)
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
if(${using_md} MATCHES "True")
message(WARNING "PETSc was built with /MT, but /MD is currently set.
See http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F")
endif(${using_md} MATCHES "True")
endif (petsc_cc_flags MATCHES "-MT")
endif (WIN32)
include (CorrectWindowsPaths)
convert_cygwin_path(petsc_lib_dir)
message (STATUS "petsc_lib_dir ${petsc_lib_dir}") message (STATUS "petsc_lib_dir ${petsc_lib_dir}")
macro (PETSC_FIND_LIBRARY suffix name) macro (PETSC_FIND_LIBRARY suffix name)
set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again
find_library (PETSC_LIBRARY_${suffix} NAMES ${name} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) if (WIN32)
set (libname lib${name}) #windows expects "libfoo", linux expects "foo"
else (WIN32)
set (libname ${name})
endif (WIN32)
find_library (PETSC_LIBRARY_${suffix} NAMES ${libname} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH)
set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}")
mark_as_advanced (PETSC_LIBRARY_${suffix}) mark_as_advanced (PETSC_LIBRARY_${suffix})
endmacro (PETSC_FIND_LIBRARY suffix name) endmacro (PETSC_FIND_LIBRARY suffix name)
...@@ -175,29 +234,42 @@ show : ...@@ -175,29 +234,42 @@ show :
message (STATUS "Recognized PETSc install with single library for all packages") message (STATUS "Recognized PETSc install with single library for all packages")
endif () endif ()
include (CheckCSourceRuns) include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns)
macro (PETSC_TEST_RUNS includes libraries runs) macro (PETSC_TEST_RUNS includes libraries runs)
multipass_c_source_runs ("${includes}" "${libraries}" " if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C")
set(_PETSC_ERR_FUNC "CHKERRQ(ierr)")
elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX")
set(_PETSC_ERR_FUNC "CHKERRXX(ierr)")
endif()
if (PETSC_VERSION VERSION_GREATER 3.1)
set (_PETSC_TSDestroy "TSDestroy(&ts)")
else ()
set (_PETSC_TSDestroy "TSDestroy(ts)")
endif ()
set(_PETSC_TEST_SOURCE "
static const char help[] = \"PETSc test program.\"; static const char help[] = \"PETSc test program.\";
#include \"petscts.h\" #include <petscts.h>
int main(int argc,char *argv[]) { int main(int argc,char *argv[]) {
PetscErrorCode ierr; PetscErrorCode ierr;
TS ts; TS ts;
ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr); ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC};
ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr); ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC};
ierr = TSSetFromOptions(ts);CHKERRQ(ierr); ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC};
ierr = TSDestroy(ts);CHKERRQ(ierr); ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC};
ierr = PetscFinalize();CHKERRQ(ierr); ierr = PetscFinalize();${_PETSC_ERR_FUNC};
return 0; return 0;
} }
" ${runs}) ")
multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}")
if (${${runs}}) if (${${runs}})
set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL
"Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE) "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
endif (${${runs}}) endif (${${runs}})
endmacro (PETSC_TEST_RUNS) endmacro (PETSC_TEST_RUNS)
find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH) find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH)
find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH) find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH)
mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF)
......
...@@ -21,7 +21,14 @@ ...@@ -21,7 +21,14 @@
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES # # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
# endif (NOT foo_current) # 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) # 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 # Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale. # because parent variables have made old cache entries stale.
...@@ -70,9 +77,9 @@ macro (FIND_PACKAGE_MULTIPASS _name _current) ...@@ -70,9 +77,9 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
endmacro (FIND_PACKAGE_MULTIPASS) endmacro (FIND_PACKAGE_MULTIPASS)
macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs) macro (MULTIPASS_SOURCE_RUNS includes libraries source runs language)
include (CheckCSourceRuns) include (Check${language}SourceRuns)
# This is a ridiculous hack. CHECK_C_SOURCE_* thinks that if the # This is a ridiculous hack. CHECK_${language}_SOURCE_* thinks that if the
# *name* of the return variable doesn't change, then the test does # *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 # 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 # 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) ...@@ -86,6 +93,14 @@ macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs}) set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${runs})
set (CMAKE_REQUIRED_INCLUDES ${includes}) set (CMAKE_REQUIRED_INCLUDES ${includes})
set (CMAKE_REQUIRED_LIBRARIES ${libraries}) set (CMAKE_REQUIRED_LIBRARIES ${libraries})
if(${language} STREQUAL "C")
check_c_source_runs ("${source}" ${testname}) check_c_source_runs ("${source}" ${testname})
elseif(${language} STREQUAL "CXX")
check_cxx_source_runs ("${source}" ${testname})
endif()
set (${runs} "${${testname}}") 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) endmacro (MULTIPASS_C_SOURCE_RUNS)
...@@ -38,23 +38,34 @@ ...@@ -38,23 +38,34 @@
# #
# assuming both directories exist. # assuming both directories exist.
# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry) # Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
include (CorrectWindowsPaths)
macro (RESOLVE_LIBRARIES LIBS LINK_LINE) macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|/[^\" ]+(a|so|dll))" _all_tokens "${LINK_LINE}") string (REGEX MATCHALL "((-L|-l|-Wl)([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))" _all_tokens "${LINK_LINE}")
set (_libs_found) set (_libs_found "")
set (_directory_list) set (_directory_list "")
foreach (token ${_all_tokens}) foreach (token ${_all_tokens})
if (token MATCHES "-L([^\" ]+|\"[^\"]+\")") if (token MATCHES "-L([^\" ]+|\"[^\"]+\")")
# If it's a library path, add it to the list # If it's a library path, add it to the list
string (REGEX REPLACE "^-L" "" token ${token}) string (REGEX REPLACE "^-L" "" token ${token})
string (REGEX REPLACE "//" "/" token ${token}) string (REGEX REPLACE "//" "/" token ${token})
convert_cygwin_path(token)
list (APPEND _directory_list ${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 # It's a library, resolve the path by looking in the list and then (by default) in system directories
if (WIN32) #windows expects "libfoo", linux expects "foo"
string (REGEX REPLACE "^-l" "lib" token ${token})
else (WIN32)
string (REGEX REPLACE "^-l" "" token ${token}) string (REGEX REPLACE "^-l" "" token ${token})
set (_root) endif (WIN32)
if (token MATCHES "^/") # We have an absolute path, add root to the search path set (_root "")
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 "^/") endif (token MATCHES "^/")
set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
find_library (_lib ${token} HINTS ${_directory_list} ${_root}) find_library (_lib ${token} HINTS ${_directory_list} ${_root})
...@@ -78,10 +89,11 @@ endmacro (RESOLVE_LIBRARIES) ...@@ -78,10 +89,11 @@ endmacro (RESOLVE_LIBRARIES)
macro (RESOLVE_INCLUDES INCS COMPILE_LINE) macro (RESOLVE_INCLUDES INCS COMPILE_LINE)
string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}") string (REGEX MATCHALL "-I([^\" ]+|\"[^\"]+\")" _all_tokens "${COMPILE_LINE}")
set (_incs_found) set (_incs_found "")
foreach (token ${_all_tokens}) foreach (token ${_all_tokens})
string (REGEX REPLACE "^-I" "" token ${token}) string (REGEX REPLACE "^-I" "" token ${token})
string (REGEX REPLACE "//" "/" token ${token}) string (REGEX REPLACE "//" "/" token ${token})
convert_cygwin_path(token)
if (EXISTS ${token}) if (EXISTS ${token})
list (APPEND _incs_found ${token}) list (APPEND _incs_found ${token})
else (EXISTS ${token}) else (EXISTS ${token})
......
...@@ -40,15 +40,37 @@ if (ENABLE_PARALLEL_DOMAIN) ...@@ -40,15 +40,37 @@ if (ENABLE_PARALLEL_DOMAIN)
${MPI_CXX_LINK_FLAGS_} ${MPI_CXX_LIBRARIES}) ${MPI_CXX_LINK_FLAGS_} ${MPI_CXX_LIBRARIES})
# PETSc library is required # PETSc library is required
set(PETSC_EXECUTABLE_RUNS ON) find_package(petsc QUIET)
include(find_petsc)
if (PETSc_FOUND) if (PETSc_FOUND)
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 target_include_directories(amdis_parallel INTERFACE
${PETSC_DIR}/include ${PETSC_INCLUDE_DIRS})
${PETSC_DIR}/${PETSC_ARCH}/include)
# parmetis is required # parmetis is required
find_file(PARMETIS_HEADER_FILE "parmetis.h" HINTS ${PETSC_DIR}/include ${PARMETIS_DIR}/include ) find_file(PARMETIS_HEADER_FILE "parmetis.h"
HINTS ${PARMETIS_DIR}/include ${PETSC_INCLUDE_DIRS})
if (PARMETIS_HEADER_FILE) if (PARMETIS_HEADER_FILE)
get_filename_component(PARMETIS_INCLUDE_PATH "${PARMETIS_HEADER_FILE}" PATH CACHE) get_filename_component(PARMETIS_INCLUDE_PATH "${PARMETIS_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${PARMETIS_INCLUDE_PATH}) target_include_directories(amdis_parallel INTERFACE ${PARMETIS_INCLUDE_PATH})
...@@ -56,9 +78,29 @@ if (ENABLE_PARALLEL_DOMAIN) ...@@ -56,9 +78,29 @@ if (ENABLE_PARALLEL_DOMAIN)
message(FATAL_ERROR "Could not find ParMetis header file 'parmetis.h'!") message(FATAL_ERROR "Could not find ParMetis header file 'parmetis.h'!")
endif (PARMETIS_HEADER_FILE) 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 # add support for the zoltan library
if (ENABLE_ZOLTAN) if (ENABLE_ZOLTAN)
find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_DIR}/include) find_file(ZOLTAN_HEADER_FILE "zoltan_cpp.h" HINTS ${ZOLTAN_DIR}/include ${PETSC_INCLUDE_DIRS})
if (ZOLTAN_HEADER_FILE) if (ZOLTAN_HEADER_FILE)
get_filename_component(ZOLTAN_HEADER_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE) get_filename_component(ZOLTAN_HEADER_DIR "${ZOLTAN_HEADER_FILE}" PATH CACHE)
target_include_directories(amdis_parallel INTERFACE ${ZOLTAN_HEADER_DIR}) target_include_directories(amdis_parallel INTERFACE ${ZOLTAN_HEADER_DIR})
...@@ -108,9 +150,10 @@ if (ENABLE_PARALLEL_DOMAIN) ...@@ -108,9 +150,10 @@ if (ENABLE_PARALLEL_DOMAIN)
target_compile_definitions(amdis_parallel INTERFACE target_compile_definitions(amdis_parallel INTERFACE
HAVE_PARALLEL_PETSC=1 HAVE_PARALLEL_PETSC=1
PETSC_VERSION=${PETSC_VERSION}) PETSC_VERSION=${PETSC_VERSION})
target_compile_options(amdis_parallel INTERFACE
${PETSC_DEFINITIONS})
target_link_libraries(amdis amdis_parallel ${PETSC_LIBRARIES} blas lapack) target_link_libraries(amdis amdis_parallel ${PETSC_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
endif (PETSc_FOUND)
# specify how to install this target: # specify how to install this target:
# ----------------------------------- # -----------------------------------
...@@ -121,6 +164,7 @@ if (ENABLE_PARALLEL_DOMAIN) ...@@ -121,6 +164,7 @@ if (ENABLE_PARALLEL_DOMAIN)
install(FILES install(FILES
${BASE_DIR}/cmake3/ResolveCompilerPaths.cmake ${BASE_DIR}/cmake3/ResolveCompilerPaths.cmake
${BASE_DIR}/cmake3/FindPackageMultipass.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/) DESTINATION share/amdis/)
endif (ENABLE_PARALLEL_DOMAIN) endif (ENABLE_PARALLEL_DOMAIN)
Markdown is supported