Commit 7aef2864 authored by Praetorius, Simon's avatar Praetorius, Simon

Merge branch 'issue/cmake_2-8-10' into 'master'

Issue/cmake 2 8 10

Rewritten the cmake configuration for cmake version 2.8.10 in the same style as cmake 3.0 variant

See merge request !11
parents 1efa4a14 7d4dfda1
## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
##
## # The following are required to submit to the CDash dashboard:
## ENABLE_TESTING()
## INCLUDE(CTest)
set(CTEST_PROJECT_NAME "AMDiS")
set(CTEST_NIGHTLY_START_TIME "00:00:00 EST")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "my.cdash.org")
set(CTEST_DROP_LOCATION "/submit.php?project=AMDiS")
set(CTEST_DROP_SITE_CDASH TRUE)
# set(CTEST_USE_LAUNCHERS 1)
\ No newline at end of file
<html>
<head>
<title> Using AMDiS with cmake </title>
<style type="text/css" >
.desc { background-color:#E0E0E0; margin-left:100px }
</style >
</head>
<body>
<h1> Using AMDiS with cmake </h1>
With this short page, I will show you, how to use the cmake buildsystem with AMDiS. The introduction consists of two main parts:
<ol>
<li> <a href="#compiling" > compiling and installing AMDiS with CMake </a ></li>
<li> <a href="#using" > using the cmake installed AMDiS in your project </a ></li>
<li> <a href="#faq" > some frequently asked questions </a ></li>
</ol>
<h2> <a name="compiling" > Compiling and installing AMDiS with CMake </a > </h2>
<h3> configure </h3>
There are 3 different configure tools for CMake:
<ul> <li> cmake (non interactive) </li>
<li> ccmake (interactive on command line) </li>
<li> cmake-gui (qt-based gui) </li></ul>
<p>I will use the cmake and ccmake. The autoconf/automake implementation was used directly inside the AMDiS source directory (i.e. the directory you get through svn). To use the CMake buildsystem, I recommend a different directory structure for building and compiling AMDiS. The script <a href="https://fusionforge.zih.tu-dresden.de/frs/download.php/34/getamdis_cmake.sh" >getamdis_cmake.sh</a>, which can be found on <a href="https://fusionforge.zih.tu-dresden.de" >https://fusionforge.zih.tu-dresden.de</a>, creates such a directory structure.</p>
Assume, you have AMDiS downloaded in the directory
<pre class="desc" >
${HOME}/work/ </pre>
, the AMDiS source directory is
<pre class="desc">
${HOME}/work/amdis/AMDiS </pre>
. To configure and compile AMDiS I recommend using out of source builds. This means, you should create a directory amdis_build
<pre class="desc">
mkdir ${HOME}/work/amdis_build </pre>
and do the remaining work from there.
<pre class="desc">
cd ${HOME}/work/amdis_build </pre>
The simplest configuration of AMDiS, i.e. without umfpack and parallelization, only sets the install destination to the directory "${HOME}/programs/". To do this, you have to call cmake with your install destination and the AMDiS source directory as commandline arguments
<pre class="desc" >
cmake -DCMAKE_INSTALL_PREFIX=${HOME}/programs/ ../amdis/AMDiS</pre>
Compilation and installation is the same as with automake/autoconf:
<pre class="desc">
make && make install </pre >
The last command will install AMDiS to ${HOME}/programs
<h2> <a name="using" > Using the cmake installed AMDiS in your project </a > </h2>
A cmake-project consists of the source files and a file CMakeLists.txt, which contains a description of needed libraries, headers and programs. If you have a simple project with one program "fooProg", which have to compile only one source file "src/foo.cc", your CMakeLists.txt consist of the following lines:
<pre class="desc" >
project(projectName) <br>
cmake_minimum_required(VERSION 2.8)<br><br>
find_package(AMDIS REQUIRED)<br>
if(AMDIS_FOUND)<br>
include(${AMDIS_USE_FILE})<br>
add_executable(fooProg src/foo.cc)<br>
target_link_libraries(fooProg ${AMDIS_LIBRARIES})<br>
endif(AMDIS_FOUND)<br>
</pre >
The first two lines
<pre class="desc" >
project(projectName) <br>
cmake_minimum_required(VERSION 2.8)
</pre >
tell cmake the name of your project and that you whish to use only cmake versions newer than 2.8.<br>
The line
<pre class="desc" >
find_package(AMDIS REQUIRED)
</pre >
tells cmake, that you want to use AMDiS and it should complain if AMDiS was not found. CMake will print an error message, bu will not stop the execution! With the command
<pre class="desc" >
include(${AMDIS_USE_FILE})
</pre >
we read an AMDiS specific configuration file, which sets some compilerflags and adds the include directorys. The program is added with
<pre class="desc" >
add_executable(fooProg src/foo.cc)
</pre >
and we have to tell cmake, that we need the library amdis and each library amdis depends on. This is done with the command
<pre class="desc" >
target_link_libraries(fooProg ${AMDIS_LIBRARIES})
</pre >
If cmake does not find AMDiS, you have to set the variable AMDIS_DIR to the directory containing the file AMDiSConfig.cmake. This file resides in
<pre class="desc" >
${CMAKE_INSTALL_PREFIX}/share/amdis/
</pre >
where CMAKE_INSTALL_PREFIX is the directory you choose during installation of amdis.
<h2 > <a name="faq" > Frequently asked questions </a ></h2 >
<h3 > Boost </h3>
If you have different boost versions on your system and you do not want to use the standard version in /usr/lib and /usr/include, you should set the environment variable BOOST_ROOT to your boost-installation.
<h3 > I will not set the AMDIS_DIR in every project. </h3 >
If you always use the same AMDiS directory, you can add the directory to your PATH variable.
</body>
</html>
This diff is collapsed.
# globally add compile options and include directories
# globally add compile options and include directories
add_definitions(${AMDIS_COMPILEFLAGS})
include_directories(${AMDIS_INCLUDE_DIRS})
This diff is collapsed.
SET (CTEST_SOURCE_DIRECTORY @CMAKE_CURRENT_SOURCE_DIR@)
SET (CTEST_BINARY_DIRECTORY @CMAKE_CURRENT_BINARY_DIR@)
SET (CTEST_COMMAND "${CMAKE_CTEST_COMMAND}")
SET (CTEST_BUILD_COMMAND ${CTEST_BINARY_DIRECTORY}/myMake.sh)
set(CTEST_UPDATE_COMMAND ${CTEST_SOURCE_DIRECTORY}/MySvn.sh)
#set(CTEST_UPDATE_OPTIONS "--username studentiwr --password iwr_ws09")
set(CTEST_SITE @SITE@)
set(CTEST_BUILD_NAME @BUILDNAME@)
ctest_start(@CTEST_MODEL@)
ctest_build()
ctest_submit()
set(COMPILER_TEST_DIR ${CMAKE_BINARY_DIR}/CMakeFiles/compilerTest)
file(WRITE ${COMPILER_TEST_DIR}/CMakeLists.txt
"project(compilerTest)
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
# VARIADIC CLASS_TEMPLATES
add_executable(test_variadic_templ_class test_variadic_templ_class.cpp)
target_link_libraries(test_variadic_templ_class)
# VARIADIC FUNCTION TEMPLATES
add_executable(test_variadic_templ_fct test_variadic_templ_fct.cpp)
target_link_libraries(test_variadic_templ_fct)
# ALIAS TEMPLATES
add_executable(test_alias_templates test_alias_templates.cpp)
target_link_libraries(test_alias_templates)
# DECLTYPE
add_executable(test_decltype test_decltype.cpp)
target_link_libraries(test_decltype)
# AUTO SPECIFIER
add_executable(test_auto test_auto.cpp)
target_link_libraries(test_auto)
# CONSTEXPR
add_executable(test_constexpr test_constexpr.cpp)
target_link_libraries(test_constexpr)
# DELEGATING CONSTRUCTORS
add_executable(test_delegating_constructors test_delegating_constructors.cpp)
target_link_libraries(test_delegating_constructors)
# RANGE-BASED FOR LOOPS
add_executable(test_range_based_for test_range_based_for.cpp)
target_link_libraries(test_range_based_for)")
file(WRITE ${COMPILER_TEST_DIR}/test_variadic_templ_class.cpp
"template<class... Ts> struct A{}; int main(){A<int, double> a;}")
file(WRITE ${COMPILER_TEST_DIR}/test_variadic_templ_fct.cpp
"template<class... Ts> void foo(Ts... ts){}; int main(){foo(1, 2.0, 3.0f);}")
file(WRITE ${COMPILER_TEST_DIR}/test_alias_templates.cpp
"template<class T> struct A{}; template<class T> using B=A<T>; int main(){B<int> b;}")
file(WRITE ${COMPILER_TEST_DIR}/test_decltype.cpp
"int main(){decltype(1) a = 1;}")
file(WRITE ${COMPILER_TEST_DIR}/test_auto.cpp
"int main(){auto a = 1;}")
file(WRITE ${COMPILER_TEST_DIR}/test_constexpr.cpp
"constexpr int foo(){return 1;}; int main(){static constexpr int f = foo();}")
file(WRITE ${COMPILER_TEST_DIR}/test_delegating_constructors.cpp
"struct A{ A(){} A(int) : A(){} }; int main(){ A a(1);}")
file(WRITE ${COMPILER_TEST_DIR}/test_range_based_for.cpp
"int main(){ int vec[10]; for (int& elem : vec) { elem = 1; } }")
set(COMPILER_CXX11_FEATURES "")
try_compile(TEST_VARIADIC_TEMPL_CLASS ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_variadic_templ_class)
try_compile(TEST_VARIADIC_TEMPL_FCT ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_variadic_templ_fct)
if (TEST_VARIADIC_TEMPL_CLASS AND TEST_VARIADIC_TEMPL_FCT)
message("Compiler supports variadic class/ function templates")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_VARIADIC_TEMPLATES=1")
endif()
try_compile(TEST_ALIAS_TEMPLATES ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_alias_templates)
if (TEST_ALIAS_TEMPLATES)
message("Compiler supports alias-templates")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_ALIAS_TEMPLATES=1")
endif()
try_compile(TEST_DECLTYPE ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_decltype)
if (TEST_DECLTYPE)
message("Compiler supports decltype")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_DECLTYPE=1")
endif()
try_compile(TEST_AUTO_SPECIFIER ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_auto)
if (TEST_AUTO_SPECIFIER)
message("Compiler supports auto")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_AUTO=1")
endif()
try_compile(TEST_CONSTEXPR ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_constexpr)
if (TEST_CONSTEXPR)
message("Compiler supports constexpr")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_CONSTEXPR=1")
endif()
try_compile(TEST_DELEGATING_CONSTRUCTORS ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_delegating_constructors)
if (TEST_DELEGATING_CONSTRUCTORS)
message("Compiler supports delegating constructors")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_DELEGATING_CONSTRUCTORS=1")
endif()
try_compile(TEST_RANGED_BASED_FOR ${COMPILER_TEST_DIR} ${COMPILER_TEST_DIR} compilerTest test_range_based_for)
if (TEST_RANGED_BASED_FOR)
message("Compiler supports range-based for loops")
list(APPEND COMPILER_CXX11_FEATURES "-DHAS_RANGE_BASED_FOR=1")
endif()
\ No newline at end of file
# 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)
# - Try to find PETSc
# Once done this will define
# source: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
#
# PETSC_FOUND - system has PETSc
# PETSC_INCLUDES - the PETSc include directories
......@@ -10,8 +9,10 @@
# PETSC_MPIEXEC - Executable for running MPI programs
# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR)
#
# Hack: PETSC_VERSION currently decides on the version based on the
# layout. Otherwise we need to run C code to determine the version.
# Usage:
# 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
# PETSC_DIR - directory in which PETSc resides
......@@ -21,6 +22,31 @@
# 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)
if (EXISTS "${PETSC_DIR}/include/petscversion.h")
file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ")
......@@ -43,12 +69,20 @@ function (petsc_get_version)
endfunction ()
find_path (PETSC_DIR include/petsc.h
HINTS ENV PETSC_DIR
HINTS /usr/lib/petsc ENV PETSC_DIR
PATHS
/usr/lib/petscdir/3.1 /usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2 # Debian
# 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")
find_program (MAKE_EXECUTABLE NAMES make gmake)
if (PETSC_DIR AND NOT PETSC_ARCH)
set (_petsc_arches
$ENV{PETSC_ARCH} # If set, use environment variable first
......@@ -58,11 +92,11 @@ if (PETSC_DIR AND NOT PETSC_ARCH)
foreach (arch ${_petsc_arches})
if (NOT PETSC_ARCH)
find_path (petscconf petscconf.h
HINTS ${PETSC_DIR}
PATH_SUFFIXES ${arch}/include bmake/${arch}
NO_DEFAULT_PATH)
HINTS ${PETSC_DIR}
PATH_SUFFIXES ${arch}/include bmake/${arch}
NO_DEFAULT_PATH)
if (petscconf)
set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture")
set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture")
endif (petscconf)
endif (NOT PETSC_ARCH)
endforeach (arch)
......@@ -78,7 +112,10 @@ find_package_multipass (PETSc petsc_config_current
# Determine whether the PETSc layout is old-style (through 2.3.3) or
# 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
set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules")
set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables")
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
......@@ -87,9 +124,10 @@ elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3
elseif (PETSC_DIR)
message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation")
endif ()
petsc_get_version()
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
# configuration (petscvariables) in the PETSc makefile
set (ENV{PETSC_DIR} "${PETSC_DIR}")
......@@ -104,12 +142,12 @@ if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current)
include ${petsc_conf_rules}
include ${petsc_conf_variables}
show :
-@echo -n \${\${VARIABLE}}
\t-@echo -n \${\${VARIABLE}}
")
macro (PETSC_GET_VARIABLE name var)
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}
RESULT_VARIABLE petsc_return)
endmacro (PETSC_GET_VARIABLE)
......@@ -118,6 +156,7 @@ show :
petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line)
petsc_get_variable (PETSC_INCLUDE petsc_include)
petsc_get_variable (PCC petsc_cc)
petsc_get_variable (PCC_FLAGS petsc_cc_flags)
petsc_get_variable (MPIEXEC petsc_mpiexec)
# We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid!
file (REMOVE ${petsc_config_makefile})
......@@ -126,11 +165,39 @@ show :
# Extract include paths and libraries from compile command 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}")
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
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}}")
mark_as_advanced (PETSC_LIBRARY_${suffix})
endmacro (PETSC_FIND_LIBRARY suffix name)
......@@ -167,29 +234,42 @@ show :
message (STATUS "Recognized PETSc install with single library for all packages")
endif ()
include (CheckCSourceRuns)
include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns)
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.\";
#include \"petscts.h\"
#include <petscts.h>
int main(int argc,char *argv[]) {
PetscErrorCode ierr;
TS ts;
ierr = PetscInitialize(&argc,&argv,0,help);CHKERRQ(ierr);
ierr = TSCreate(PETSC_COMM_WORLD,&ts);CHKERRQ(ierr);
ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
ierr = TSDestroy(ts);CHKERRQ(ierr);
ierr = PetscFinalize();CHKERRQ(ierr);
ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC};
ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC};
ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC};
ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC};
ierr = PetscFinalize();${_PETSC_ERR_FUNC};
return 0;
}
" ${runs})
")
multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}")
if (${${runs}})
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}})
endmacro (PETSC_TEST_RUNS)
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)
mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF)
......@@ -199,7 +279,7 @@ int main(int argc,char *argv[]) {
if (petsc_works_minimal)
message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.")
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)
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).")
......@@ -207,21 +287,21 @@ int main(int argc,char *argv[]) {
else (petsc_works_allincludes) # We are going to need to link the external libs explicitly
resolve_libraries (petsc_libraries_external "${petsc_libs_external}")
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)
petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" 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.")
set (petsc_includes_needed ${petsc_includes_minimal})
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})
else (petsc_works_alllibraries)
# It looks like we really need everything, should have listened to Matt
set (petsc_includes_needed ${petsc_includes_all})
petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all)
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.")
else (petsc_works_all) # We fail anyways
message (STATUS "PETSc could not be used, maybe the install is broken.")
endif (petsc_works_all)
# It looks like we really need everything, should have listened to Matt
set (petsc_includes_needed ${petsc_includes_all})
petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all)
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.")
else (petsc_works_all) # We fail anyways
message (STATUS "PETSc could not be used, maybe the install is broken.")
endif (petsc_works_all)
endif (petsc_works_alllibraries)
endif (petsc_works_allincludes)
endif (petsc_works_minimal)
......
......@@ -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)
find_file(HYPRE_H HYPRE.h)
find_library(HYPRE_LIB HYPRE)
if(HYPRE_H AND HYPRE_LIB)
set(HAVE_HYPRE ON)
find_package(MPI REQUIRED)
#append each library in the hypre_lib directory beginning with HYPRE to the list of hypre libraries
get_filename_component(HLIB_PATH ${HYPRE_LIB} PATH)
file(GLOB HYPRE_OTHER ${HLIB_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}HYPRE*${CMAKE_SHARED_LIBRARY_SUFFIX})
find_library(LAPACK_LIB lapack)
set(HYPRE_LIBRARIES ${MPI_LIBRARIES} ${HYPRE_LIB} ${HYPRE_OTHER} ${LAPACK_LIB})
message("hypre libraries: ${HYPRE_LIBRARIES}")
get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${HYPRE_H} PATH)
list(APPEND HYPRE_INCLUDE_DIRECTORIES ${MPI_CXX_INCLUDE_PATH})
else()
if(HAVE_HYPRE)
message("could not find hypre:")
message("library: ${HYPRE_LIB}")
message("header: ${HYPRE_H}")
endif()
set(HAVE_HYPRE FALSE)
endif()
# - Try to find PETSc
# Once done this will define
# source: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
#
# PETSC_FOUND - system has PETSc
# PETSC_INCLUDES - the PETSc include directories
# PETSC_LIBRARIES - Link these to use PETSc
# PETSC_COMPILER - Compiler used by PETSc, helpful to find a compatible MPI
# PETSC_DEFINITIONS - Compiler switches for using PETSc
# PETSC_MPIEXEC - Executable for running MPI programs
# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR)
#
# Hack: PETSC_VERSION currently decides on the version based on the
# layout. Otherwise we need to run C code to determine the version.
#
# Setting these changes the behavior of the search
# PETSC_DIR - directory in which PETSc resides
# PETSC_ARCH - build architecture
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
function (petsc_get_version)
if (EXISTS "${PETSC_DIR}/include/petscversion.h")
file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ")
foreach (line ${vstrings})
string (REGEX REPLACE " +" ";" fields ${line}) # break line into three fields (the first is always "#define")
list (GET fields 1 var)
list (GET fields 2 val)
set (${var} ${val} PARENT_SCOPE)
set (${var} ${val}) # Also in local scope so we have access below