CMAKE_{C/CXX}_FLAGS affects all targets in LLVM. This is
undesirable in situations where we do not want to apply
every optimization flag to every target for faster build speeds.
For example, we can selectively apply -flto=thin flags to
binaries that we care about optimizing and keep other tools
in the distribution on the non-optimized version. The pattern
follows a similar approach to how multi-distributions are created.
The example of the thinLTO above can be done by doing the
following:
set(LLVM_CUSTOM_BINARIES clang lld CACHE STRING "List of targets to apply custom flags") set(LLVM_clang_COMPILER_FLAGS -flto=thin CACHE STRING "Custom compiler flags to clang") set(LLVM_lld_COMPILER_FLAGS -flto=thin CACHE STRING "Custom compiler flags to lld")
There's probably other applications where this could be used
(e.g. avoid optimizing host tools for build speed improvement etc.).
I've generalized this so that users can apply their desired flags to
targets that are generated by llvm_add_library and add_llvm_executable.