Skip to content

Instantly share code, notes, and snippets.

@robertmaynard
Last active May 7, 2020 07:11
Show Gist options
  • Save robertmaynard/5750737 to your computer and use it in GitHub Desktop.
Save robertmaynard/5750737 to your computer and use it in GitHub Desktop.
CMake RPath Support Example
cmake_minimum_required(VERSION 2.8.12)
project(OSXRPath)
# enable @rpath in the install name for any shared library being built
set(CMAKE_MACOSX_RPATH 1)
# add a shared library
add_library(foo SHARED foo.cpp)
# use the shared library
# note: CMake will add an RPATH to this executable which is the absolute location of libfoo.dylib in the build tree.
add_executable(bar bar.cpp)
# installation
install(TARGETS foo DESTINATION lib)
install(TARGETS bar DESTINATION bin)
# the install RPATH for bar to find foo in the install tree.
# if the install RPATH is not provided, the install bar will have none
set_target_properties(bar PROPERTIES INSTALL_RPATH "@loader_path/../lib")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment