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
...@@ -59,11 +92,11 @@ if (PETSC_DIR AND NOT PETSC_ARCH) ...@@ -59,11 +92,11 @@ if (PETSC_DIR AND NOT PETSC_ARCH)
foreach (arch ${_petsc_arches}) foreach (arch ${_petsc_arches})
if (NOT PETSC_ARCH) if (NOT PETSC_ARCH)
find_path (petscconf petscconf.h find_path (petscconf petscconf.h
HINTS ${PETSC_DIR} HINTS ${PETSC_DIR}
PATH_SUFFIXES ${arch}/include bmake/${arch} PATH_SUFFIXES ${arch}/include bmake/${arch}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
if (petscconf) if (petscconf)
set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture") set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture")
endif (petscconf) endif (petscconf)
endif (NOT PETSC_ARCH) endif (NOT PETSC_ARCH)
endforeach (arch) endforeach (arch)
...@@ -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}/lib/petsc/conf/rules")
set (petsc_conf_rules "${PETSC_DIR}/conf/rules") set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
set (petsc_conf_variables "${PETSC_DIR}/conf/variables") elseif (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3
else () set (petsc_conf_rules "${PETSC_DIR}/conf/rules")
set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules") set (petsc_conf_variables "${PETSC_DIR}/conf/variables")
set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
endif ()
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)
...@@ -207,7 +279,7 @@ int main(int argc,char *argv[]) { ...@@ -207,7 +279,7 @@ int main(int argc,char *argv[]) {
if (petsc_works_minimal) if (petsc_works_minimal)
message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.") message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.")
set (petsc_includes_needed "${petsc_includes_minimal}") set (petsc_includes_needed "${petsc_includes_minimal}")
else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it
petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes) petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes)
if (petsc_works_allincludes) # It does, we just need all the includes ( if (petsc_works_allincludes) # It does, we just need all the includes (
message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).") message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).")
...@@ -215,21 +287,21 @@ int main(int argc,char *argv[]) { ...@@ -215,21 +287,21 @@ int main(int argc,char *argv[]) {
else (petsc_works_allincludes) # We are going to need to link the external libs explicitly else (petsc_works_allincludes) # We are going to need to link the external libs explicitly
resolve_libraries (petsc_libraries_external "${petsc_libs_external}") resolve_libraries (petsc_libraries_external "${petsc_libs_external}")
foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) foreach (pkg SYS VEC MAT DM KSP SNES TS ALL)
list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external}) list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external})
endforeach (pkg) endforeach (pkg)
petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries) petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries)
if (petsc_works_alllibraries) if (petsc_works_alllibraries)
message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.") message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.")
set (petsc_includes_needed ${petsc_includes_minimal}) set (petsc_includes_needed ${petsc_includes_minimal})
else (petsc_works_alllibraries) else (petsc_works_alllibraries)
# It looks like we really need everything, should have listened to Matt # It looks like we really need everything, should have listened to Matt
set (petsc_includes_needed ${petsc_includes_all}) set (petsc_includes_needed ${petsc_includes_all})
petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all) petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all)
if (petsc_works_all) # We fail anyways if (petsc_works_all) # We fail anyways
message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.")
else (petsc_works_all) # We fail anyways else (petsc_works_all) # We fail anyways
message (STATUS "PETSc could not be used, maybe the install is broken.") message (STATUS "PETSc could not be used, maybe the install is broken.")
endif (petsc_works_all) endif (petsc_works_all)
endif (petsc_works_alllibraries) endif (petsc_works_alllibraries)
endif (petsc_works_allincludes) endif (petsc_works_allincludes)
endif (petsc_works_minimal) endif (petsc_works_minimal)
......
...@@ -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.
...@@ -39,7 +46,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current) ...@@ -39,7 +46,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
# The name of the stored value for the given state # The name of the stored value for the given state
set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state}) set (_stored_var PACKAGE_MULTIPASS_${_NAME}_${_state})
if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") if (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
set (_states_current "NO") set (_states_current "NO")
endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}") endif (NOT "${${_stored_var}}" STREQUAL "${${_NAME}_${_state}}")
set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE) set (${_stored_var} "${${_NAME}_${_state}}" CACHE INTERNAL "Stored state for ${_name}." FORCE)
list (REMOVE_AT _args 0) list (REMOVE_AT _args 0)
...@@ -61,7 +68,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current) ...@@ -61,7 +68,7 @@ macro (FIND_PACKAGE_MULTIPASS _name _current)
if (_cmd STREQUAL "DEPENDENTS") if (_cmd STREQUAL "DEPENDENTS")
list (REMOVE_AT _args 0) list (REMOVE_AT _args 0)
foreach (dep ${_args}) foreach (dep ${_args})
set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) set (${_NAME}_${dep} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
endforeach (dep) endforeach (dep)
endif (_cmd STREQUAL "DEPENDENTS") endif (_cmd STREQUAL "DEPENDENTS")
set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) set (${_NAME}_FOUND "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
...@@ -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})
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}}") 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
string (REGEX REPLACE "^-l" "" token ${token}) if (WIN32) #windows expects "libfoo", linux expects "foo"
set (_root) string (REGEX REPLACE "^-l" "lib" token ${token})
if (token MATCHES "^/") # We have an absolute path, add root to the search path else (WIN32)
set (_root "/") 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 "^/") 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,77 +40,120 @@ if (ENABLE_PARALLEL_DOMAIN) ...@@ -40,77 +40,120 @@ 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)
target_include_directories(amdis_parallel INTERFACE set(PETSC_INCLUDE_DIRS ${PETSC_INCLUDES})
${PETSC_DIR}/include set(PETSC_LIBRARY_DIRS ${PETSC_LIB_DIR})
${PETSC_DIR}/${PETSC_ARCH}/include) message(STATUS " Found PETSc, version ${PETSC_VERSION}")