How to remove compile flags

I’m not sure how well whitelisting flags like that will work for me. If I’ve understood correctly, the process for removing a flag “foo” from the “frobnicator” target would be something like this:

  1. Remove foo from the flags that are applied to all targets (CMAKE_CXX_FLAGS at the moment, or the myflags INTERFACE in your example),
  2. Add the above generator expression for the foo flag,
  3. Add the needs_foo property to every target apart from frobnicator.

The trouble is my code base is very large, so step (3) would involve adding a property to thousands of targets. If we then ever wanted to re-instate the foo flag, we’d have to remove that property from thousands of targets.

Is there no blacklisting solution available? I’ve got a vague idea that we could write a function a bit like this, but it seems inelegant… I’m also not sure that CMAKE_CXX_FLAGS would actually populate those target properties.

function(remove_compiler_flag target flag)
  foreach(property IN COMPILE_DEFINITIONS COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS etc)
    # Get the target property
    # If the specified flag is in that list, remove it and re-set the target property
  endforeach()
endfunction()