From dda2bc6ee1f1eaf6bc2c006833ac4c50681a6a72 Mon Sep 17 00:00:00 2001 From: maier Date: Mon, 24 Sep 2012 15:56:08 +0000 Subject: [PATCH] Bugfix: Search for petsc correctly. git-svn-id: https://svn.dealii.org/branches/branch_cmake@26670 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/cmake/configure/configure_petsc.cmake | 15 +++-- deal.II/cmake/modules/FindPETSC.cmake | 66 ++++++++++++++++--- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/deal.II/cmake/configure/configure_petsc.cmake b/deal.II/cmake/configure/configure_petsc.cmake index a4ac110581..a6eb563494 100644 --- a/deal.II/cmake/configure/configure_petsc.cmake +++ b/deal.II/cmake/configure/configure_petsc.cmake @@ -27,20 +27,21 @@ MACRO(FEATURE_PETSC_FIND_EXTERNAL var) # Petsc has to be configured with the same MPI configuration as # deal.II. # - # petscconf.h should export PETSC_HAVE_MPI 1 if mpi support is enabled. + # petscconf.h should export PETSC_HAVE_MPIUNI 1 in case mpi support is + # _NOT_ enabled. # So we check for this: # - FILE(STRINGS "${PETSC_INCLUDE_DIR}/petscconf.h" PETSC_RELEASE_STRING - REGEX "#define.*PETSC_HAVE_MPI.*1") + FILE(STRINGS "${PETSC_PETSCCONF_H}" PETSC_RELEASE_STRING + REGEX "#define.*PETSC_HAVE_MPIUNI 1") IF("${PETSC_RELEASE_STRING}" STREQUAL "") - SET(PETSC_WITH_MPI FALSE) + SET(PETSC_WITH_MPIUNI FALSE) ELSE() - SET(PETSC_WITH_MPI TRUE) + SET(PETSC_WITH_MPIUNI TRUE) ENDIF() - IF( (PETSC_WITH_MPI AND NOT DEAL_II_COMPILER_SUPPORTS_MPI) + IF( (PETSC_WITH_MPIUNI AND DEAL_II_COMPILER_SUPPORTS_MPI) OR - (NOT PETSC_WITH_MPI AND DEAL_II_COMPILER_SUPPORTS_MPI)) + (NOT PETSC_WITH_MPIUNI AND NOT DEAL_II_COMPILER_SUPPORTS_MPI)) MESSAGE(STATUS "Could not find a sufficient petsc installation: " "Petsc has to be configured with the same MPI configuration as deal.II." diff --git a/deal.II/cmake/modules/FindPETSC.cmake b/deal.II/cmake/modules/FindPETSC.cmake index fc6d183fc9..f8688998d6 100644 --- a/deal.II/cmake/modules/FindPETSC.cmake +++ b/deal.II/cmake/modules/FindPETSC.cmake @@ -4,11 +4,17 @@ INCLUDE(FindPackageHandleStandardArgs) -FIND_PATH(PETSC_INCLUDE_DIR petscconf.h +# +# To safe some logic, promote environment variables to cmake variables if +# they are not already set. +# +SET_IF_EMPTY(PETSC_DIR "$ENV{PETSC_DIR}") +SET_IF_EMPTY(PETSC_ARCH "$ENV{PETSC_ARCH}") + +FIND_PATH(PETSC_INCLUDE_DIRS petscconf.h HINTS # petsc is special. Account for that ${PETSC_DIR}/${PETSC_ARCH}/include - $ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/include PATH_SUFFIXES petsc ) @@ -17,27 +23,71 @@ FIND_LIBRARY(PETSC_LIBRARY HINTS # petsc is special. Account for that ${PETSC_DIR}/${PETSC_ARCH} - $ENV{PETSC_DIR}/$ENV{PETSC_ARCH} PATH_SUFFIXES lib${LIB_SUFFIX} lib64 lib ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PETSC DEFAULT_MSG PETSC_LIBRARY PETSC_INCLUDE_DIR) + +# +# So, up to this point it was easy. Now, the tricky part. +# If petsc is not installed, but a source tree is given by PETSC_DIR petsc +# splits up its include files to two places: +# ${PETSC_DIR}/include +# ${PETSC_DIR}/${PETSC_ARCH}/incldue +# +IF("${PETSC_INCLUDE_DIRS}" STREQUAL "${PETSC_DIR}/${PETSC_ARCH}/include") + # + # We found petsc and we used PETSC_DIR and PETSC_ARCH for finding it. + # + LIST(APPEND PETSC_INCLUDE_DIRS "${PETSC_DIR}/include") +ENDIF() + +# +# Let's see whether we are able to find petscversion.h and petscconf.h: +# +FIND_FILE(PETSC_PETSCVERSION_H petscversion.h + HINTS + ${PETSC_INCLUDE_DIRS} + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_FIND_ROOT_PATH + ) + +FIND_FILE(PETSC_PETSCCONF_H petscconf.h + HINTS + ${PETSC_INCLUDE_DIRS} + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_FIND_ROOT_PATH + ) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PETSC DEFAULT_MSG + PETSC_LIBRARY + PETSC_INCLUDE_DIRS + PETSC_PETSCCONF_H + PETSC_PETSCVERSION_H + ) IF(PETSC_FOUND) - FILE(STRINGS "${PETSC_INCLUDE_DIR}/petscversion.h" PETSC_MAJOR_STRING + FILE(STRINGS "${PETSC_PETSCVERSION_H}" PETSC_MAJOR_STRING REGEX "#define.*PETSC_VERSION_MAJOR") STRING(REGEX REPLACE "^.*PETSC_VERSION_MAJOR.*([0-9]+).*" "\\1" PETSC_MAJOR "${PETSC_MAJOR_STRING}") - FILE(STRINGS "${PETSC_INCLUDE_DIR}/petscversion.h" PETSC_MINOR_STRING + FILE(STRINGS "${PETSC_PETSCVERSION_H}" PETSC_MINOR_STRING REGEX "#define.*PETSC_VERSION_MINOR") STRING(REGEX REPLACE "^.*PETSC_VERSION_MINOR.*([0-9]+).*" "\\1" PETSC_MINOR "${PETSC_MINOR_STRING}") - FILE(STRINGS "${PETSC_INCLUDE_DIR}/petscversion.h" PETSC_SUBMINOR_STRING + FILE(STRINGS "${PETSC_PETSCVERSION_H}" PETSC_SUBMINOR_STRING REGEX "#define.*PETSC_VERSION_SUBMINOR") STRING(REGEX REPLACE "^.*PETSC_VERSION_SUBMINOR.*([0-9]+).*" "\\1" PETSC_SUBMINOR "${PETSC_SUBMINOR_STRING}") - FILE(STRINGS "${PETSC_INCLUDE_DIR}/petscversion.h" PETSC_RELEASE_STRING + FILE(STRINGS "${PETSC_PETSCVERSION_H}" PETSC_RELEASE_STRING REGEX "#define.*PETSC_VERSION_RELEASE.*1") IF("${PETSC_RELEASE_STRING}" STREQUAL "") SET(PETSC_RELEASE FALSE) -- 2.39.5