Skip to content

Instantly share code, notes, and snippets.

@jtanx
Created August 3, 2019 07:22
Show Gist options
  • Save jtanx/be16cfcd8fb5a73a9d70baeed8464a3e to your computer and use it in GitHub Desktop.
Save jtanx/be16cfcd8fb5a73a9d70baeed8464a3e to your computer and use it in GitHub Desktop.
Custom library install path for MacOS and CMake
# Suppose under certain circumstances you want to set the library path explicitly to something, but
# in the usual case, you would like it to remain as an rpath.
# This adds a variable to the install script that can be overridden
install(CODE "
if(NOT DEFINED CUSTOM_LIBRARY_PREFIX)
set(CUSTOM_LIBRARY_PREFIX \"@rpath\")
endif()
")
set_property(TARGET my_target PROPERTY INSTALL_NAME_DIR "\${CUSTOM_LIBRARY_PREFIX}")
# Now when install is run, it keeps the same behaviour as before (setting the path to @rpath/my_target.dylb)
# But suppose you manually invoke the install script like:
cmake -DCUSTOM_LIBRARY_PREFIX=/my/custom/path -P cmake_install.cmake
# Then now the library path will be /my/custom/path/my_target.dylib instead of @rpath/my_target.dylib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment