macOS: sign/package a Framework and a Bundle which embeddes that Framework

I have project with a macOS Framework and Bundle: The framework is consumed by the app/bundle by embedding it. I also want to create two package: One is the Framework as SDK and one is the App/Bundle with the embedded Framework. I followed the examples in the book “Professional CMake: A Practical Guide” how to create the Framework and Bundle, how to embed it, etc

Without signing everything works a expected: I see two packages created as dmg.
When I enable signing for both (the framework and the bundle) I getting an error

code object is not signed at all

This is what I tried so far.

add_library(MyFwk SHARED ...)

set_target_properties(MyFwk PROPERTIES
  FRAMEWORK TRUE
  INSTALL_RPATH @loader_path/../../..
  XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED TRUE
  ...
)

install(TARGETS MyFwk
  EXPORT MyFwkSDK
  INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  FRAMEWORK
    DESTINATION "."
    COMPONENT sdk
)

add_executable(MyApp MACOSX_BUNDLE ...)

set_target_properties(MyApp PROPERTIES
  INSTALL_RPATH @executable_path/../Frameworks
  XCODE_ATTRIBUTE_SIGNING_ALLOWED TRUE
  XCODE_ATTRIBUTE_SKIP_INSTALL NO
  XCODE_EMBED_FRAMEWORKS MyFwk
  XCODE_EMBED_FRAMEWORKS_SIGN_ON_COPY TRUE
)

target_link_libraries(MyApp PRIVATE MyFwk)

install(TARGETS MyApp
  BUNDLE
    DESTINATION "."
    COMPONENT app
  FRAMEWORK
    DESTINATION MyApp.app/Contents/Frameworks
    COMPONENT app
)

set(CPACK_GENERATOR DragNDrop)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
include(CPack)

I use CMake 3.32.1 and Xcode 12.4 (12D4e).
How do I achieve that both package are signed?

That version doesn’t exist. Did you mean 3.23.1 or 3.22.1?

What CMake generator are you using (hopefully the Xcode generator)?

What command line(s) are you using to do the build?

What command line(s) are you using to create the package(s)?

Sorry I mistyped: I use 3.23.1 and the Xcode generator.

I use these steps to build and create the package:

# mkdir build; cd build
# cmake -G Xcode ..
# cmake --build . --config RelWithDebInfo --target package