In building a framework for use in an mac/tv/iOS project I decided to build a framework and include bitcode, just in case. However, my output framework doesn't contain bitcode.
I can see -fembed-bitcode
is being called on each source file but when I check the .dylib
with otool -l library.dylib
there are no __LLVM
sections. Switching to creating a static library I can see the __LLVM
sections.
Why isn't cmake correctly building the library?
In order to correctly build the dynamic library whether in a framework or not you need to look at the last line of output from cmake. There you'll see clang
called with all the .o
files and the output file being the .dylib
. This line is missing -fembed-bitcode
and when linking the library you need to again pass the -fembed-bitcode
flag.
So by adding the flag to the compile target and library linking correctly adds bitcode.
target_compile_options( library PUBLIC -fembed-bitcode )
target_link_options( library PUBLIC -fembed-bitcode )