如何使用fixup_bundle将库添加到OSX上的框架?

时间:2017-01-24 13:29:38

标签: macos cmake frameworks rpath

我已经使用CMake在OSX上创建了一个框架,但框架动态地与libusb链接。如何使用fixup_bundle()或其他内容将libusb.dylib复制到框架包中,并修复我的库rpath,使其指向框架,而不是绝对路径我建造的libusb

1 个答案:

答案 0 :(得分:0)

修复rpath相对容易:

set_target_properties(mylib PROPERTIES
    # Build a framework on OSX.
    FRAMEWORK TRUE
    # Add a relative path for dependencies to the rpath of mylib (when installed).
    INSTALL_RPATH "@loader_path"
    # But also use the INSTALL_RPATH anyway in the build tree, before it is installed.
    BUILD_WITH_INSTALL_RPATH TRUE
)

但是这并没有将依赖项复制到框架中。我是手动完成的:

# Copy libfoo into the bundle.
if (APPLE)
    add_custom_command(TARGET mylib POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:libfoo>" "$<TARGET_FILE_DIR:mylib>"
        COMMENT "Bundling libfoo"
        VERBATIM
    )
endif ()