Thomas Kaltfuss
Thomas Kaltfuss

Reputation: 33

Meson build: Add dependency path for executable manually

What I'd like to do, is rather easy: Compile a project using the Meson build system + manually including a dependency.

However, there's one dependency, which I do not want to install to /usr/lib, due to System Integrity Protection on Mac. (I know I can turn this off; I don't want to.)

So basically I wanna do: g++ -L[path_to_lib] [files...] but use meson instead of g++.

However, this seems to be super complicated. After doing some research and unsuccessfully adding cc = meson.get_compiler('c') dep = cc.find_library('granite' dirs: [ [path_to_dep] ]) to my meson.build file (which doesn't work, as it handles libraries, not dependencies) I'm left feeling rather dumb.

Please help!

I know I could just add the relevant path to $PATH, but that is more than overkill and I refuse to believe that there isn't another nice quick way to do so. (As is with the ancient c compiler...)

Upvotes: 2

Views: 4719

Answers (1)

pmod
pmod

Reputation: 10997

You should be able to solve your problem without modifying meson.build file (I mean leave granite as ordinary dependency). meson uses pkg-config to search for dependencies, so if you add your non-standard path containing granite package config file to PKG_CONFIG_PATH it will find it. And in this case granite package config file should be correct, of course, i.e. contain correct library and header paths, which should be correct if you configure installation of granite with something like:

# Configure:
$ cmake -DCMAKE_INSTALL_PREFIX=/some/path...
# Build:
$ make
# Install (need sudo?):
$ make install

$ export PKG_CONFIG_PATH=/some/path...:$PKG_CONFIG_PATH

granite_dep = dependency('granite')
my_app = executable('my_app',
  dependencies : [granite_dep]
  ...

However, note that in case of find_library() according to reference manual:

The result object can be used just like the return value of dependency

So, it should work:

granite_dep = cc.find_library('granite', dirs : [path])
executable(..., dependencies : granite_dep)

But, I recommend standard way that utilizes pkg-config, because granite can also have dependencies that you will not be able to automatically pick up this way.

Upvotes: 3

Related Questions