<div class="gmail_quote">On Mon, May 14, 2012 at 4:58 PM, Bill Hoffman <span dir="ltr"><<a href="mailto:bill.hoffman@kitware.com" target="_blank">bill.hoffman@kitware.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For those we hard coded many of the flags into a table. So, basically for VS greater than 6, we have a table that maps flags to actual options in the IDE. There is no special per-compiled support in CMake... :)<br>
<br>
All it knows is that flat /Foobar == "Turn on option foobar" and creates the right xml or project input file.</blockquote><div><br></div>Thanks for the explanation.<div><br></div><div>It would be nice to have target properties for these, instead of this obscure mapping. It makes it difficult to figure out how exactly to append compiler flags. For example, I'm using set_property() with APPEND_STRING, and I have to make sure my spacing is correct each time I enable a compiler-specific feature using compiler flags. I had to use trial & error to determine that APPEND_STRINGS worked, but APPEND didn't for COMPILE_FLAGS. There's a lot of boilerplate logic that I have to deal with when using set_property with COMPILE_FLAGS. </div>
<div><br></div><div>It would be much easier to specify some target properties instead. Or maybe to simplify things, we can have a compiler_flags() command that simplifies doing this work, if it is undesirable to have new target properties?</div>
<div><br></div><div>Is improvement desired in this area? Is the current implementation really satisfactory? It doesn't exactly offer an intuitive or maintainable solution.</div><div><br></div><div>Here is what I have to do right now to enable precompiled headers on MSVC:</div>
<div><br></div><div><div>macro( _precompiled_headers PrecompiledHeader PrecompiledSource SourcesVar )</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if( MSVC )</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>get_filename_component( PrecompiledBasename ${PrecompiledHeader} NAME_WE )</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>set( PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch" )</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set( Sources ${${SourcesVar}} )</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${PrecompiledSource} APPEND_STRING PROPERTY</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\" "</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${PrecompiledSource} APPEND PROPERTY</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>OBJECT_OUTPUTS "${PrecompiledBinary}"</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${Sources} APPEND_STRING PROPERTY</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\" "</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${Sources} APPEND PROPERTY</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>OBJECT_DEPENDS "${PrecompiledBinary}"</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>else()</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>message( "Precompiled header support not provided for this platform" )</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>endif()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># Add precompiled header to SourcesVar</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>list( APPEND ${SourcesVar} ${PrecompiledSource} )</div><div>endmacro()</div></div><div><br></div><div>I feel like CMake should offer me a higher-level way of dealing with this. </div>
</div>