Actual source code: package.c

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

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

  6:   Not Collective

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

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

 14:   Level: intermediate

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

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

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

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

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