Commit 866968b0 authored by Praetorius, Simon's avatar Praetorius, Simon

Merge branch 'issue/cmake_configuration' into 'master'

Issue/cmake configuration

rewritten several cmake files to be more compatible with several linux distributions

See merge request !8
parents d272ab51 379e8d5c
......@@ -2,12 +2,9 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(AMDiS)
if (USE_NEW_CMAKE AND ${CMAKE_VERSION} VERSION_GREATER "3.2")
# Experimental implementation of new CMakeLists.txt
# Can be selected by calling cmake -DUSE_NEW_CMAKE=ON .
# Use only if you know what you are doing :-)
include(${AMDiS_SOURCE_DIR}/cmake3/CMakeLists.txt)
if (${CMAKE_VERSION} VERSION_GREATER "3.2")
include(${AMDiS_SOURCE_DIR}/cmake3/CMakeLists.txt)
else ()
# By defualt the classical CMakeLists file ist used
include(${AMDiS_SOURCE_DIR}/cmake/CMakeLists.txt)
# Fallback to classical CMakeLists file
include(${AMDiS_SOURCE_DIR}/cmake/CMakeLists.txt)
endif ()
......@@ -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)
......
#thats bad because it affects each target
# globally add compile options and include directories
add_definitions(${AMDIS_COMPILEFLAGS})
include_directories(${AMDIS_INCLUDE_DIRS})
......@@ -25,12 +25,12 @@ SET(MTL_INCLUDE_DIR ${LIB_DIR}/mtl4/ CACHE PATH "mtl4 directory")
# #message("svn-rev: ${svn_info_WC_REVISION}")
# set(AMDIS_SUB_MINOR "${svn_info_WC_REVISION}")
# endif()
set(CurrentRevision "0.9")
set(CurrentRevision "1.1")
if(NOT AMDIS_MAJOR)
set(AMDIS_MAJOR "0")
set(AMDIS_MAJOR "1")
endif()
if(NOT AMDIS_MINOR)
set(AMDIS_MINOR "9")
set(AMDIS_MINOR "1")
endif()
list(APPEND COMPILEFLAGS "-DAMDIS_VERSION=${CurrentRevision}")
......
# enable the c++11 features. From cmake version 3.0 this is simply done by setting
# the cxx_standard variables. For older cmake version the compile-flags must be added manually.
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX)
if (ENABLE_CXX11)
list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
if (${CMAKE_VERSION} VERSION_GREATER "3.0")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") # cmake can not detect intel compile features
set(REQUIRED_CXX_FEATURES "cxx_alias_templates" "cxx_auto_type" "cxx_lambdas" "cxx_override" "cxx_range_for" "cxx_static_assert" "cxx_variadic_templates")
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG)
set(CXX11_CODE "
#include <array>
#include <tuple>
template <class... T> using A = std::tuple<T...>;
int main(){
decltype(1) vec[]={1,2,3};
for(auto&& x:vec);
}")
if (COMPILER_SUPPORTS_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES_WITH_CXX11_FLAG)
set(CMAKE_REQUIRED_FLAGS "")
endif ()
if (COMPILER_SUPPORTS_CXX11_FLAG AND CXX11_COMPILES_WITH_CXX11_FLAG)
add_definitions("-std=c++11")
else ()
check_cxx_source_compiles("${CXX11_CODE}" CXX11_COMPILES)
if (NOT CXX11_COMPILES)
message (FATAL_ERROR "Compiler does not support C++11.")
endif ()
endif ()
add_library(test_compiler_features cmake/dummy.cc)
foreach(feature ${REQUIRED_CXX_FEATURES})
target_compile_features(test_compiler_features PUBLIC ${feature})
endforeach(feature)
endif ()
else()
if (CMAKE_COMPILER_IS_GNUCXX)
set(GXX_MIN_VER "4.8")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GXX_MIN_VER)
message (FATAL_ERROR "For C++11-Features the G++ Compiler must be at least version $GXX_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=gnu++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_MIN_VER "3.0")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_MIN_VER)
message (FATAL_ERROR "For C++11-Features the Clang Compiler must be at least version $CLANG_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(INTEL_MIN_VER "12.1")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS INTEL_MIN_VER)
message (FATAL_ERROR "For C++11-Features the Intel C++ Compiler must be at least version $INTEL_MIN_VER")
endif ()
list(APPEND COMPILEFLAGS "-std=c++11")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(MSVC_MIN_VER "12.0")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MSVC_MIN_VER)
message (FATAL_ERROR "For C++11-Features the MSVC C++ Compiler must be at least version $MSVC_MIN_VER")
endif ()
endif ()
endif()
list(APPEND COMPILEFLAGS "-DHAS_CXX11=1")
else ()
list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
list(APPEND COMPILEFLAGS "-DHAS_CXX11=0")
endif (ENABLE_CXX11)
......@@ -14,8 +14,8 @@
# target_link_libraries(yourTarget AMDiS)
#
if (${CMAKE_VERSION} VERSION_LESS "3.0")
message(FATAL_ERROR "The Configuration file was created for CMake version >= 3.0")
if (${CMAKE_VERSION} VERSION_LESS "3.2")
message(FATAL_ERROR "The Configuration file was created for CMake version >= 3.2")
endif ()
list(APPEND CMAKE_MODULE_PATH ${AMDIS_DIR})
......@@ -36,14 +36,16 @@ set(AMDIS_NEED_COMPOSITE_FEM @ENABLE_COMPOSITE_FEM@)
set(BUILD_SHARED_LIBS @BUILD_SHARED_LIBS@)
set(CMAKE_BUILD_TYPE @CMAKE_BUILD_TYPE@)
include(FindPkgConfig)
add_library(amdis_base INTERFACE)
add_library(AMDiS ALIAS amdis_base)
target_compile_definitions(amdis_base INTERFACE)
if (AMDIS_NEED_CXX11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(test_compile_features)
target_enable_cxx11(AMDIS_NEED_CXX11 amdis_base INTERFACE)
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=1)
else ()
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=0)
......@@ -82,7 +84,8 @@ endif (NOT BOOST_ROOT)
if (NOT BOOST_LIBRARYDIR)
set(BOOST_LIBRARYDIR @BOOST_LIBRARYDIR@)
endif (NOT BOOST_LIBRARYDIR)
include(find_boost)
include(target_enable_boost)
target_enable_boost(amdis_base INTERFACE ON)
# umfpack library
# --------------------
......@@ -90,7 +93,8 @@ if (AMDIS_NEED_UMFPACK)
set(AMDIS_SuiteSparse_DIR @SuiteSparse_DIR@)
set(AMDIS_UMFPACK_INCLUDE_DIR @UMFPACK_INCLUDE_DIRS@)
set(AMDIS_UMFPACK_LIB_DIR ${AMDIS_UMFPACK_INCLUDE_DIR}/../include)
include(find_umfpack)
include(target_enable_umfpack)
target_enable_umfpack(amdis_base INTERFACE ON)
endif (AMDIS_NEED_UMFPACK)
......@@ -100,27 +104,9 @@ if (AMDIS_HAS_PARALLEL_DOMAIN)
target_compile_definitions(amdis_base INTERFACE
HAVE_PARALLEL_DOMAIN_AMDIS=1)
find_package(MPI REQUIRED)
if (MPI_FOUND)
target_include_directories(amdis_base INTERFACE ${MPI_INCLUDE_PATH})
target_compile_options(amdis_base INTERFACE ${MPI_COMPILE_FLAGS})
target_link_libraries(amdis_base INTERFACE ${MPI_LIBRARIES})
endif (MPI_FOUND)
set(PETSC_EXECUTABLE_RUNS ON)
set(AMDIS_PETSC_DIR @PETSC_DIR@)
include(find_petsc)
if (PETSc_FOUND)
target_include_directories(amdis_base INTERFACE ${PETSC_INCLUDES})
target_link_libraries(amdis_base INTERFACE
${PETSC_LIBRARY_SYS}
${PETSC_LIBRARIES}
blas lapack)
target_compile_definitions(amdis_base INTERFACE
HAVE_PARALLEL_PETSC=1)
else()
message(FATAL_ERROR "Could not find PETSc!")
endif (PETSc_FOUND)
include(target_enable_petsc)
target_enable_mpi(amdis_base INTERFACE ON)
target_enable_petsc(amdis_base INTERFACE ON)
endif (AMDIS_HAS_PARALLEL_DOMAIN)
......@@ -188,12 +174,19 @@ unset(_MUPARSER_LIB CACHE)
# Zoltan library
# --------------
if (AMDIS_NEED_ZOLTAN)
find_library(ZOLTAN_LIB zoltan HINTS ENV LIBRARY_PATH DOC "Full path to the zoltan library")
if (ZOLTAN_LIB)
target_link_libraries(amdis_base INTERFACE ${ZOLTAN_LIB})
else()
message(FATAL_ERROR "Could not find zoltan library!")
endif()
include(target_enable_zoltan)
target_enable_zoltan(amdis_base INTERFACE ON)
endif ()
set(AMDIS_LIBRARIES AMDiS)
# Extract some variables from INTERFACE target AMDiS
get_target_property(AMDIS_INCLUDE_DIRS AMDiS INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(AMDIS_LIBRARIES AMDiS INTERFACE_LINK_LIBRARIES)
get_target_property(AMDIS_COMPILEFLAGS AMDiS INTERFACE_COMPILE_OPTIONS)
if (NOT AMDIS_COMPILEFLAGS)
set(AMDIS_COMPILEFLAGS "")
endif()
get_target_property(_DEFINITIONS AMDiS INTERFACE_COMPILE_DEFINITIONS)
foreach(defn ${_DEFINITIONS})
list(APPEND AMDIS_COMPILEFLAGS "-D${defn}")
endforeach(defn)
message(STATUS "To compile your program with AMDiS simply add the target 'AMDiS' to the target_link_libraries(...) command")
\ No newline at end of file
# globally add compile options and include directories
add_definitions(${AMDIS_COMPILEFLAGS})
include_directories(${AMDIS_INCLUDE_DIRS})
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(AMDiS VERSION 0.9 LANGUAGES CXX)
message(WARNING "This is an experimental CMakeLists.txt file.")
project(AMDiS VERSION 1.1 LANGUAGES CXX)
set(BASE_DIR ${AMDiS_SOURCE_DIR})
set(SOURCE_DIR ${BASE_DIR}/src)
......@@ -11,6 +9,7 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
endif ()
include(FindPkgConfig)
# ------------------------------------------------------------------------------
#some options to control the build process
......@@ -32,14 +31,9 @@ option(BUILD_SHARED_LIBS "Build all libraries as shared or static, default: shar
mark_as_advanced(BUILD_SHARED_LIBS)
if (MSVC)
# if (${CMAKE_VERSION} VERSION_LESS "3.4")
set(BUILD_SHARED_LIBS false)
mark_as_advanced(BUILD_SHARED_LIBS)
message(WARNING "Currently we can only build static libraries with Visual Studio")
# elseif (BUILD_SHARED_LIBS)
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true)
# set(MSVC_SHARED_LIBS true)
# endif ()
set(BUILD_SHARED_LIBS false)
mark_as_advanced(BUILD_SHARED_LIBS)
message(WARNING "Currently we can only build static libraries with Visual Studio")
endif (MSVC)
# ------------------------------------------------------------------------------
......@@ -49,22 +43,12 @@ add_library(amdis_base INTERFACE)
add_library(AMDiS::base ALIAS amdis_base)
target_include_directories(amdis_base INTERFACE ${SOURCE_DIR})
target_compile_definitions(amdis_base INTERFACE
$<$<CONFIG:Release>:DEBUG=0>
$<$<NOT:$<CONFIG:Release>>:DEBUG=1>)
target_compile_definitions(amdis_base INTERFACE)
include(test_compile_features)
test_compile_features(ENABLE_CXX11 amdis_base INTERFACE
cxx_alias_templates
cxx_auto_type
cxx_lambdas
cxx_override
cxx_range_for
cxx_static_assert
cxx_variadic_templates)
target_enable_cxx11(ENABLE_CXX11 amdis_base INTERFACE)
if (ENABLE_CXX11)
# set(CMAKE_CXX_STANDARD 11)
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=1)
else ()
target_compile_definitions(amdis_base INTERFACE HAS_CXX11=0)
......@@ -75,10 +59,15 @@ endif (ENABLE_CXX11)
include(find_mtl4) # -> target mtl4
install(FILES ${BASE_DIR}/cmake3/find_mtl4.cmake DESTINATION share/amdis/)
include(find_umfpack)
if (ENABLE_UMFPACK)
include(target_enable_umfpack) # -> target boost
target_enable_umfpack(amdis_base INTERFACE)
install(FILES ${BASE_DIR}/cmake3/target_enable_umfpack.cmake DESTINATION share/amdis/)
endif (ENABLE_UMFPACK)
include(find_boost) # -> target boost
install(FILES ${BASE_DIR}/cmake3/find_boost.cmake DESTINATION share/amdis/)
include(target_enable_boost) # -> target boost
target_enable_boost(amdis_base INTERFACE)
install(FILES ${BASE_DIR}/cmake3/target_enable_boost.cmake DESTINATION share/amdis/)
# ------------------------------------------------------------------------------
......@@ -236,9 +225,9 @@ endif (ENABLE_COMPOSITE_FEM)
# ------------------------------------------------------------------------------
if (MSVC)
target_compile_definitions(amdis PRIVATE
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS)
target_compile_definitions(amdis PRIVATE
_SCL_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS)
endif (MSVC)
target_link_libraries(amdis AMDiS::base muparser)
......@@ -266,5 +255,4 @@ configure_file(${BASE_DIR}/cmake3/AMDISConfig.cmake.in
install(FILES ${AMDiS_BINARY_DIR}/AMDISConfig.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/AMDISUse.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/test_compile_features.cmake DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/dummy.cc DESTINATION share/amdis/)
install(FILES ${BASE_DIR}/cmake3/test_compile_features.cmake DESTINATION share/amdis/)
\ 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)
# source: https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake
# - Try to find PETSc
# Once done this will define
#
......@@ -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) ")
......@@ -42,14 +68,21 @@ function (petsc_get_version)
endif ()
endfunction ()
if (PETSC_DIR)
file(TO_CMAKE_PATH ${PETSC_DIR} PETSC_DIR)
endif (PETSC_DIR)
find_path (PETSC_DIR include/petsc.h
HINTS ${AMDIS_PETSC_DIR} $ENV{HOME}/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")
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
......@@ -59,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)
......@@ -79,25 +112,22 @@ 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}/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_variables "${PETSC_DIR}/lib/petsc/conf/variables")
endif ()
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
set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules")
set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables")
elseif (PETSC_DIR)
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 ()
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}")
......@@ -112,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)
......@@ -126,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})
......@@ -134,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)
......@@ -175,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)
......@@ -207,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).")
......@@ -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
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.")