How to deal with PCH?

1,290 views
Skip to first unread message

Mathias Gaunard

unread,
Sep 9, 2012, 9:03:55 AM9/9/12
to ninja-build
It seems that the idea with Ninja is to use -MD type flags to generate
implicit dependencies.
However, both GCC and Clang are bogus and will not output the
dependencies from a PCH file when using it. (see gcc bug 14933)

What is therefore the recommended way to deal with this?

Allan Odgaard

unread,
Sep 9, 2012, 9:17:01 AM9/9/12
to ninja...@googlegroups.com
On Sep 9, 2012, at 3:03 PM, Mathias Gaunard <mat...@gaunard.com> wrote:

> […] GCC and Clang […] will not output the dependencies from a PCH file […] (gcc bug 14933)
>
> What is therefore the recommended way to deal with this?


Setup your .o files to depend on the precompiled header (i.e. the version produced by clang/gcc), which in turn should depend on the headers it includes (which are output with -MD when you precompile it).

In best-case this improves build performance (smaller DAG) and makes perfect sense to me, so I wouldn’t consider it a bug.

Nico Weber

unread,
Sep 9, 2012, 6:36:18 PM9/9/12
to ninja...@googlegroups.com
On Sun, Sep 9, 2012 at 6:17 AM, Allan Odgaard <text...@gmail.com> wrote:
On Sep 9, 2012, at 3:03 PM, Mathias Gaunard <mat...@gaunard.com> wrote:

> […] GCC and Clang […] will not output the dependencies from a PCH file […] (gcc bug 14933)
>
> What is therefore the recommended way to deal with this?


Setup your .o files to depend on the precompiled header (i.e. the version produced by clang/gcc), which in turn should depend on the headers it includes (which are output with -MD when you precompile it).

That's what we do in chromium as well.

Rule for the gch file:

build $
    obj/third_party/WebKit/Source/WebCore/webcore_platform.WebCorePrefix.h-cc.gch: $
    cxx ../../third_party/WebKit/Source/WebCore/WebCorePrefix.h
  cflags_pch_cc = -x c++-header

Rule for a cpp file depending on it:

build $
    obj/third_party/WebKit/Source/WebCore/platform/webcore_platform.LayoutTestSupport.o: $
    cxx $
    ../../third_party/WebKit/Source/WebCore/platform/LayoutTestSupport.cpp $
    | $
    obj/third_party/WebKit/Source/WebCore/webcore_platform.WebCorePrefix.h-cc.gch $
    || $    obj/third_party/WebKit/Source/WebCore/WebCore.gyp/webcore_platform.gen/WebCore/WebCoreSystemInterface.h

(Since compile flags are different for precompiled headers in c, c++, objc, and objc++ modes, we build four different gch files. This example is for c++, hence the '-cc.gch'.)

If you use gyp, the GCC_PRECOMPILE_PREFIX_HEADER and GCC_PREFIX_HEADER xcode_settings get translated into the right thing transparently for the ninja generator.

Nico


Reply all
Reply to author
Forward
0 new messages