[CMake] Secret precompiled header support?

Robert Dailey rcdailey.lists at gmail.com
Mon May 14 18:17:51 EDT 2012


On Mon, May 14, 2012 at 4:58 PM, Bill Hoffman <bill.hoffman at kitware.com>wrote:
>
> 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... :)
>
> All it knows is that flat /Foobar == "Turn on option foobar" and creates
> the right xml or project input file.


Thanks for the explanation.

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.

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?

Is improvement desired in this area? Is the current implementation really
satisfactory? It doesn't exactly offer an intuitive or maintainable
solution.

Here is what I have to do right now to enable precompiled headers on MSVC:

macro( _precompiled_headers PrecompiledHeader PrecompiledSource SourcesVar )
if( MSVC )
get_filename_component( PrecompiledBasename ${PrecompiledHeader} NAME_WE )
set( PrecompiledBinary
"${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch" )
set( Sources ${${SourcesVar}} )

set_property(
SOURCE ${PrecompiledSource} APPEND_STRING PROPERTY
COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\" "
)

set_property(
SOURCE ${PrecompiledSource} APPEND PROPERTY
OBJECT_OUTPUTS "${PrecompiledBinary}"
)
 set_property(
SOURCE ${Sources} APPEND_STRING PROPERTY
COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\" "
)
 set_property(
SOURCE ${Sources} APPEND PROPERTY
OBJECT_DEPENDS "${PrecompiledBinary}"
)
else()
message( "Precompiled header support not provided for this platform" )
endif()
 # Add precompiled header to SourcesVar
list( APPEND ${SourcesVar} ${PrecompiledSource} )
endmacro()

I feel like CMake should offer me a higher-level way of dealing with this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120514/d3394363/attachment-0001.htm>


More information about the CMake mailing list