diff --git a/CMakeLists.txt b/CMakeLists.txt index ce54658c8..262116a1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,21 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) set(CMAKE_INCLUDE_CURRENT_DIR ON) +if (DEFINED CMAKE_INSTALL_RPATH) + set(Base_rpath "${CMAKE_INSTALL_RPATH}") +else() + if(BUILD_SHARED_LIBS) + set(p "${CMAKE_INSTALL_FULL_LIBDIR}") + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${p}" i) + if("${i}" STREQUAL "-1") + set(Base_rpath "${p}") + endif() + endif() +endif() + +# Append non-standard external dependency directories, if any. +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + # Check integrity of node structure when compiled as debug add_compile_options($<$:-DCMARK_DEBUG_NODES>) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 82bdc04e6..523b2cb82 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,6 @@ add_library(cmark xml.c) cmark_add_compile_options(cmark) set_target_properties(cmark PROPERTIES - MACOSX_RPATH TRUE OUTPUT_NAME "cmark" # Avoid name clash between PROGRAM and LIBRARY pdb files. PDB_NAME libcmark @@ -56,7 +55,8 @@ add_executable(cmark_exe main.c) cmark_add_compile_options(cmark_exe) set_target_properties(cmark_exe PROPERTIES - OUTPUT_NAME "cmark") + OUTPUT_NAME "cmark" + INSTALL_RPATH "${Base_rpath}") target_link_libraries(cmark_exe PRIVATE cmark)