[CMake] INSTALL_NAME_DIR with IMPORTED targets
Justin Holewinski
shawmishrak at gmail.com
Wed Nov 4 10:23:32 EST 2009
Is there a way to make CMake honor the INSTALL_NAME_DIR property for
IMPORTED library targets?
For the Mac OS X build of an application, I have a binary-only, third-
party library in the form of a .dylib that I keep in the source tree.
I add it to my CMake build script as such:
ADD_LIBRARY(foo SHARED IMPORTED)
SET_TARGET_PROPERTIES(foo PROPERTIES IMPORTED_LOCATION "$
{THIRD_PARTY_LIB}")
where THIRD_PARTY_LIB is the path to the library in the source tree.
When I configure the bundle for the application, I add ``foo'' as a
link library with TARGET_LINK_LIBRARIES, e.g.
ADD_EXECUTABLE(myexe MACOSX_BUNDLE "<sources>")
TARGET_LINK_LIBRARIES(myexe foo ${OTHER_LIBRARY_TARGETS})
where OTHER_LIBRARY_TARGETS are additional shared libraries built for
the project.
I install with:
INSTALL(TARGETS myexe DESTINATION .)
INSTALL(TARGETS ${OTHER_LIBRARY_TARGETS} DESTINATION myexe.app/
Contents/MacOS)
INSTALL(FILES ${THIRD_PARTY_LIB})
As is, this builds the app bundle but does not properly adjust
the .dylib paths in the binaries. I can fix this with:
SET_TARGET_PROPERTIES(${OTHER_LIBRARY_TARGETS} PROPERTIES
INSTALL_NAME_DIR "@executable_path")
and this works great for the shared libraries built for the project,
but this does *not* work for the IMPORTED library:
SET_TARGET_PROPERTIES(foo PROPERTIES INSTALL_NAME_DIR
"@executable_path")
or
SET_TARGET_PROPERTIES(${THIRD_PARTY_LIB} PROPERTIES INSTALL_NAME_DIR
"@executable_path")
In either case, ``otool -L'' shows that the third-party library name
is not prepended with @executable_path and hence trying to launch the
bundle as an application fails with an error saying the third-party
library could not be located.
Is there a way to make CMake honor INSTALL_NAME_DIR for IMPORTED
targets, or perhaps a better way of linking against and installing
third-party libraries on Mac OS X using CMake's install provisions? I
could probably use a post-build shell script, but I would like to do
this within the CMake build scripts, if possible.
Thanks!
More information about the CMake
mailing list