6

I'm using cotire(https://github.com/sakra/cotire) plugin for CMake, which handles several nice things related to compilation speedup(for example precompiled headers).

The problem is that I include several headers (Boost related or Protobuf) as system ones - in which warnings are disabled. After they are being precompiled I've got a lot of warnings.

Can I disable warnings in precompiled headers?

Dejwi
  • 4,393
  • 12
  • 45
  • 74
  • 1
    With [cotire 1.6](https://github.com/sakra/cotire) warnings in precompiled headers are suppressed. – sakra Mar 16 '14 at 14:48
  • CMake 3.16 introduced native support for precompiled headers. Have a look for target_precompile_headers. You might be able to get rid of cotire. – usr1234567 Dec 28 '19 at 19:11

1 Answers1

1

I don't think there's a built in way to do this, we modified the cotire function cotire_add_pch_compilation_flags (line 1244 cotire.cmake version 1.5.1) to add the "-w" flag when compiling the precompiled header. We changed the GNU|CLang section to read

elseif (_compilerID MATCHES "GNU|Clang")
        # GCC / Clang options used
        # -x specify the source language
        # -c compile but do not link
        # -o place output in file
        set (_xLanguage_C "c-header")
        set (_xLanguage_CXX "c++-header")
        if (_flags)
            # append to list
            list (APPEND _flags "-x" "${_xLanguage_${_language}}" "-w" "-c" "${_prefixFile}" -o "${_pchFile}")
        else()
            # return as a flag string
            set (_flags "-x ${_xLanguage_${_language}} -w -c \"${_prefixFile}\" -o \"${_pchFile}\"")
        endif()

This suppresses all warnings for us, we have a lot of warnings turned on - including -Werror, so it was an essential change!

Adam Bowen
  • 10,820
  • 6
  • 36
  • 41