MantisBT - CMake
View Issue Details
0013567CMakeCMakepublic2012-10-02 07:252013-03-04 08:38
JussiP 
 
normalfeaturealways
closedduplicate 
LinuxLinuxAny
CMake 2.8.9 
 
0013567: Add functionality to help users write precompiled header support
This bug is not a request for general precompiled header support, but rather a request for some additional functionality to make writing that support easier.

To use precompiled headers with gcc, they must be compiled like this:

g++ [every single flag and option that would be given to source files] header.h -o header.h.gch

Those flags include stuff like -fPIC, -D flags and so on. If any one of them is missing, the produced file will not work.

Currently in CMake this list of flags is really hard to get to. There are two choices that I can see.

1) add a function to CMake that gives all command line switches for a given target. Then it could be used to build the pch like this

-----

get_all_switches_for_target(switches targetname)
list(APPEND switches ${pch_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${pch_file}.gch)
add_custom_command(...

-----

2) If you add the header to the list of source files and then do this:

set_property(SOURCE precompiled.h PROPERTY LANGUAGE CXX)

then CMake will build the pch correctly, but it will be called precompiled.o. GCC will not use it in this case. If there were an additional property which would allow the user to set the output file name (and tell CMake not to link the resulting object file in the target), then the pch could be generated and used easily.

The difference between the two is that the latter would automatically be part of dependency tracking. This is only an issue if you want to precompile your own headers. Most projects only use precompiled headers for system headers, such as STL, Boost and Qt.
No tags attached.
duplicate of 0001260closed Kitware Robot Support for precompiled headers 
Issue History
2012-10-02 07:25JussiPNew Issue
2012-10-02 08:01Brad KingRelationship addedduplicate of 0001260
2012-10-02 08:02Brad KingNote Added: 0031148
2012-10-02 08:02Brad KingStatusnew => resolved
2012-10-02 08:02Brad KingResolutionopen => duplicate
2013-03-04 08:38Robert MaynardNote Added: 0032464
2013-03-04 08:38Robert MaynardStatusresolved => closed

Notes
(0031148)
Brad King   
2012-10-02 08:02   
All PCH discussion is in issue 0001260.
(0032464)
Robert Maynard   
2013-03-04 08:38   
Closing resolved issues that have not been updated in more than 4 months.