[igt-dev] [PATCH 1/1] meson: Set up runpath for installed executables
Daniel Vetter
daniel at ffwll.ch
Tue Jan 30 07:55:50 UTC 2018
On Fri, Jan 19, 2018 at 01:44:07PM +0200, Petri Latvala wrote:
> Meson builds libigt as a shared library, and executables naturally
> have to find it at runtime. Using default options puts the library to
> a normal search paths, but any modifications to the directory options
> or a non-conventional prefix setting makes using LD_LIBRARY_PATH or
> other library search means mandatory.
>
> Add a build option 'use_rpath' (default: false) that makes meson set
> up DT_RUNPATH at install time, pointing to the library with a path
> relative to the executable, using $ORIGIN. That way the installed
> executables find the library even when not installed to exactly the
> build-time configured prefix path, a setup CI occasionally uses.
>
> Signed-off-by: Petri Latvala <petri.latvala at intel.com>
> Cc: Tomi Sarvela <tomi.p.sarvela at intel.com>
> Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Not exactly the most knowledgeable person in this area, but still:
Acked-by: Daniel Vetter <daniel.vetter at ffwll.ch>
> ---
> meson_options.txt | 4 ++++
> tests/meson.build | 26 ++++++++++++++++++++++++++
> tools/meson.build | 26 ++++++++++++++++++++++++++
> 3 files changed, 56 insertions(+)
> create mode 100644 meson_options.txt
>
> diff --git a/meson_options.txt b/meson_options.txt
> new file mode 100644
> index 00000000..41be35e0
> --- /dev/null
> +++ b/meson_options.txt
> @@ -0,0 +1,4 @@
> +option('use_rpath',
> + type : 'boolean',
> + value : false,
> + description : 'Set runpath on installed executables for libigt.so')
> diff --git a/tests/meson.build b/tests/meson.build
> index 2322217d..b764b7f7 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -255,24 +255,49 @@ if alsa.found() and gsl.found()
> test_deps += alsa
> endif
>
> +if get_option('use_rpath')
> + # Set up runpath for the test executables towards libigt.so.
> + # The path should be relative to $ORIGIN so the library is
> + # still found properly even if installed to a path other than
> + # prefix.
> +
> + # libdir and libexecdir are pathnames relative to
> + # prefix. meson enforces this.
> +
> + # Start from the executable
> + rpathdir = '$ORIGIN'
> + # Executables are installed in libexecdir. Add a .. for each
> + # directory name in it.
> + foreach p : libexecdir.split('/')
> + rpathdir = join_paths(rpathdir, '..')
> + endforeach
> + # Add relative path to libdir
> + rpathdir = join_paths(rpathdir, libdir)
> +else
> + rpathdir = ''
> +endif
> +
> test_executables = []
>
> foreach prog : test_progs
> test_executables += executable(prog, prog + '.c',
> dependencies : test_deps,
> install_dir : libexecdir,
> + install_rpath : rpathdir,
> install : true)
> endforeach
>
> test_executables += executable('perf_pmu', 'perf_pmu.c',
> dependencies : test_deps + [ lib_igt_perf ],
> install_dir : libexecdir,
> + install_rpath : rpathdir,
> install : true)
> test_progs += 'perf_pmu'
>
> executable('testdisplay', ['testdisplay.c', 'testdisplay_hotplug.c'],
> dependencies : test_deps,
> install_dir : libexecdir,
> + install_rpath : rpathdir,
> install : true)
> test_progs += 'testdisplay'
>
> @@ -292,6 +317,7 @@ endforeach
> executable('gem_stress', 'gem_stress.c',
> install : true,
> install_dir : libexecdir,
> + install_rpath : rpathdir,
> dependencies : igt_deps)
>
> # IMPORTANT: These tests here are all disabled because the result in sometime
> diff --git a/tools/meson.build b/tools/meson.build
> index acd9242d..98366a09 100644
> --- a/tools/meson.build
> +++ b/tools/meson.build
> @@ -50,9 +50,32 @@ if libdrm_intel.found()
> tool_deps += zlib
> endif
>
> +if get_option('use_rpath')
> + # Set up runpath for the test executables towards libigt.so.
> + # The path should be relative to $ORIGIN so the library is
> + # still found properly even if installed to a path other than
> + # prefix.
> +
> + # libdir and bindir are pathnames relative to prefix. meson
> + # enforces this.
> +
> + # Start from the executable
> + rpathdir = '$ORIGIN'
> + # Executables are installed in bindir. Add a .. for each
> + # directory name in it.
> + foreach p : bindir.split('/')
> + rpathdir = join_paths(rpathdir, '..')
> + endforeach
> + # Add relative path to libdir
> + rpathdir = join_paths(rpathdir, libdir)
> +else
> + rpathdir = ''
> +endif
> +
> foreach prog : tools_progs
> executable(prog, prog + '.c',
> dependencies : tool_deps,
> + install_rpath : rpathdir,
> install : true)
> endforeach
>
> @@ -63,18 +86,21 @@ if libudev.found()
> ]
> executable('intel_dp_compliance', sources : intel_dp_compliance_src,
> dependencies : [tool_deps, libudev],
> + install_rpath : rpathdir,
> install : true)
> endif
>
> intel_l3_parity_src = [ 'intel_l3_parity.c', 'intel_l3_udev_listener.c' ]
> executable('intel_l3_parity', sources : intel_l3_parity_src,
> dependencies : tool_deps,
> + install_rpath : rpathdir,
> install : true)
>
> intel_reg_src = [ 'intel_reg.c', 'intel_reg_decode.c', 'intel_reg_spec.c' ]
> executable('intel_reg', sources : intel_reg_src,
> dependencies : tool_deps,
> install : true,
> + install_rpath : rpathdir,
> c_args : [
> '-DIGT_DATADIR="@0@"'.format(datadir),
> ])
> --
> 2.14.1
>
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
More information about the igt-dev
mailing list