Hi all,
In the codebase in which I’m currently working, there are two scenarios where I might want to remove compile flags from a target:
- Some targets want almost all the compile flags given by CMAKE_CXX_FLAGS and friends. However, I need to remove or disable certain flags for those targets,
- Some targets require their own entirely custom set of build flags, and don’t want to use CMAKE_CXX_FLAGS (and friends) at all.
For (1), the best idea I have is to get CMAKE_CXX_FLAGS and friends, manually remove the flags I don’t want, and re-set those variables on a directory level. This is cumbersome, because the number of flags that need to be changed increases linearly with the number of CMAKE_BUILD_TYPEs. It’s also prone to break in future when new build types are added. Is there a cleaner way to achieve this?
(Side note - the scoping rules are also not clear to me. If I set CMAKE_CXX_FLAGS as a non-cache variable, does it apply to all targets in the current directory and below? If I have two targets in the same directory, declare one, then change CMAKE_CXX_FLAGS and declare the other, are my new CMAKE_CXX_FLAGS applied to just the second target?).
For (2) the same work-around applies, but I wonder if there’s some way to entirely exclude a target from CMAKE_CXX_FLAGS, CMAKE_BUILD_TYPE, etc.?
Thanks,
Tom