INSTALL_NAME_DIR of shared library ignored with IOS_INSTALL_COMBINED
Here is an example project of a shared library (minimal, not even an interface header here...) which should have @rpath
as its install name prefix when being installed:
cmake_minimum_required(VERSION 3.15)
project(test C)
set(SOURCE_FILE "${CMAKE_BINARY_DIR}/empty.c")
file(WRITE ${SOURCE_FILE} "")
add_library(test SHARED ${SOURCE_FILE})
set_target_properties(test PROPERTIES INSTALL_NAME_DIR "@rpath") # same as MACOSX_RPATH TRUE?
install(TARGETS test)
If we run the following command to get a fat/combined ios library...
mkdir build
cd build
cmake .. -GXcode \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
-DCMAKE_IOS_INSTALL_COMBINED=YES \
-DCMAKE_INSTALL_PREFIX=./install
cmake --build . --target install
otool -L install/lib/libtest.dylib
... we get this wrong result for otool:
install/lib/libtest.dylib:
/Users/agirault/Projects/test-ios-install/build/Debug-iphonesimulator/libtest.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
/Users/agirault/Projects/test-ios-install/build/Debug-iphonesimulator
is incorrect: it should be @rpath
instead which is the value of INSTALL_NAME_DIR
, or at least the absolute path of the installed library and not of one of the built libraries. Note: I had to set INSTALL_NAME_DIR "@rpath"
because MACOSX_RPATH TRUE
did not seem to work
If we change the command to not do a combined build but a device only build (same with simulator only build)...
cmake .. -GXcode \
-DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_IOS_INSTALL_COMBINED=NO \
-DCMAKE_INSTALL_PREFIX=./install
cmake --build . --target install
otool -L install/lib/libtest.dylib
... the result of otool is correct:
install/lib/libtest.dylib:
@rpath/libtest.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
It seems the IOS_INSTALL_COMBINED
is behavior is incorrect for a shared library, whether INSTALL_NAME_DIR
is set or not.