Implement changes for CMake policy 0068
authorErik Lindahl <erik@kth.se>
Wed, 27 Dec 2017 11:50:51 +0000 (12:50 +0100)
committerMark Abraham <mark.j.abraham@gmail.com>
Thu, 4 Jan 2018 10:14:25 +0000 (11:14 +0100)
CMake-3.9 introduced a changed behavior for RPATH
vs. install_name options on OS X. This avoids relying
on functionality that will be removed in future
CMake versions.

Change-Id: Ic3697615bc372d09d45dfd007ba5a088624de051

CMakeLists.txt

index 7745cd0012206cdba57ae1aaa6abfffed8455df0..73469b7703e21ce8d266813e7881150616603e8c 100644 (file)
@@ -857,13 +857,18 @@ else()
     # RPATHs), and makes the binaries in the build tree relocatable.
     if(GMX_LIB_INSTALL_DIR STREQUAL "lib")
         set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+        if(POLICY CMP0068)
+            cmake_policy(SET CMP0068 NEW) # From CMake-3.9
+            set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
+        endif()
     endif()
     # Set the RPATH as relative to the executable location to make the
     # binaries relocatable.
-    if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") #Assume OS X >=10.5
-        set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${GMX_LIB_INSTALL_DIR}")
-    else()
+    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") #Assume OS X >=10.5
         set(CMAKE_INSTALL_RPATH "@executable_path/../${GMX_LIB_INSTALL_DIR}")
+        set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_RPATH})
+    else()
+        set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${GMX_LIB_INSTALL_DIR}")
     endif()
     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
     set(CMAKE_MACOSX_RPATH 1)