[CMake] install name for fortran dylibs on mac

Dan Kegel dank at kegel.com
Sat May 3 18:23:41 EDT 2014


Have you tried just using INSTALL_NAME_DIR, e.g.

cmake_minimum_required(VERSION 2.8)
set(MYLIBDIR "${CMAKE_SOURCE_DIR}/lib")

add_library(foo SHARED foo.c)
set_target_properties(
   foo
   PROPERTIES
   INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
)

add_executable(x x.c)
target_link_libraries(x foo)

install(TARGETS foo x
   RUNTIME DESTINATION "${DESTDIR}${CMAKE_INSTALL_PREFIX}/bin"
   LIBRARY DESTINATION "${DESTDIR}${CMAKE_INSTALL_PREFIX}/lib"
)

?
For a fully-worked C example with script, see
http://kegel.com/macosx/rpath/demo-install_name-cmake-2.8/
Try just building and running that example and see if it does what you want.


On Sat, May 3, 2014 at 3:15 PM, Izaak Beekman <ibeekman at umiacs.umd.edu> wrote:
> So I noticed the CMAKE_MACOSX_RPATH variable, and tried setting it, which
> does result in the install name of the dylib being set to
> @rpath/dylibname.so BUT when I link it in an executable tool -L just shows
> the dylib as @rpath/dylibname.so and the linker fails to find it at run
> time. What is the proper way to get CMake to build the executable linking
> against the dylib and be able to run it in the build tree and install tree?
>
> Izaak Beekman
> ===================================
> (301)244-9367
> UMD-CP Visiting Graduate Student
> Aerospace Engineering
> ibeekman at umiacs.umd.edu
> ibeekman at umd.edu
>
>
> On Sat, May 3, 2014 at 10:54 AM, Dan Kegel <dank at kegel.com> wrote:
>>
>> On Sat, May 3, 2014 at 7:17 AM,  <clinton at elemtech.com> wrote:
>> > Use at least CMake 2.8.12 and in your library project add this:
>> > set(CMAKE_MACOSX_RPATH 1)
>> > ...
>> > For more details:
>> > http://www.kitware.com/blog/home/post/510
>>
>> What he said.  See also past discussion at
>> http://web.archiveorange.com/archive/v/5y7PkspCBZwiWhvodZSP
>> I put together some tiny demos showing various ways to do it, with
>> walkthroughs, at
>> http://kegel.com/macosx/rpath/
>
>


More information about the CMake mailing list