[cmake-developers] [CMake 0013567]: Add functionality to help users write precompiled header support

Mantis Bug Tracker mantis at public.kitware.com
Tue Oct 2 07:25:51 EDT 2012


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=13567 
====================================================================== 
Reported By:                JussiP
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   13567
Category:                   CMake
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2012-10-02 07:25 EDT
Last Modified:              2012-10-02 07:25 EDT
====================================================================== 
Summary:                    Add functionality to help users write precompiled
header support
Description: 
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.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2012-10-02 07:25 JussiP         New Issue                                    
======================================================================




More information about the cmake-developers mailing list