Search code examples
c++cmakeprecompiled-headers

Force CMake to rebuild precompiled headers


How do I get CMake to rebuild all the precompiled headers? (Using g++ and Linux) And how do I get CMake to disable all precompiled headers?

I am getting some build errors that have sprung up and they refer to the .ch files. So want to investigate whether this is due to precompiled headers.


Solution

  • In CMake, and assuming use of the target_precompile_headers() command, you can disable precompiled headers for a specific CMake target by setting the DISABLE_PRECOMPILE_HEADERS property:

    set_target_properties(MyTarget PROPERTIES 
        DISABLE_PRECOMPILE_HEADERS ON
    )
    

    or you can disable precompiled headers for the entire project by setting this in the top-level CMake file:

    set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
    

    To get CMake to rebuild all of the precompiled headers, you could simply delete those that have been generated, so they are re-generated.