file(GET_RUNTIME_DEPENDENCIES) need a way to know whether the dependencies is a framework or not
When runtime dependencies are normal dylibs, the below example works properly:
add_library(Foo SHARED foo.cpp foo.h)
add_executable(Main main.cpp)
target_link_libraries(Main Foo)
set_target_properties(Main PROPERTIES INSTALL_RPATH "@executable_path")
install(TARGETS Main RUNTIME DESTINATION bin)
install(
CODE "file(GET_RUNTIME_DEPENDENCIES EXECUTABLES \$<TARGET_FILE:Main> RESOLVED_DEPENDENCIES_VAR DEPS)\n \"
foreach(DEP \${DEPS})\n \
file(INSTALL \${DEPS} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)\n \
endforeach()")
However, if the runtime dependent library is a framework it won't work, for example
add_library(Foo SHARED foo.cpp foo.h)
set_target_properties(Foo PROPERTIES FRAMEWORK TRUE PUBLIC_HEADER "foo.h")
add_executable(Main main.cpp)
target_link_libraries(Main Foo)
set_target_properties(Main PROPERTIES INSTALL_RPATH "@executable_path")
install(TARGETS Main RUNTIME DESTINATION bin)
install(
CODE "file(GET_RUNTIME_DEPENDENCIES EXECUTABLES \$<TARGET_FILE:Main> RESOLVED_DEPENDENCIES_VAR DEPS)\n \"
foreach(DEP \${DEPS})\n \
file(INSTALL \${DEPS} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)\n \
endforeach()")
After cmake -DCMAKE_INSTALL_PREFIX=/tmp ..
, make install
, /tmp/bin/Main
failed with dyld Library not loaded: @rpath/Foo.framework/Versions/A/Foo
, this is because only Foo
is copied to ${CMAKE_INSTALL_PREFIX}/bin
, but what needs to happen is the entire framework Foo.framework/Versions/A/Foo
to be copied to ${CMAKE_INSTALL_PREFIX}/bin
. There doesn't seem to be a function to take in the library name ${DEPS}
as an input and return the corresponding target as an output so we can check whether the target is a framework or not. I think what's better is for file(GET_RUNTIME_DEPENDENCIES)
to provide a new argument like RESOLVED_FRAMEWORK_DEPENDENCIES_VAR
to resolve this problem. Do you agree?