how to enable exceptions for one component

LLVM_ENABLE_EH is a global option, not a target property. For a single target, it’s more appropriate to use LLVM_REQUIRES_EH, which is also a variable you’ll need to set before calling add_llvm_component_library. You can do something like

set(LLVM_REQUIRES_EH_ORIGINAL ${LLVM_REQUIRES_EH})

set(LLVM_REQUIRES_EH YES)

add_llvm_component_library(LLVMTargetLibrary

TargetFile1.cpp

TargetFile2.cpp

)

set(LLVM_REQUIRES_EH ${LLVM_REQUIRES_EH_ORIGINAL})

The implementation for this functionality lives in llvm/cmake/modules/AddLLVM.cmake [1], where you can see what effect LLVM_REQUIRES_EH has.

[1] https://github.com/llvm/llvm-project/blob/master/llvm/cmake/modules/AddLLVM.cmake

Perfect, thanks.

For the record, I had to also set/reset LLVM_REQUIRES_RTTI in the same way.