3

I have prepared some sort of compiler wrapper which:

  • Invoke original compiler with original params(+ flags needed to force preprocessing only) to generate preprocessed C++ file
  • Do some sort of magic on preprocessed file
  • Invoke original compiler with approximately original params to generate object file from my magically changed file

Similar procedure for linking executables, static/shared libraries etc.

My wrapper is designed to handle gcc, clang and msvc flags.

To inject my "compiler wrapper" for cmake projects, make projects or autotools is very easy(cmake params, env variables, autotools params etc.), however I have no idea how to do this with Visual Studio solutions or msbuild.

So question is: do you know any way, how can I force msbuild or visual studio to use my wrapper instead cl?

(mostly interesting for me is msvc 2015 professional, however this probably doesn't matter)

Only idea I have is to change PATH env variable and name my wrapper cl.exe but this smells for my very ugly and I will be very surprised if there is no more clever solution.

Joy
  • 1,171
  • 9
  • 15
  • If you want full-blown support than the proper way is probably to create an additional toolset (meaning a bunch of msbuild files in the correct location). You could look at how other compiler writers do it (intel and e.g. https://blogs.msdn.microsoft.com/vcblog/2015/12/04/clang-with-microsoft-codegen-in-vs-2015-update-1/). Otherwise build your sources using 'Custom Build Tool' or use a makefile project. – stijn Aug 04 '17 at 14:36
  • Usage of makefiles(anyway I support it out of the box) is not a solution(or at most last option) because this way it will require from potential user of my tool to create from scratch whole build configs only to use them(even if I'm personally hater of microsoft solutions in this area and think that every seriously developed/maintained C/C++ project should have cmake, it doesn't mean that for end users it is not big effort to create them). Anyway thank you for answer - i will try to find how it's done for clang. – Tomasz Frydrych Aug 09 '17 at 11:40
  • 1
    Cannot yet mark this as duplicate, but just figured out the answer, see https://stackoverflow.com/questions/45835043/how-to-override-compile-command-of-visual-studio-2017-community. In short: override ClToolExe and ClToolPath properties and point them to your executable. – stijn Aug 23 '17 at 14:19
  • Possible duplicate of [How to override compile command of Visual Studio 2017 Community](https://stackoverflow.com/questions/45835043/how-to-override-compile-command-of-visual-studio-2017-community) – stijn Aug 23 '17 at 14:40
  • 1
    Possible duplicate of [How to use Clang compiler with MSBuild?](https://stackoverflow.com/questions/30761708/how-to-use-clang-compiler-with-msbuild) – Trass3r May 31 '19 at 18:10

0 Answers0