3

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.

Danijel
  • 8,198
  • 18
  • 69
  • 133
windenergy
  • 361
  • 1
  • 4
  • 13

2 Answers2

1

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.

TingPing
  • 2,129
  • 1
  • 12
  • 15
  • From what I understand of the manual, projectA would have to reside in the src folder of projectB in the subprojects directory. But if projectA is used by more than one project, how can it be in multiple places at once? – windenergy Jun 01 '17 at 20:04
  • You use `git` submodules typically. – TingPing Jun 02 '17 at 21:26
  • 1
    To Answer windnergy's question, put symlinks into the subprojects directory, pointing to the true location – Paulus Nov 16 '18 at 07:34
  • TingPing are you sure of this? I originally started with my libraries as subprojects, then read the meson FAQ which recommends using subdir over subproject. I was under the impression that subproject was for external projects (e.g. from github) over which user has minimal control, and subdir was for users own code? – Paulus Nov 16 '18 at 07:37
  • The question literally was about 2 separate projects. Yes a subdir is what you should use for single projects. – TingPing Nov 17 '18 at 23:36
  • I feel it makes sense to use subprojects since otherwise you could possibly get a 'ERROR: Second call to project' upon linking a subdir. – Nujufas Sep 17 '20 at 00:22
0

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])  
Danijel
  • 8,198
  • 18
  • 69
  • 133