Official support for precompiled headers

General questions regarding the usage of CodeLite
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Official support for precompiled headers

Post by marfi »

Hi Eran,
the only thing I miss in CL and which would make me definitely happy with this GREAT IDE is 'official' support for precompiled headers. I know that they can be created via 'Custom makefile steps' dialog, but it would be nice to have some more user-friendly way how to do it. Moreover, I'm afraid that current approach have at least one serious drawback: if concurrent build is used (for example 8 files at the same time on my 8-core workstation ;) ) then the first parallel build stage can produce compiler's warnings/errors because the PCH file is not fully completed yet. In my opinion the PCH file should be created separately before some 'barrier' and processing of the rest project files should be started after that. What do you think about it?

Regards
Michal
User avatar
eranif
CodeLite Plugin
Posts: 6372
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Official support for precompiled headers

Post by eranif »

marfi wrote:I'm afraid that current approach have at least one serious drawback:
Not really. The current build system is using the 'QueueCommand' class. We can create new command 'PreCompiledHeaderCommand' and push it *brefore* the 'Build' command so it will be processed before. We can also set the m_checkBuildSuccess for the build request to true so it wont be processed if the PHC compilation fails.

Currently, the utilization of the #processors is done by the make file -j option, but from codelite point of view, its a single command - so I dont see any drawback here ;)

Eran
Make sure you have read the HOW TO POST thread
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Re: Official support for precompiled headers

Post by marfi »

Just little clarification: the compiler warning mentioned above (something like "xyz.gch file is too short to be precompiled header") disappeared after project cleanup so now works even rebuild flawlessly. Only tiny 'problem' that remains is that 'Clean' command doesn't remove *.gch file which situation has pros as well as cons: advantage is that after rebuild command I haven't to wait for new PCH file creation, but if the precompiled code changes then I must remove this file manually.

Regards
Michal
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Re: Official support for precompiled headers

Post by marfi »

Hi Eran,
are you sure that 'custom makefile steps' are really performed before compilation of all other project files? See the output of compiler bellow:

Code: Select all

----------Build Started--------
"make"  -j 2 -f "Src_wsp.mk"
----------Building project:[ GizmoTest1 - Release ]----------
g++ wx_pch.h -O2 -Winvalid-pch -include wx_pch.h -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread -D__WX__ -DWX_PRECOMP  "-I." 
g++ -c  "/home/michal/Src/GizmoTest1/gizmotest1_app.cpp" -O2 -Winvalid-pch -include wx_pch.h -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread -D__WX__ -DWX_PRECOMP  -o ./Release/gizmotest1_app.o "-I." 
cc1plus: warning: ./wx_pch.h.gch: not a PCH file
g++ -c  "/home/michal/Src/GizmoTest1/gui.cpp" -O2 -Winvalid-pch -include wx_pch.h -I/usr/lib/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread -D__WX__ -DWX_PRECOMP  -o ./Release/gui.o "-I." 
cc1plus: warning: ./wx_pch.h.gch: not a PCH file
g++ -o ./Release/GizmoTest1 ./Release/gizmotest1_app.o ./Release/gui.o  "-L."   -s -pthread -Wl,-Bsymbolic-functions  -lwx_gtk2u_richtext-2.8 -lwx_gtk2u_aui-2.8 -lwx_gtk2u_xrc-2.8 -lwx_gtk2u_qa-2.8 -lwx_gtk2u_html-2.8 -lwx_gtk2u_adv-2.8 -lwx_gtk2u_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8  
----------Build Ended----------
0 errors, 0 warnings
This output is shown during first project build when the PCH file doesn't exist yet. Although the PCH file is really processed as the first file, the other files cannot use it, because it isn't probably fully created yet. All next project builds/rebuilds work fine if the PCH file already exists.

Best regards
Michal
User avatar
eranif
CodeLite Plugin
Posts: 6372
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Official support for precompiled headers

Post by eranif »

marfi wrote:are you sure that 'custom makefile steps' are really performed before compilation of all other project files?
The custom makefile steps are part of a project, and not the workspace. So if a project has a 'custom makefile steps' they will be executed before that project compilation and the workspace.

I will be starting working on the PCH thing any time now.

Eran
Make sure you have read the HOW TO POST thread
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Re: Official support for precompiled headers

Post by marfi »

The custom makefile steps are part of a project, and not the workspace.
I know, I used wrong words :) I meant 'files included in a project'.
I will be starting working on the PCH thing any time now.
Nice to hear about it! I'm looking forward.

Best regards
Michal
User avatar
eranif
CodeLite Plugin
Posts: 6372
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Official support for precompiled headers

Post by eranif »

How did you set your 'custom makefile steps' to include PCH file?

Eran
Make sure you have read the HOW TO POST thread
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Re: Official support for precompiled headers

Post by marfi »

It is not set in 'custom makefile steps' but in compiler options. Just use this flags:

Code: Select all

-Winvalid-pch;-include wx_pch.h;
where "wx_pch.h" is header file neme used in 'custom makefile steps'. If you want to use precompiled headers with wxWidgets then you have to also set WX_PRECOMP symbol in preprocessor definitions. My PCH file looks like this:

Code: Select all

#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED

#ifdef _DISWARNINGS_MSVC
#pragma warning( disable : 4100 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4275 )
#endif

// basic wxWidgets headers
#include <wx/wxprec.h>

// debug memory allocation enhancement (MS VC only)
#ifdef _DEBUG_MSVC
#ifdef _DEBUG
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#endif

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
	#include <wx/wx.h>
#endif

#ifdef WX_PRECOMP
	// put here all your rarely-changing header files
#endif // WX_PRECOMP

#endif // WX_PCH_H_INCLUDED
Regards
Michal
User avatar
eranif
CodeLite Plugin
Posts: 6372
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Official support for precompiled headers

Post by eranif »

I understand that, but you need to have wx_prec.h.gch to actually have it, no?

The wx_prec.h must be compiled to create wx_prec.h.gch

How did you do that, or did the WX makefile already provides that for you?

Eran
Make sure you have read the HOW TO POST thread
marfi
CodeLite Expert
Posts: 159
Joined: Mon Nov 03, 2008 9:17 pm
Contact:

Re: Official support for precompiled headers

Post by marfi »

I use the way I've found somewhere in this forum. I've inserted
wx_pch.h.gch
into "Dependecies" field and
wx_pch.h.gch: wx_pch.h
<TAB>$(CompilerName) wx_pch.h $(CmpOptions) $(IncludePath)
into "Rule action" (the second line must be indented by tab).

Regards
M.
Post Reply