How to name package based on target architecture on macOS?

Hi!

I want to name my macOS package according to the target architecture(s) that CMake is going to build.
How do I do that? Which variables do I need to query? E.g. CMAKE_OSX_ARCHITECTURES might not necessarily be set, right?

The outcome I want to have is:
x86_64 → Intel
aarch64 → Silicon
x86_64, aarch64 → Universal

Thanks a lot for any hints!

CMAKE_OSX_ARCHITECTURES is the first place I’d look. Other than that, I think CMAKE_SYSTEM_PROCESSOR is likely to be useful.

I don’t tend to trust CMAKE_SYSTEM_PROCESSOR for anything important unless I know that the project I’m using it with explicitly sets it. There’s no standard set of values for it, and the toolchain file the developer uses can set it to any arbitrary value. The CMAKE_OSX_ARCHITECTURES variable should be more reliable and I think better reflects the information you are trying to capture.

Thank you! The problem that I have with CMAKE_OSX_ARCHITECTURES is that it does not need to be set, right (i.e. it’s optional)?
How would I get its defaults (i.e. probably the host architecture in the same format, right?) in case it is not set.

I think cmake_host_system_information may be useful here.