xref: /petsc/src/sys/objects/package.c (revision 5f80ce2ab25dff0f4601e710601cbbcecf323266)
1 
2 #include <petsc/private/petscimpl.h>        /*I    "petscsys.h"   I*/
3 
4 /*@C
5    PetscHasExternalPackage - Determine whether PETSc has been configured with the given package
6 
7    Not Collective
8 
9    Input Parameters:
10 .  pkg - external package name
11 
12    Output Parameters:
13 .  has - PETSC_TRUE if PETSc is configured with the given package, else PETSC_FALSE.
14 
15    Level: intermediate
16 
17    Notes:
18    This is basically an alternative for PETSC_HAVE_XXX whenever a preprocessor macro is not available/desirable, e.g. in Python.
19 
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.
22 
23    The lookup is case insensitive, i.e. looking for "HDF5" or "hdf5" is the same.
24 
25 .seealso: PetscViewerType, MatPartitioningType, MatSolverType
26 @*/
27 PetscErrorCode  PetscHasExternalPackage(const char pkg[], PetscBool *has)
28 {
29   char   pkgstr[128], *loc;
30   size_t cnt;
31 
32   PetscFunctionBegin;
33   PetscValidCharPointer(pkg,1);
34   PetscValidBoolPointer(has,2);
35   CHKERRQ(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   CHKERRQ(PetscStrtolower(pkgstr));
38 #if defined(PETSC_HAVE_PACKAGES)
39   CHKERRQ(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(0);
45 }
46