target_precompile_headers: Support for BEFORE and AFTER
After looking up on of the generated pch files in my project I noticed that target_precompile_headers append the list of precompiled headers of linked libraries to the back of target's pch file. This leads to my problem where I have two libraries (A and B, B links against A) that have their own set of precompiled headers. In case of B, some precompiled headers are dependent on headers defined in A's precompiled headers. Because precompiled headers of A are appended to the back of B's pch, B fails to build. So far, I can see two workarounds for the problem:
- #include required headers in B's header files
- add required headers to target_precompile_headers in B (place them before the header that requires them)
I quickly glimpsed over the CMake src and extending support for BEFORE and AFTER seems pretty straightforward. I believe some additional care should be taken when handling REUSE_FROM together with those flags (probably REUSE_FROM should be mutually exclusive with AFTER/BEFORE).
I am not sure if it is up to the discussion here, but maybe it would be good to consider making target_precompile_headers default behaviour to PREPEND instead of APPEND precompiled headers of linked libraries. Personally, I would find it more intuitive but probably it is just me and there are many reasons why the current approach is better.