Actual source code: package.c


  2: #include <petsc/private/petscimpl.h>

  4: /*@C
  5:    PetscHasExternalPackage - Determine whether PETSc has been configured with the given package

  7:    Not Collective

  9:    Input Parameter:
 10: .  pkg - external package name

 12:    Output Parameter:
 13: .  has - `PETSC_TRUE` if PETSc is configured with the given package, else `PETSC_FALSE`.

 15:    Level: intermediate

 17:    Notes:
 18:    This is basically an alternative for `PETSC_HAVE_XXX` whenever a preprocessor macro is not available/desirable, e.g. in Python.

 20:    The external package name pkg is e.g. "hdf5", "yaml", "parmetis".
 21:    It should correspond to the name listed in  `./configure --help`  or e.g. in `PetscViewerType`, `MatPartitioningType`, `MatSolverType`.

 23:    The lookup is case insensitive, i.e. looking for "HDF5" or "hdf5" is the same.

 25: .seealso: `PetscViewerType`, `MatPartitioningType`, `MatSolverType`
 26: @*/
 27: PetscErrorCode PetscHasExternalPackage(const char pkg[], PetscBool *has)
 28: {
 29:   char   pkgstr[128], *loc;
 30:   size_t cnt;

 32:   PetscFunctionBegin;
 35:   PetscCall(PetscSNPrintfCount(pkgstr, sizeof(pkgstr), ":%s:", &cnt, pkg));
 36:   PetscCheck(cnt < sizeof(pkgstr), PETSC_COMM_SELF, PETSC_ERR_SUP, "Package name is too long: \"%s\"", pkg);
 37:   PetscCall(PetscStrtolower(pkgstr));
 38: #if defined(PETSC_HAVE_PACKAGES)
 39:   PetscCall(PetscStrstr(PETSC_HAVE_PACKAGES, pkgstr, &loc));
 40: #else
 41:   #error "PETSC_HAVE_PACKAGES macro undefined. Please reconfigure"
 42: #endif
 43:   *has = loc ? PETSC_TRUE : PETSC_FALSE;
 44:   PetscFunctionReturn(PETSC_SUCCESS);
 45: }