0

So I have the following setup (simplified version):

application/app1.hpp
application/app1.cpp
application/utils/utils1.hpp
application/utils/utils1.cpp

So when I compile app1.cpp I do so like this (this is a cut-down version of the compile):

g++ -Wall -Wextra -Werror -I application -isystem application/utils -MMD -MP -MF dep.d -c application/app1.cpp -o obj.o

Where I use -MDD to auto generate dependency information. I use -isystem to inhibit warnings from files in utils folder.

Note: that utils is a sub-module (i.e. a seperate project that compiles on its own). Therefore I don't want compile warnings/errors from that project. Therefore I am using -isystem application/utils to include folders. When you use isystem you don't get gcc warnings - which is great :)

However I just discovered that this is also the reason I am not getting complete depenecy outputs. Files included in the isystem directories are not added as dependecies in the gcc generated dep.d file.

So it seems I can either ignore the warnings from utils but not get depenency generation for it OR I can get the dependency output but not ignore the warnings.

I really want both:

  • No warnings from utils
  • Dependencies from utils folder (via gcc's -MMD)

Is that possible to get both behaviours somehow?

Some ideas of mine:

  • I was thinking of somehow running the dependency pre-processor part on its own first and then the compile... but I did not see a way to do that
  • Force include folders in the MMD part. I found that I can include specific files with -include but not folders and I don't have a list of files :(
code_fodder
  • 15,263
  • 17
  • 90
  • 167
  • 1
    You're going to end up with several portability problems. The `-isystem` behavior gets overloaded a lot on different operating systems. I ran into a BSD (OpenBSD maybe?) a while ago where all `-isystem` headers were automatically wrapped in `extern "C"` blocks. That was a problem for Boost. – Zan Lynx Jan 15 '19 at 20:45
  • Yeah, watch out for this: https://stackoverflow.com/questions/9775583/why-does-openbsds-g-make-system-headers-default-to-c-linkage – Zan Lynx Jan 15 '19 at 20:48
  • @ZanLynx thanks for the heads up on that one :) . For the moment I am happy that our environment is a controlled one (ubuntu linux only) for building. – code_fodder Jan 15 '19 at 21:06

1 Answers1

0

I just found something that could work, but I am not sure how efficient it is. I found the -E gcc option which replaces -c (compile) with preprocess only). So I could do:

  1. Generate the dependency info:

    g++ -I application -I application/utils -E application/app1.cpp -o /dev/null -MMD -MP -MF dep.d

  2. Compile the file with minimal warnings:

    g++ -Wall -Wextra -Werror -I application -isystem application/utils -c application/app1.cpp -o obj.o

This will mean that the preprocessor runs twice - not sure how much work that is... but it seems to run pretty quickly compared to the compile phase.

If there is further ideas I am still very much open to them... I won't mark this answer for a while incase someone has a better idea...

Community
  • 1
  • 1
code_fodder
  • 15,263
  • 17
  • 90
  • 167