Description | The example below goes to CMAKE_CXX_FLAGS_DEBUG, however the report covers all flags which have CMAKE_BUILD_TYPE-dependent counterparts (e.g. CMAKE_{C,CXX,LINK,...}_FLAGS_*)
Currently, CMAKE_CXX_FLAGS_DEBUG goes to compiler flags after CMAKE_CXX_FLAGS. This is inconvenient, as it does not allow user to override project-set flags with flags suitable for local environment. For example, FreeBSD ports collection has a policy of enforcing systemwide optimization (-Ox) flags on all port builds. These flags are passed via CMAKE_CC_FLAGS/CMAKE_CXX_FLAGS, but when BUILD_TYPE is used (it is) they do not override project-set flags, which is undesirable. The only ways to fix this are either to not use CMAKE_BUILD_TYPE (which is not acceptable as build-type specific flags may contain critical features, e.g. -DNDEBUG which may severely affect performance and program bahavior) or patch CMakeLists.txt to remove unwanted vendor's flags (not very nice either).
Placing CMAKE_*_FLAGS _after_ CMAKE_*_FLAGS_* will allow gracefully overriding of needed flags so that is what I propose. |