Xcode: Unable to code sign when embeding a macOS framework inside two different bundles
I have project where I create a macOS framework and then embed the framework inside two different executable/bundles with code signing enabled. Configuring and generating is working with command cmake -G Xcode ..
. But when I build the project with
cmake --build . --config Debug
it's failing with error:
/usr/bin/codesign --force --sign XXXXXXXXXXXXXXXXX -o runtime --entitlements /Users/jcarl/devel/CMake_Embed_Sign_Framework/build/exe1/EmbedFrameworkTwice.build/Debug/exe1.build/Exe1.app.xcent --timestamp\=none /Users/jcarl/devel/CMake_Embed_
Sign_Framework/build/exe1/Debug/Exe1.app
/Users/jcarl/devel/CMake_Embed_Sign_Framework/build/exe1/Debug/Exe1.app: code object is not signed at all In subcomponent: /Users/jcarl/devel/CMake_Embed_Sign_Framework/build/exe1/Debug/Exe1.app/Contents/Frameworks/Fwk.framework
Command CodeSign failed with a nonzero exit code
It's randomly failing with one of my bundles.
I attached a project where you can reproduce the error. NOTE: A Apple Development Team ID has to be set in the main CMakeLists.txt.
I also dug a little bit into the generated Xcode project file to understand what maybe going wrong.
In the section PBXBuildFile
I see the framework
3686758ACF9F40438DA851F4 = {isa = PBXBuildFile; fileRef = 7B19B44200274907B37896E8 /* fwk */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy,CodeSignOnCopy); }; };
which then referenced twice in the section PBXCopyFilesBuildPhase
926C40A995274995A5E04088 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3686758ACF9F40438DA851F4,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
F06C43EF489147F8BA027FC0 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3686758ACF9F40438DA851F4,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
From my limited understand of Xcode it seems that Xcode gets upset if a PBXBuildFile referenced by two different PBXCopyFilesBuildPhase.