<div class="gmail_quote">On Fri, May 18, 2012 at 12:07 PM, Bill Hoffman <span dir="ltr">&lt;<a href="mailto:bill.hoffman@kitware.com" target="_blank">bill.hoffman@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 5/18/2012 12:51 PM, Robert Dailey wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<br>
I certainly agree with all of your points but consider this. Even though<br>
PCH support may not exist on every compiler, every company that wants to<br>
add PCH support to CMake through scripting logic is essentially doing<br>
the same work over and over again. Everybody is going to do the same things:<br>
<br></div>
 1. Restrict the functionality to MSVC only via conditional branching<br>
 2. Call the same CMake commands to add the same compiler flag with the<div><div class="h5"><br>
    same parameters<br>
<br>
Just because every compiler doesn&#39;t support it doesn&#39;t mean CMake can&#39;t<br>
provide some way to eliminate the boilerplate. If we want to use PCH<br>
through CMake, there is certain logic that must exist. It&#39;s really just<br>
a question of WHERE that should exist: In CMake C++ code or in CMake as<br>
a script.<br>
<br>
What do we do if PCH support isn&#39;t provided by a compiler, but we have<br>
enabled it in our scripts? There are several things you can do, but what<br>
I commonly do is just ignore the request. For example, for all platforms<br>
I may invoke my custom function to enable PCH, but on the platforms that<br>
don&#39;t support it, it&#39;s just going to make sure that those files get<br>
compiled. Even if you don&#39;t enable PCH or can&#39;t use it, the PCH header<br>
file is still included in all CPP files that need includes from it, so<br>
the code will still compile. In this specific case, ignoring the request<br>
still works, and the user doesn&#39;t have to worry about the lack of the<br>
feature resulting in the build failing.<br>
<br>
You know all of this but the main point I wanted to make is that even<br>
though CMake can&#39;t guarantee PCH support on all platforms, it&#39;s still<br>
adding value by eliminating boilerplate. People won&#39;t be redundantly<br>
implementing and re-testing the same complex logic to add the feature in<br>
a modular way. Maybe a good middle ground would be to have a CMake built<br>
in module that provides &quot;convenience&quot; functions for operations like<br>
this. That way, CMake C++ code isn&#39;t changing, but we still give the<br>
users a subset of functionality to work with.<br>
<br>
Just a thought!<br>
</div></div></blockquote>
<br>
<br>
I agree, I hate to see code duplication. We do have a test to make sure it is possible that is run each night:<br>
<br>
Tests/PrecompiledHeader<br>
<br>
<br>
I have never used it, so I am not sure how hard it is.  I am thinking maybe the thing to do is create a module for each compiler that we add support for PCH.   Something like Modules/MSVCPCH.cmake.  Since it is so compiler specific.  Then the implementation would be in cmake code in a module and it will be clear that it is for one compiler. Perhaps you could generalize what you have already done into a module like this that could be included in CMake?</blockquote>
<div><br></div><div>I&#39;d be more than happy to do that, however my setup is a little different from what you&#39;re suggesting. I basically have something like this (pseudo code):</div><div><br></div><div>function( precompiled_headers )</div>
<div>  if( MSVC )</div><div>    ....</div><div>  elseif( GCC )</div><div>    ....</div><div>  else()</div><div>    # Not supported</div><div>  endif() </div><div>endfunction()</div><div><br></div><div>If you are wanting to split it out into separate modules, the logic above would be the responsibility of the client. In other words, CMake wouldn&#39;t help the user choose the right CMake PCH module depending on their target compiler. Am I misunderstanding your idea?</div>
</div>