Author Topic: Enable the PCH when build C::B against wx3.x  (Read 479 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5029
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Enable the PCH when build C::B against wx3.x
« on: February 28, 2018, 02:50:37 am »
The PCH file is normally larger in wx3.x version than wx2.x. I think for historical reasons: For example, old windows GCC(such as tdm gcc 5.1) does not handle a PCH file size which is larger than 128M. But some newer windows GCC(such as GCC from mingw-w64 site) suite already has a patch to fix this issue. The PCH issue of Windows GCC is fixed for more than two years.

I personally have this patch in my local copy for quite a long time:
Code: [Select]
src/CodeBlocks_wx31.cbp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/CodeBlocks_wx31.cbp b/src/CodeBlocks_wx31.cbp
index 51dacc95..9f164270 100644
--- a/src/CodeBlocks_wx31.cbp
+++ b/src/CodeBlocks_wx31.cbp
@@ -715,12 +715,13 @@
  <Add option="-mthreads" />
  <Add option="-fmessage-length=0" />
  <Add option="-fexceptions" />
+ <Add option="-Winvalid-pch" />
  <Add option="-std=gnu++11" />
  <Add option="-DHAVE_W32API_H" />
  <Add option="-D__WXMSW__" />
  <Add option="-DWXUSINGDLL" />
  <Add option="-DcbDEBUG" />
- <Add option="-DNOPCH" />
+ <Add option="-DCB_PRECOMP" />
  <Add option="-DwxUSE_UNICODE" />
  <Add directory="$(#WX31.include)" />
  <Add directory="$(#WX31.lib)/gcc_dll$(WX_CFG)/msw$(WX_SUFFIX)" />
@@ -1256,6 +1257,7 @@
  <Option target="sdk" />
  </Unit>
  <Unit filename="include/sdk.h">
+ <Option compile="1" />
  <Option weight="1" />
  <Option target="src" />
  </Unit>
@@ -1266,6 +1268,7 @@
  <Option target="sdk" />
  </Unit>
  <Unit filename="include/sdk_precomp.h">
+ <Option compile="1" />
  <Option weight="0" />
  <Option target="sdk" />
  </Unit>

Today, I did some tests:
I use MinGW-W64 mingw-build gcc 7.2 32bit compiler, wx3.1.1-rc and build CodeBlocks_wx31.cbp with PCH enabled and not.

With out PCH enabled, it takes:
Code: [Select]
Process terminated with status 0 (12 minute(s), 21 second(s))
0 error(s), 4 warning(s) (12 minute(s), 21 second(s))

With PCH enabled, it takes:
Code: [Select]
Process terminated with status 0 (5 minute(s), 51 second(s))
0 error(s), 4 warning(s) (5 minute(s), 51 second(s))

So, it is more than 50% build time saved.  :)

This is done in my Windows 7 64bit system.

Any objections?

BTW: another patch is need to build cb against wx3.1.1, see: UXTheme error when compiling with wxWidgets 3.1.1

« Last Edit: February 28, 2018, 02:55:00 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline BlueHazzard

  • Lives here!
  • ****
  • Posts: 1872
Re: Enable the PCH when build C::B against wx3.x
« Reply #1 on: March 01, 2018, 09:54:32 pm »
This would break compilation with compiler prior 7.XX on windows?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6239
    • My Best Post
Re: Enable the PCH when build C::B against wx3.x
« Reply #2 on: March 01, 2018, 09:57:12 pm »
This would break compilation with compiler prior 7.XX on windows?

Only with a few 5.xx compilers; I forgot the exact version numbers that has the bug.
Edit: It might even have been 4.xx compilers that had the bug.
Edit2: The bug was in MinGW GCC 4.8; started in one of the last MinGW GCC 4.7.x builds.
I believe it was fixed in the 5.xx compilers.

Tim S.
« Last Edit: March 01, 2018, 10:09:53 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5029
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Enable the PCH when build C::B against wx3.x
« Reply #3 on: March 02, 2018, 02:32:08 am »
This would break compilation with compiler prior 7.XX on windows?
Hi, you can see my answers here for details https://stackoverflow.com/questions/10841306/cc1plus-exe-crash-when-using-large-precompiled-header-file/19372020#19372020

It is in year 2015.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5029
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Enable the PCH when build C::B against wx3.x
« Reply #4 on: May 12, 2018, 08:03:06 am »
FYI: I commit the patch in r11401.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.