https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html lists the preconditions that need to be satisfied for a precompiled header to be usable with a given compiler invocation.
In short it's:
- same compiler binary
same -m -f -p -O options with exceptions for: -fmessage-lenght= -fpreprocessed -fsched-interblock -fsched-spec -fsched-spec-load -fsched-spec-load-dangerous -fsched-verbose=number -fschedule-insns -fvisibility= -pedantic-errors
-g at least if the compilation is with -g (=> pchs should always be compiled with -g)
I'm curious if I could manage this automatically for an arbitrary option set.
The idea is I could run my gcc invocation through a wrapper that would extract from it information about the compiler binary and the -m -f -p -O options, form a filepath for the compiled header based on this info, check if a precompiled header is already in there and if not create it, prepend the header's directory to the preprocessor's iquote or isystem search path, and run the actual wrapped gcc invocation.
Is there a better approach? If not, is there a way for me to extract the gcc options without having to keep in sync with the documented gcc option set?