[petsc-users] Weird handling of compiler flags by the build system

meator meator.dev at gmail.com
Mon Jul 1 04:21:19 CDT 2024


Hello,

I am currently packaging PETSc and have noticed some peculiar behavior 
when attempting to override CFLAGS, CXXFLAGS, and FFLAGS.

Firstly, when calling ./configure with CFLAGS="args" as its argument, it 
seems to completely override the flag detection system in 
config/BuildSystem/config/compilerOptions.py (and presumably other 
places). Same holds true for CXXFLAGS and FFLAGS. This is not desirable 
for me. With the underlying compiler detected as GCC, I would normally 
get -fvisibility=hidden and a bunch of extra warnings. These all get 
lost when CFLAGS or CXXFLAGS is overridden. Is there a way to simply 
append flags instead of overriding them? Losing flags such as 
-fvisibility=hidden can severely affect the compiled library.

Other build systems usually differentiate between mandatory flags that 
will get included no matter what and overridable flags which may be 
replaced. It looks like such a system even exists in PETSc, because 
-fPIC gets included in C flags even when CFLAGS is set. I understand 
that the situation here is a bit more complex, as PETSc must support a 
plethora of compilers which use differing flags and compiler wrappers 
like mpicc are prevalent.

I assume that the same issue occurs for FFLAGS. I do not know Fortran, 
so I cannot evaluate the risks of omitting flags that are included when 
FFLAGS isn't specified, but I assume that some of the "lost" flags are 
also of importance.

Another issue, which I find more severe, is that the overridden flags 
get included in cflags_extra, cxxflags_extra, and fflags_extra of the 
generated pkg-config file. This is highly undesirable because the flags 
used to build PETSc should not be used for compiling user programs. My 
package template provides flags like -ffile-prefix-map, which make sense 
when PETSc is being built in a fake destdir to be packaged but do not 
make sense for user programs.

The pkg-config file generated by PETSc is something I've never seen 
before. It took me a considerable amount of time to comprehend the extra 
keys set there, but I now understand that they are used in the sample 
Makefile and CMake build definition file.

I am not 100% certain why this system is in place. Why does the 
pkg-config file need to provide extra flags and set compilers? I've seen 
no other pkg-config file which does such things.

Is there a way to fix the pkg-config file (apart from manually removing 
cflags_extra, cxxflags_extra, and fflags_extra from the .pc file)?

Thanks in advance
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x1A14CB3464CBE5BF.asc
Type: application/pgp-keys
Size: 6275 bytes
Desc: OpenPGP public key
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240701/b2d06bd7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240701/b2d06bd7/attachment.sig>


More information about the petsc-users mailing list