# PETSC_FOUND
# PETSC_LIBRARIES
# PETSC_INCLUDE_DIRS
-# PETSC_PETSCCONF_H
-# PETSC_PETSCVERSION_H
# PETSC_VERSION
# PETSC_VERSION_MAJOR
# PETSC_VERSION_MINOR
SET_IF_EMPTY(PETSC_DIR "$ENV{PETSC_DIR}")
SET_IF_EMPTY(PETSC_ARCH "$ENV{PETSC_ARCH}")
-FIND_PATH(PETSC_INCLUDE_DIRS petscconf.h
+
+#
+# Search for the first part of the includes:
+#
+FIND_PATH(PETSC_INCLUDE_DIR_ARCH petscconf.h
HINTS
# petsc is special. Account for that
${PETSC_DIR}/${PETSC_ARCH}/include
+ ${PETSC_INCLUDE_DIRS}
PATH_SUFFIXES petsc
)
+
FIND_LIBRARY(PETSC_LIBRARIES
NAMES petsc
HINTS
# 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
+# ${PETSC_DIR}/${PETSC_ARCH}/include
#
-IF("${PETSC_INCLUDE_DIRS}" STREQUAL "${PETSC_DIR}/${PETSC_ARCH}/include")
+IF("${PETSC_INCLUDE_DIR_ARCH}" STREQUAL "${PETSC_DIR}/${PETSC_ARCH}/include")
#
# We found petsc and we used PETSC_DIR and PETSC_ARCH for finding it.
+ # So, we assume a source tree layout:
#
- LIST(APPEND PETSC_INCLUDE_DIRS "${PETSC_DIR}/include")
+ IF(PETSC_INCLUDE_DIRS MATCHES "-NOTFOUND")
+ SET(PETSC_INCLUDE_DIRS "${PETSC_INCLUDE_DIR_ARCH};${PETSC_DIR}/include"
+ CACHE STRING "Include paths for petsc"
+ FORCE
+ )
+ ENDIF()
ENDIF()
NO_CMAKE_FIND_ROOT_PATH
)
+#
+# If no, PETSC_INCLUDE_DIRS is invalid, so reset it to NOTFOUND:
+#
+IF( PETSC_PETSCCONF_H MATCHES "-NOTFOUND" OR
+ PETSC_PETSCVERSION_H MATCHES "-NOTFOUND" )
+ SET(PETSC_INCLUDE_DIRS "PETSC_INCLUDE_DIRS-NOTFOUND"
+ CACHE STRING "Include paths for petsc"
+ FORCE
+ )
+ENDIF()
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(PETSC DEFAULT_MSG
+ PETSC_LIBRARIES
+ PETSC_INCLUDE_DIRS
+ PETSC_PETSCCONF_H
+ PETSC_PETSCVERSION_H
+ )
+
-IF(NOT PETSC_PETSCCONF_H MATCHES "-NOTFOUND")
+IF(PETSC_FOUND)
#
# Is petsc compiled with support for MPIUNI?
MARK_AS_ADVANCED(PETSC_LIBMPIUNI)
ENDIF()
-ENDIF()
-
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(PETSC DEFAULT_MSG
- PETSC_LIBRARIES
- PETSC_INCLUDE_DIRS
- PETSC_PETSCCONF_H
- PETSC_PETSCVERSION_H
- )
-
-IF(PETSC_FOUND)
FILE(STRINGS "${PETSC_PETSCVERSION_H}" PETSC_VERSION_MAJOR_STRING
REGEX "#define.*PETSC_VERSION_MAJOR")
MARK_AS_ADVANCED(
PETSC_LIBRARIES
PETSC_INCLUDE_DIRS
- PETSC_PETSCCONF_H
- PETSC_PETSCVERSION_H
)
ENDIF()
+#
+# Unset a bunch of cached variables.
+# Only PETSC_INCLUDE_DIRS should remain cached
+#
+UNSET(PETSC_INCLUDE_DIR_ARCH CACHE)
+UNSET(PETSC_PETSCCONF_H CACHE)
+UNSET(PETSC_PETSCVERSION_H CACHE)