systemc: Change the test binaries to use rpath.
authorGabe Black <gabeblack@google.com>
Tue, 28 Aug 2018 03:08:05 +0000 (20:08 -0700)
committerGabe Black <gabeblack@google.com>
Wed, 26 Sep 2018 00:03:24 +0000 (00:03 +0000)
Use rpath to link the gem5 dynamic library into the systemc test
binaries so that they don't have to be run from a particular directory
to resolve all their linking dependencies.

Change-Id: I66b18c23ae6bbf32a959022f8789fc8bdd3a6c6b
Reviewed-on: https://gem5-review.googlesource.com/12270
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>

src/systemc/tests/SConscript

index 086ffee26f4a8eed059182ca78f96c0288302427..74ec0e050afe90f9cc5d3491fb87b958c8008db4 100644 (file)
@@ -79,14 +79,24 @@ if env['USE_SYSTEMC']:
             env.Append(CPPPATH=test_dir.Dir('include'))
             env.Append(CPPPATH=ext_dir)
 
+            shared_lib_path = env['SHARED_LIB'][0].abspath
+            sl_dir, sl_base = os.path.split(shared_lib_path)
+            env.Append(LIBPATH=[sl_dir], LIBS=[sl_base])
+
             super(SystemCTestBin, cls).declare_all(env)
 
         def declare(self, env):
+            env = env.Clone()
             sources = list(self.sources)
             for f in self.filters:
                 sources = Source.all.apply_filter(f)
             objs = self.srcs_to_objs(env, sources)
-            objs = objs + env['SHARED_LIB'] + env['MAIN_OBJS']
+            objs = objs + env['MAIN_OBJS']
+            relpath = os.path.relpath(
+                    env['SHARED_LIB'][0].dir.abspath,
+                    self.path(env).dir.abspath)
+            env.Append(LINKFLAGS=Split('-z origin'))
+            env.Append(RPATH=env.Literal(os.path.join('\\$$ORIGIN', relpath)))
             return super(SystemCTestBin, self).declare(env, objs)
 
     tests = []