This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Support per-target compiler and linker flags
AbandonedPublic

Authored by thevinster on Jul 24 2023, 3:54 PM.

Details

Reviewers
phosek
smeenai
Summary

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.

Diff Detail

Event Timeline

thevinster created this revision.Jul 24 2023, 3:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 3:54 PM
Herald added a subscriber: ekilmer. · View Herald Transcript
thevinster retitled this revision from [CMake] Support per-binary custom compiler/linker flags to [CMake] Support per-target compiler and linker flags.Jul 24 2023, 4:27 PM
thevinster edited the summary of this revision. (Show Details)
thevinster added reviewers: phosek, smeenai.
thevinster published this revision for review.Jul 24 2023, 4:30 PM

Would love to get some feedback whether there's interest in this or if there's a better way to solve the build speed issue.

Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 4:30 PM
thevinster abandoned this revision.Oct 4 2023, 6:22 PM

Will resubmit on Github along with more testing results.