windenergy
windenergy

Reputation: 391

How to include library and header files from another one of my Meson projects?

I have two projects on the go, one is a library, and the other wants to use some of that library.

My directory structure is:

Work/
      ProjectA/ 
               src/
                   include/
               build/

      ProjectB/ 
               src/
               build/

Assume both projects are built with meson-build, and projectA is the library.

1- How do I get ProjectB to see the include files of ProjectA? 2- How do I link the .lib file of projectA? (which is currently in the build folder)

When I try to create a dependency using relative paths, I cant find the thing that gets the .lib file? I am only able to get the header files using:

a_dep = declare_dependency(include_directories : include_directories('../../ProjectA/src/include'))

Note I am using windows, but also will be using linux.

Upvotes: 3

Views: 7494

Answers (2)

Danijel
Danijel

Reputation: 8606

One way to access the includes from another project is to use subprojects() and get_variable():

Project B:

project('Project B', ...) 
.
.
.
projectB_inc = [ 'inc', 'src/inc' ]
inc_dirs = include_directories(projectB_inc)
.
.
.
projecB_lib = static_library('projectB',...

Access Project B from Project A:

project('Project A', ...) 
.
.
.
pB = subproject('projectB')
pB_inc_dirs = rp.get_variable('inc_dirs')
.
.
.
# Use the include dirs: 

pA_inc_dirs = ... 

exe = executable(
  'projectA_exe',
  'main.c',
  ...
  include_directories:  [pA_inc_dirs, pB_inc_dirs])  

Upvotes: 0

TingPing
TingPing

Reputation: 2282

You should make one of the projects a subproject and extract the dependency from it:

It doesn't make sense to hardcode a path to a local project, that is broken by concept.

Upvotes: 0

Related Questions