Browse Source

Adjust RPATH to also search lib directory relative to the executables.
Closes #448.

Yao Wei Tjong 姚伟忠 11 years ago
parent
commit
a5e34ea512
2 changed files with 15 additions and 11 deletions
  1. 1 1
      Rakefile
  2. 14 10
      Source/CMakeLists.txt

+ 1 - 1
Rakefile

@@ -185,7 +185,7 @@ task :ci_package_upload do
     upload_dir = "/home/frs/project/#{ENV['TRAVIS_REPO_SLUG']}/Snapshots"
     if ENV['SITE_UPDATE']
       # Download source packages from GitHub
-      system "export SNAPSHOT_VER=$(git describe $TRAVIS_COMMIT |ruby -pe 'gsub(/-(?!g)/s, %q{.})'); wget -q https://github.com/$TRAVIS_REPO_SLUG/tarball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.tar.gz && wget -q https://github.com/$TRAVIS_REPO_SLUG/zipball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.zip" or abort 'Failed to get source packages'
+      system "export SNAPSHOT_VER=$(git describe $TRAVIS_COMMIT |ruby -pe 'gsub(/-(?!g)/, %q{.})'); wget -q https://github.com/$TRAVIS_REPO_SLUG/tarball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.tar.gz && wget -q https://github.com/$TRAVIS_REPO_SLUG/zipball/$TRAVIS_COMMIT -O Urho3D-$SNAPSHOT_VER-Source-snapshot.zip" or abort 'Failed to get source packages'
       # Only keep the snapshots from the last 30 revisions
       system "for v in $(sftp [email protected] <<EOF |tr ' ' '\n' |grep Urho3D- |cut -d '-' -f1,2 |uniq |tail -n +31
 cd #{upload_dir}

+ 14 - 10
Source/CMakeLists.txt

@@ -127,20 +127,24 @@ include (CPack)
 
 # Setup RPATH settings
 if (NOT WIN32)
-    if (APPLE AND (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12))
-        set (CMAKE_MACOSX_RPATH TRUE)
-        # Note for older version CMake users, you may need to use DYLD_LIBRARY_PATH environment variable to specify the path where Urho3D shared library is being installed
-        # when attempting to execute the samples or tools installed by Urho3D SDK with SHARED lib type
-    endif ()
+    # Add RPATH entries when building
     set (CMAKE_SKIP_BUILD_RPATH FALSE)
+    # But don't set them yet in the build tree
     set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
-    set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+    if (APPLE)
+        if (CMAKE_VERSION VERSION_GREATER 2.8.12 OR CMAKE_VERSION VERSION_EQUAL 2.8.12)
+            set (CMAKE_MACOSX_RPATH TRUE)
+        endif ()
+        set (ORIGIN @loader_path)
+    else ()
+        set (ORIGIN $ORIGIN)
+    endif ()
+    # When installing set the first RPATH entry to the library location relative to the executable
+    set (CMAKE_INSTALL_RPATH ${ORIGIN}/../../../lib${LIB_SUFFIX}/Urho3D)    # The library location is based on SDK install destination as defined above
+    # The second entry to the install destination of the library, if the destination location is not in the system default search path
     list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} isSystemDir)
     if (isSystemDir STREQUAL -1)
-        # If SDK installation location is not in the system default search paths then add the library installation location to target's RPATH
-        set (CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${DEST_LIBRARY_DIR})
-        # Note for Linux users, you should not need to use LD_LIBRARY_PATH environment variable pointing to Urho3D shared library path anymore when executing installed targets
-        # even when the shared library is installed on a non-default installation location
+        list (APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${DEST_LIBRARY_DIR})
     endif ()
 endif ()