--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,30 @@
 cmake_minimum_required(VERSION 3.13)
 project(Cppcheck VERSION 2.18.3 LANGUAGES CXX)

+# Set relative RPATH to the lib/ directory. Assuming binaries will be in either
+# libexec/ or bin/ the appropriate relative will be '../lib'
+#
+# This is set to be the default behaviour to minimise problems when we switch to
+# C++11/14 (requiring us to ship a libstdc++.so library for Linux distributions
+# that do not have a C++11/14 standard libraries installed by default.
+#
+# This also reduces the risk of shipping with bad RPATHs, at the expense of
+# developers having to set an additional property on targets that need to link
+# against libraries not in the RPATH below.
+
+if(APPLE)
+    set(CMAKE_MACOSX_RPATH ON)
+    set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version" FORCE)
+    set(CMAKE_INSTALL_NAME_DIR "@rpath")
+else()
+    set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/")
+endif()
+
+# Don't include build-time locations in the RPATH
+set(CMAKE_BUILD_WITH_INSTALL_RPATH     TRUE)
+set(CMAKE_SKIP_BUILD_RPATH             FALSE)
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH  FALSE)
+
 include(cmake/options.cmake)

 include(cmake/cxx11.cmake)
