Applying user7860670's idea, I was able to achieve the desired functionality (even though my original question asked for something else), although now compilation is slower by about 1-2 seconds.