'Signing a MacOS Framework using CMake

I'm developing a C/C++ library that will be distributed as a Framework for apple architectures, but I'm having trouble getting CMake to sign my binaries for notarization/distribution.

What are the best practices for codesigning a Framework using CMake?

Since the library will support multiple platforms, I want to use my existing conan/cmake build system instead of maintaining separate Xcode project files specifically for apple. Ideally, I'd like to do codesigning as part of the build, so conan will automatically package up the signed Framework.

Based on the CMake FRAMEWORK documentation and other questions I've dug up on the subject, it seems CMake should sign my output bundle as long as XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY and XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED are set, but that's not the experience I'm having. My CMake output doesn't mention code signing, and after building/packaging a quick codesign verification shows that codesigning didn't happen:

codesign -v build/package/HelloWorld.framework

build/package/HelloWorld.framework: code object is not signed at all
In architecture: x86_64

The target properties for my framework are set up as follows:

set_target_properties(${TARGET_NAME} PROPERTIES
    OUTPUT_NAME ${TARGET_NAME}
    PUBLIC_HEADER "${PUB_INCLUDES}")
if((CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") AND BUILD_SHARED_LIBS)
    set_target_properties(${TARGET_NAME} PROPERTIES
        FRAMEWORK TRUE
        FRAMEWORK_VERSION C
        MACOSX_FRAMEWORK_IDENTIFIER "com.example.project"
        XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED ${APPLE_SIGN_BINARIES}
        XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${APPLE_CERT_IDENTIFIER}"
        XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "XXXXX")
endif()

I'm generally using APPLE_CERT_IDENTIFIER = "Developer ID", but I've also tried with various other Developer and Distribution certs, including trying their full name (ie "Developer ID Applicaton: Devname (hex code)"). Setting CODE_SIGNING_REQUIRED to TRUE, YES, or eliminating it altogether doesn't seem to make a difference.

I'm also aware of a bundle generator for CPack. I haven't tried this route yet since at first glance it seems more tailored for installer packages and complete apps instead of individual frameworks. Is this something I should be pursuing instead of the FRAMEWORK target properties above?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source