Bug 153871 - Extended support of C++ precompiled headers
Extended support of C++ precompiled headers
Status: NEW
Product: cnd
Classification: Unclassified
Component: Project
5.x
All All
: P2 with 5 votes (vote)
: 7.4
Assigned To: issues@cnd
issues@cnd
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-25 15:51 UTC by yurac
Modified: 2014-04-14 14:31 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yurac 2008-11-25 15:51:07 UTC
Implement extended support of precompile headers with gcc pls.

what I need:
- some option in project properties (like switch on/off)
- creation of makefiles (build precompile headers (.h .hpp ...) first then object files (.c .cpp ...))

Result:
- change in one header file leads to rebuild of depended .cpp files

This link may help to understand how it all works in gcc:
http://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Precompiled-Headers.html

You have a plug-in for showing c++ headers dependencies - just may be helpful for realization.
Comment 1 Leonid Lenyashin 2008-11-25 16:43:33 UTC
Please evaluate
Comment 2 zachsaw 2012-07-19 07:02:34 UTC
+1 vote (where's the vote button???).

Additionally, allow us to choose the PCH filename.

Also, have a look at how Borland (Embarcadero) implements their PCH.
Comment 3 soldatov 2012-07-19 08:13:15 UTC
(In reply to comment #2)
> +1 vote (where's the vote button???).
Ctrl-F and you can find "Priority: 	P2 with 3 votes (vote)" text
Comment 4 igor_nikiforov 2012-08-27 14:55:14 UTC
You can use the following workaround to get precompiled headers.

For GNU compiler:
    Option #1 (precompiled headers will be created whenever you like):
        1. Go to header's file you want to pre-compile properties (select Properties from it's context menu).
        2. Go to Custom Build Step category and set Compile Line (like, gcc -c -g -Wall myheader.h) and Outputs (like, myheader.h.pch).
        3. Go to the source file(s) compiler properties (Properties -> C Compiler or Properties -> C++ Compiler), the header file included into, and set Additional Dependencies field to precompiled header(s) file name (like, myheader.h.pch).
    
    Option #2 (precompiled headers will be created in the build directory):
        1. Go to header's file you want to precompile properties.
        2. Go to General category and set Tool to either C Compiler or C++ Compiler.
        3. Go to the source file(s) compiler properties (Properties -> C Compiler or Properties -> C++ Compiler), the header file included into, and set Additional Dependencies field to precompiled header(s) name prefixed by ${OBJECTDIR} (like, ${OBJECTDIR}/myheader.h.pch) and Include Directory to ${OBJECTDIR}.


For Oracle Solaris Studio compilers (see http://docs.oracle.com/cd/E18659_01/html/821-1384/bjapr.html#bjavy):
        1. Go to the source file(s) properties.
        2. Set Additional Options on C Compiler or C++ Compiler category to -xpch=auto.


For Qt projects (http://qt-project.org/doc/qt-4.7/qmake-precompiledheaders.html):
        1. Go to Qt project properties.
        2. Set PRECOMPILED_HEADER variable to list of headers you want to precompile in Custom Definitions field.

It would be nice to know if some of the above options doesn't work for you and why.
Comment 5 igor_nikiforov 2012-08-28 12:14:41 UTC
zachsaw and others,

Could you please share you ideas how you expected this to be implemented?
Or provided workarounds are quite suitable for you?

Regards,
  Igor
Comment 6 yurac 2012-08-28 12:36:28 UTC
I was looking for project level switch: use / not use. Because for quite big projects with more than 100 headers its annoying to change properties for around 200 files (100 header file and around 100 cpp files).

Pre-compile header naming is not important for me, I`m ok with "<original_header_name>.pch" pattern, like "my_header.h.pch".

The output is Makefile that builds project with pre-compiled headers. So I can commit it and later checkout on CI node and build sources with pre-compiled headers.
Comment 7 igor_nikiforov 2012-08-28 14:41:16 UTC
yurac, thanks a lot for reply!

Could you, please, answer some more questions to make your requirements more clear.

1. Do you using only GCC or some other compilers sets as well (like Solaris Studio)?
2. All sources from you project are written in the same language (compiled by the same compiler)? I'm asking that as you can't use a C precompiled header for a C++ compilation.
3. It's OK for you to place precompiled header files to the directory with headers or you expect them to be created in some other location?
4. Do you need to provide some additional compiler's options for headers compilation?
5. Are you expecting all .pch files to be removed then you are doing clean of the project or they should not be touched on cleaning?

Probably I'll have some more questions a little bit later.

Thanks in advance,
  Igor
Comment 8 zachsaw 2012-08-29 01:12:57 UTC
Hi Igor,

My thinking of precompiled header support is similar to Yurac's.

Particularly, of all the IDEs I've used, I like the implementation by Borland.

You have the option to either "Create and use" / "Do not use" / "Use PCH file" (this last one won't be possible for what I'm suggesting below).

The way they have done it is the precompiled header for the entire project ends up in one PCH file (it's huge but it's also used for code assist / completion). I suspect this is not possible with GCC, but it would be possible to create the same in a "pch" folder as individual files, just like how .o files are dumped into "bin".

Answers to your question to Yurac from my perspective:

1. Do you using only GCC or some other compilers sets as well (like Solaris
Studio)?

Only GCC.

2. All sources from you project are written in the same language (compiled by
the same compiler)? I'm asking that as you can't use a C precompiled header for
a C++ compilation.

Not at the moment but it is feasible that someone would have C and C++ in one project. Is this technically not possible? 

3. It's OK for you to place precompiled header files to the directory with
headers or you expect them to be created in some other location?

Some other location -- preferably "pch\Debug" "pch\Release" folders under the same project root. PCH creation phase will generate plenty of files/subfolders within it but that's not a big deal -- they're all contained within the same "pch" folder.

4. Do you need to provide some additional compiler's options for headers
compilation?

No. But currently active compiler options should be used to create the pch's. If project compiler options change, all .pch files would need to be recreated.

5. Are you expecting all .pch files to be removed then you are doing clean of
the project or they should not be touched on cleaning?

Clean should remove .pch files. Keep in mind that a lot of source files refer to the same .h file, which is where pch comes in to reduce compilation time. So long as pch is generated prior to any build actions, total build time will be reduced (experience from other IDEs). In addition, we should only be doing clean minimally anyway.
Comment 9 igor_nikiforov 2012-08-30 14:30:51 UTC
Hello zachsaw,

Thanks for such a detailed answers to my questions.

Borland's (as I've seen it last time in C++Builder 6) as well as Microsoft VS's approaches uses the following
general idea: all includes you want to precompile should be somehow grouped together. Borland's approach uses
pragmas to separate headers, that should be precompiled, from ones that should not. In MSVS you should include
header to "special" header file, and in that case it will be precompiled. And this approach looks to be better when compiling
all the headers we have in project.

So It looks like the better way to have pre-compiled headers in you project is to create MSVS like "special" include file (one for
each compiler) and include all headers you want to precompile in it. And this "special" will be included into you sources
instead of these headers. After that you can make this file precompilable the way I've described in my comment above.

Such approach will provide you ability to use any compiler options you want while precompiling this header. And it also be
possible to separate headers that make sense to precompile from other ones.

Regards,
  Igor
Comment 10 kexik 2012-08-30 14:43:04 UTC
Apple Xcode has precompiled header implemented the same way as MSVC - one selected header pre-compiled into .pch file and then included into all other sources automatically.
Comment 11 igor_nikiforov 2012-09-04 13:12:16 UTC
Summing everything up here is steps how to use pre-compiled headers in NetBeans CND projects for GCC:
  1. Create header file and include all headers you want to precompile into it. Note: this file is compiler specific. This means that all C-headers should be included into file which will be precompiled by C-compiler.
  2. Replace includes in source files by include of this single header.
  3. Set it Command Line to header compile line and Outputs to <headername>.h.gch. Note: it's better place the precompiled header at the same directory as original headers.
  4. Add the following lines to .build-pre target in the Makefile (don't forget to replace <headername> by actual header name):
     @echo Pre-compiling headers
     @${MKDIR} -p ${CND_BUILDDIR}/${CONF}/${CND_PLATFORM_${CONF}}
     @${MAKE} -f nbproject/Makefile-${CONF}.mk <headername>.h.gch
  5. Clean and build project -> precompiled header will appear and will be used on next re-builds.

Here is an example how it works:
  1. Create Quote sample.
  2. Create precompiled.h in Header Files folder.
  3. Add all includes into it:
      #include <iostream>
      #include <cstdlib>
      #include <list>
      #include <assert.h>

      #include "cpu.h"
      #include "customer.h"
      #include "disk.h"
      #include "memory.h"
      #include "module.h"
      #include "system.h"
  4. All .cc files should include only precompiled.h.
  5. Set Custom Build Step properties of precompiled.h:
      Command Line: g++ -c -g -Wall -MMD -MP -MF ${OBJECTDIR}/precompiled.h.pch.d -o precompiled.h.gch precompiled.h
      Outputs: precompiled.h.gch
  6. Update Makefile (listed under Important Files):
      .build-pre:
          @echo Pre-compiling headers
          @${MKDIR} -p ${CND_BUILDDIR}/${CONF}/${CND_PLATFORM_${CONF}}
          @${MAKE} -f nbproject/Makefile-${CONF}.mk precompiled.h.gch
  7. Clean and Build Quote -> precompiled.h.gch  will appear near precompiled.h and will be used on next rebuilds.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo