FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
720 stars 177 forks source link

can't find PETSc complex: PETSC_DIR not set in FindPETSc.cmake #819

Closed drew-parsons closed 4 years ago

drew-parsons commented 4 years ago

Trying to test dolfinx with complex number support. I've pointed PETSC_DIR at the location of my PETSc complex installation (on Debian) and provided it to cmake:

cmake -D PETSC_DIR:PATH=/usr/lib/petscdir/petsc3.12/x86_64-linux-gnu-complex  ..

(not showing the other cmake flags here) But cmake finds my PETSc real instead of PETSc complex.

Digging into FindPETSc.cmake, it's using pkg-config to find PETSc, with

set(ENV{PKG_CONFIG_PATH} "$ENV{CRAY_PETSC_PREFIX_DIR}/lib/pkgconfig:$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")

If I set a debug message here (message("looking for PETSc with PKG_CONFIG_PATH = $ENV{PKG_CONFIG_PATH}"))

then cmake prints

looking for PETSc with PKG_CONFIG_PATH=/lib/pkgconfig://lib/pkgconfig:/lib/pkgconfig:

So evidently the definition of PETSC_DIR given by -D PETSC_DIR:PATH= is not propagating down into FindPETSc.cmake.

But of course, FindPETSc.cmake here is using $ENV{PETSC_DIR}, not ${PETSC_DIR}. Should this be changed (or should perhaps both $ENV{PETSC_DIR} and ${PETSC_DIR} be used?)

drew-parsons commented 4 years ago

The same applies to FindSLEPc.cmake too.

drew-parsons commented 4 years ago

Alternatively should it be documented that PETSC_DIR must set as a environment variable, not as a cmake defined variable?

(I guess cmake -DPETSC_DIR never was working, so Debian/Ubuntu builds have only ever been made against the default PETSc version found by pkg-config from the default PKG_CONFIG_PATH)

francesco-ballarin commented 4 years ago

Has it not always been that PETSC_DIR should be an environment variable, even in DOLFIN? I have got an "export PETSC_DIR=..." in my fenics install script for as long as I can remember, and that has not changed in the fenicsx one.

Apart from that, I do agree that this should be documented. For instance this line https://github.com/FEniCS/dolfinx/blob/master/cpp/cmake/modules/FindPETSc.cmake#L238 can be changed in

    FAIL_MESSAGE "PETSc could not be found. Be sure to set PETSC_DIR as an environment variable.")

(just to put my two cents in)

chrisrichardson commented 4 years ago

@francesco-ballarin - feel free to make a PR