On 14 April 2012 01:19, Jed Brown <jedbrown at mcs.anl.gov> wrote: > > > On Fri, Apr 13, 2012 at 17:17, Mohammad Mirzadeh <mirzadeh at gmail.com> > wrote: >> >> Hi, >> >> Are there any cmake conf file that I can include in my CMakeLists.txt that >> would automatically detect include/lib directory for my petsc installation? >> Right now I'm doing this manually and was wondering if its possibel to >> automate it. > > > https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake >
Jed, have you considered adding this to petsc-dev, removing all the checks for old PETSc releases? Or perhaps better, how about dumping an autogenerated PETSc.cmake in $PETSC_DIR/$PETSC_ARCH/conf/PETSc.cmake, or perhaps other name, defining all the stuff end users need. For example, I'm using the code below in a codebase I'm working on (note that at the end I'm loading PETScConfig.cmake), but this is not robust, it does not handle builds with separate libraries. If PETSc provides all these variables, then I could simply include (${PETSC_DIR}/${PETSC_ARCH}/conf/PETSc.cmake), and you can make your FindPETSc.cmake much simpler (at least for the upcoming version of PETSc) find_path (PETSC_DIR include/petsc.h HINTS ENV PETSC_DIR DOC "PETSc Directory") set (PETSC_ARCH $ENV{PETSC_ARCH}) find_path (PETSC_INCLUDE_DIR petsc.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" NO_DEFAULT_PATH) mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) set (PETSC_INCLUDES ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR} CACHE PATH "PETSc include paths" FORCE) set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc preprocesor definitions" FORCE) find_path (PETSC_LIB_DIR NAMES "" HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/lib" NO_DEFAULT_PATH) find_library (PETSC_LIBRARY NAMES petsc HINTS "${PETSC_LIB_DIR}" NO_DEFAULT_PATH) set (PETSC_LIBRARIES ${PETSC_LIBRARY} CACHE FILEPATH "PETSc library" FORCE) include (${PETSC_DIR}/${PETSC_ARCH}/conf/PETScConfig.cmake) -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo 3000 Santa Fe, Argentina Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169