Bug 89155 - [Help Wanted] Support GCC precompiled headers for managed makefiles
Summary: [Help Wanted] Support GCC precompiled headers for managed makefiles
Status: ASSIGNED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement with 9 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords: helpwanted
: 106697 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-26 00:50 EST by Alexander Staubo CLA
Modified: 2020-09-04 15:21 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Staubo CLA 2005-03-26 00:50:40 EST
GCC 3.4 supports precompiling headers to drastically reduce compilation time.
This feature can be activated by executing the compiler directly on the header
file, like so:

  gcc all.h

Or, if the file is not named like a header, like so:

  gcc -x c-header all.cpp

This generates a .gch file, which GCC will automatically pick up if all.h or
all.cpp is included with #include.

Since CDT doesn't support customized make steps or per-file compilation
settings, there's no way to automatically execute any of the above commands as
part of the build process.

You'd think that you could tell CDT that .H or .hh was a source file instead of
a header file, but in the current milestone 5, 1) CDT ignores such redefinitions
(if you do it through the global prefs, the mapping is not even saved), and 2)
there's no way to set the header to be compiled before other files, anyway.
Comment 1 Tom Tromey CLA 2005-09-02 13:44:40 EDT
Note that you can't reliably make a separate build rule
(or a pre-make rule in the cdt builder) that does this, either,
because the compiler flags must be the same for the PCH
build and these are not available in the generated Makefile
(they are baked directly into the compilation rules).
E.g., changing from the debug to the release configuration
would break the PCH file.
Comment 2 Johan Walles CLA 2007-11-08 10:27:30 EST
Would using ccache be good enough for you?

http://ccache.samba.org/

Instead of "gcc", just use "ccache gcc" as your compiler.
Comment 3 Chris Recoskie CLA 2009-05-07 14:59:06 EDT
CDT has had per-file compilation settings and pre and post build steps for a long time now, but the rest of the story is still missing.

I don't think anyone is currently planning to work on this.  Help wanted.
Comment 4 Andrew Gvozdev CLA 2009-07-28 17:45:03 EDT
*** Bug 106697 has been marked as a duplicate of this bug. ***
Comment 5 David Brady CLA 2009-10-24 17:12:24 EDT
I've successfully made precompiled headers work in my own plugin for another compiler.  I could replicate the work for GCC and post it here, but I don't know if I'll have time for a while, and there's other bugs that are a higher priority for me to have fixed right now.

But it was really simple to get working.

What I did was add headers as a compilable filetype for the compiler tool, and a nameProvider for the outputType, that will output a gch if it detects a header filetype.  This step adds headers to the makefile.

I then added an additional dependency on a $(PCH) make variable to the non-header input files for the compiler tool.  

I then added an additional compiler option for headers, to precompile the headers.  Then when the user selects the precompile option, the compile options are changed accordingly, and the headers are added to the $(PCH) variable.

Then when the user builds, since all the source files depend on the gch files, they are built first (even with parallel builds enabled), and everything's good.

The only bit of this that I couldn't get working for my own plugin, was adding the headers automatically to the $(PCH) variable when the precompile option was selected.  I actually modify the make command to be "make PCH=header.gch".  It works well enough for our project.