Direct support for enabling bitcode on Apple platforms
Enabling bitcode for Apple platforms is problematic (for example, see #23390 (closed), #22961). We currently hard-code adding -Wl,-headerpad_max_install_names
to linker flags on Apple platforms, but this conflicts with options like -fembed-bitcode
, -fembed-bitcode-marker
or -bitcode_bundle
. The linker emits a warning that it will ignore -headerpad_max_install_names
when any of those other flags are also given. This in turn defeats logic in the various CheckXXXCompilerFlags
and CheckLinkerFlags
modules, which relies on compile and link being warning-free.
Because CMake is forcing the -Wl,-headerpad_max_install_names
flag onto projects, it is very difficult for them to engineer an arrangement that works with bitcode enabled. CMake should provide direct support for enabling bitcode and it should then not add -Wl,-headerpad_max_install_names
if it will conflict.
As additional info, the relevant project setting for Xcode is ENABLE_BITCODE
. When building directly, that will result in -fembed-bitcode-marker
being added, while for an Archive operation, it will add -fembed-bitcode
instead (see this thread in the Apple developer forums for useful information). If the user wants to force using -fembed-bitcode
for regular builds instead of -fembed-bitcode-marker
, the linked discussion provides a couple of ways they can do that (i.e. the DEPLOYMENT_PROCESSING
or BITCODE_GENERATION_MODE
settings). It is debatable whether we want to support that secondary configurability, supporting just ENABLE_BITCODE
might be enough. However, for other generators, we would have to pick which flag to add (-fembed-bitcode
or -fembed-bitcode-marker
), so we might end up needing to add that secondary support anyway in order to provide the required flexibility for them.