3

I have a precompiled header that needs to be included atop each .cpp in my project. I fear that I will waste a lot of time explaining and fixing that in coworkers code.

Is there an MSBuild step that I can do to #include "stdafx.h" at the top of all my .cpp files so it dosen't need to do done manually?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    I'm confused--why do the pch requirements of your project need to affect what other people do with their projects? – dlf Nov 06 '14 at 14:28
  • @dlf Ugh, now that I reread that "other people's projects" makes no sense. I've changed it to say "coworkers code". – Jonathan Mee Nov 06 '14 at 14:37
  • @JonathanMee That does make more sense. :) But if I recall correctly, if you have precompiled headers switched on, MSBuild gives you an actual build-time error if you neglect to #include stdafx.h in any cpp (unless that cpp specifically has precompiled headers disabled), which (hopefully!) makes it difficult to forget. But to answer your question directly--I'm not aware of any way to make the compiler forcibly include a particular header in every cpp whether it asks for it or not. – dlf Nov 06 '14 at 14:40
  • @Jarod42 `/Yu` is the switch that I use to indicate that _I am_ using a precompiled header, but then I need to go `#include "stdafx.h"` at the top of all the .cpps. I want to remove the need to add `#include "stdafx.h"` at the top of all my .cpps; that is to say I want to do that programatically. – Jonathan Mee Nov 06 '14 at 14:48

1 Answers1

5

You have the compiler option /FI pathname

which virtually add #include "pathname" at the first line of the file.

Note: the equivalent for gcc is -include path.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Yeah I just found it thanks I just found that /FI option thanks to your "gcc -include" comment and this page: http://www.cmake.org/pipermail/cmake/2010-February/035208.html Testing it out and then I will accept. – Jonathan Mee Nov 06 '14 at 15:06