From fbc0f1719803d06b925bb69590e092c3d2fac12f Mon Sep 17 00:00:00 2001 From: Elias Daler Date: Sun, 19 Aug 2018 01:06:32 +0300 Subject: [PATCH] Fix RPATH for installed examples on Linux --- cmake/Macros.cmake | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index ecb37c8b2..65aa1aba9 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -230,14 +230,25 @@ macro(sfml_add_example target) target_link_libraries(${target} PRIVATE ${THIS_DEPENDS}) endif() + set(target_install_dir ${SFML_MISC_INSTALL_PREFIX}/examples/${target}) + + if(SFML_OS_LINUX OR SFML_OS_FREEBSD) + file(RELATIVE_PATH rel_lib_dir + ${CMAKE_INSTALL_PREFIX}/${target_install_dir} + ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) + + set_target_properties(${target} PROPERTIES + INSTALL_RPATH "$ORIGIN/${rel_lib_dir}") + endif() + # add the install rule install(TARGETS ${target} - RUNTIME DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples - BUNDLE DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples) + RUNTIME DESTINATION ${target_install_dir} COMPONENT examples + BUNDLE DESTINATION ${target_install_dir} COMPONENT examples) # install the example's source code install(FILES ${THIS_SOURCES} - DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} + DESTINATION ${target_install_dir} COMPONENT examples) if (THIS_RESOURCES_DIR) @@ -248,7 +259,7 @@ macro(sfml_add_example target) message(FATAL_ERROR "Given resources directory to install does not exist: ${THIS_RESOURCES_DIR}") endif() install(DIRECTORY ${THIS_RESOURCES_DIR} - DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} + DESTINATION ${target_install_dir} COMPONENT examples) endif()