How to get macOS/iOS framework root directory at install time?

Hi,

Let’s have a cross-platform command-line test application TestApp. This app depends on OpenCV, built as a dynamic framework on Apple. To install the app and runtime dependencies, I have:

install(TARGETS TestApp
        RUNTIME_DEPENDENCY_SET TestAppDeps
        DESTINATION "$<TARGET_FILE_DIR:TestApp>"
)

install(IMPORTED_RUNTIME_ARTIFACTS
        RUNTIME_DEPENDENCY_SET TestAppDeps
        DESTINATION "$<TARGET_FILE_DIR:TestApp>"
)

install(RUNTIME_DEPENDENCY_SET TestAppDeps
        DESTINATION "$<TARGET_FILE_DIR:TestApp>"
        PRE_EXCLUDE_REGEXES
                [=[api-ms-]=]
                [=[ext-ms-]=]
        POST_EXCLUDE_REGEXES
                [=[.*(\\|/)system32(\\|/).*\.dll]=]
                [=[^/(lib|usr/lib|usr/local/lib)]=]
                "$<TARGET_FILE_DIR:TestApp>"
        DIRECTORIES
                "$<TARGET_FILE_DIR:opencv_core>"
)

When running cmake install, I’m getting the following error:

CMake Error at TestApp/cmake_install.cmake:140 (file):
  file Could not resolve runtime dependencies:

    @rpath/opencv2.framework/Versions/4.0.1/opencv2

Looking at TestApp/cmake_install.cmake, I can see that the opencv_core target directory is obviously “too deep” into the opencv2.framework directory structure:

  elseif(CMAKE_INSTALL_CONFIG_NAME MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$")
    file(GET_RUNTIME_DEPENDENCIES 
      RESOLVED_DEPENDENCIES_VAR _CMAKE_DEPS
      EXECUTABLES
        "/Users/<user>/Documents/TestApp/build_arm64_osx/TestApp/Release/TestApp"
      DIRECTORIES
        "/Users/<user>/Documents/Dependencies/macOS/arm64/OpenCV_4.0.1/lib/3rdparty/opencv2.framework/Versions/4.0.1"
      PRE_EXCLUDE_REGEXES
        "api-ms-"
        "ext-ms-"
      POST_EXCLUDE_REGEXES
        ".*(\\\\|/)system32(\\\\|/).*\\.dll"
        "^/(lib|usr/lib|usr/local/lib)"
        "/Users/<user>/Documents/TestApp/build_arm64_osx/TestApp/Release"
      )

Is there a target or framework property, defining the root path of the framework, that I should use to give the DIRECTORIES argument the correct search path? In the above example, it should be two levels upper, i.e. omitting the Versions/4.0.1 part of the path.

Thanks.

So the problem isn’t with the recorded framework path, it appears. Even hardcoding the correct path doesn’t fix this issue.

The problem seems to reside in the inability of GET_RUNTIME_DEPENDENCIES to retrieve the path of the opencv2 framework.