Author Topic: Precompiled headers  (Read 3463 times)

Offline valkenar

  • Single posting newcomer
  • *
  • Posts: 7
Precompiled headers
« on: March 17, 2007, 05:28:47 pm »
Is it intentional that if the project is configured to compile a given header file that this header file will be compiled every build, whether or not it has changed? This seems to be the behavior, and I wasn't sure if this was intended behavior or whether I should report it as a bug.

This is relevant to me, because I use a custom build step that generates a cpp file, and it means that every build includes runnng the custom build step and also compiling the generated cpp files, even when they haven't changed.  Is there a workaround for this? 

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Precompiled headers
« Reply #1 on: March 17, 2007, 05:35:53 pm »
If an header is configured to be compiled then it will create PCH file for GCC. But it won't be compiled in every build unless you make some changes to it.

If the cpp file is changed, then it shouldn't compile the header file or other files unnecessarily. :)
Be a part of the solution, not a part of the problem.

Offline valkenar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Precompiled headers
« Reply #2 on: April 07, 2007, 01:32:16 am »
If an header is configured to be compiled then it will create PCH file for GCC. But it won't be compiled in every build unless you make some changes to it.

If the cpp file is changed, then it shouldn't compile the header file or other files unnecessarily. :)

This seems not to be true.  If I repeatedly build, I get this:
-
------------- Build: Debug in Program ---------------
Precompiling header: header1.h
Compiling: moc_header1.cpp
Linking console executable: bin\Debug\test.exe
Process terminated with status 0 (0 minutes, 4 seconds)
0 errors, 0 warnings

Every time I run a build.
 

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Precompiled headers
« Reply #3 on: April 07, 2007, 06:21:40 am »
My test results doesn't show that. ;)

Quote
-------------- Build: Release in Test ---------------
[ 20.0%] Precompiling header: wx_pch.h
[ 40.0%] Compiling: resource.rc
[ 60.0%] Compiling: TestMain.cpp
[ 80.0%] Compiling: TestApp.cpp
[100.0%] Linking executable: bin\Release\Test.exe
Process terminated with status 0 (0 minutes, 24 seconds)
0 errors, 0 warnings
 
-------------- Build: Release in Test ---------------
[ 50.0%] Compiling: TestApp.cpp  <-- Only this file was changed
[100.0%] Linking executable: bin\Release\Test.exe
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings

Your case may happen, if you Rebuild the project.

I agree that it's not perfect, but it works. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline Alturin

  • Multiple posting newcomer
  • *
  • Posts: 79
Re: Precompiled headers
« Reply #4 on: April 09, 2007, 04:21:40 pm »
Wouldn't that be because rebuild = clean+build, so it'd have to rebuild the header file cos it got cleaned?

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Precompiled headers
« Reply #5 on: April 09, 2007, 04:47:04 pm »
Wouldn't that be because rebuild = clean+build, so it'd have to rebuild the header file cos it got cleaned?

Yes.
Be a part of the solution, not a part of the problem.

Offline valkenar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Precompiled headers
« Reply #6 on: April 11, 2007, 05:03:21 pm »
Thank you having taken the time to look at it. I'm really not sure what the difference here is. I'm rather certain that I'm not rebuilding. I hit ctrl-f9 to start my builds, which is the hot-key listed next to the "build" menu item, first on the list in the build menu. Also, none of my other cpp files are being recompiled, just the one generated by the header-compilation step.

Remember, I'm using a custom build command here, not standard precompiled headers. The header file is configured to execute a custom command on compilation. What I'm trying to avoid is executing that command if the header file has not actually changed. If it's just some quirk in the way I've installed/configured codeblocks then I guess I'll just take another look around the options for something that would cause what I'm seeing.

As another data point, if I choose to compile (ctrl-shift-f9) a header file without a custom build parameter, it precompiles once, and then says "nothing to be done" on successive attempts. Whereas on my custom-command headers, it will display "precompiling header" every time.  Maybe I need to create a dummy pch as part of my custom step, so that codeblocks understands that the header has been compiled?

Offline valkenar

  • Single posting newcomer
  • *
  • Posts: 7
Re: Precompiled headers
« Reply #7 on: April 12, 2007, 07:12:08 pm »
Update:

I couldn't figure out how to prevent it from running the header precompilation step, so I just wrote a small utility called mocifnew which only executes the moc command if the source is older than the header.  This solves the problem, albeit inellegantly.