Hello,
lets say your project includes building a lot of libraries, and the dependency graph of these libraries is given by this acyclic graph. You might solve this by writing
libEvar = library('mylibE', 'fileE.cpp', link_with : [])
libDvar = library('mylibD', 'fileD.cpp', link_with : [libEvar])
libCvar = library('mylibC', 'fileC.cpp', link_with : [libDvar, libEvar])
libBvar = library('mylibB', 'fileB.cpp', link_with : [libDvar])
libAvar = library('mylibA', 'fileA.cpp', link_with : [libBvar, libCvar, libEvar])
This works, but there is one major problem: It breaks once you change the order of those lines. If all of these lines are in the same meson.build file, then putting them into the correct order is easy. But if these lines are scattered across multiple meson.build files in nested subdirectories, then it might no longer be possible (Imagine if libEvar and libCvar are in a subdirectory of libDvar's directory).
One solution would be to write this:
libs = []
# The order of the following 5 lines is irrelevant
libs += [['mylibA', 'fileA.cpp', ['mylibB', 'mylibC', 'mylibE']]]
libs += [['mylibB', 'fileB.cpp', ['mylibD']]]
libs += [['mylibC', 'fileC.cpp', ['mylibD', 'mylibE']]]
libs += [['mylibD', 'fileD.cpp', ['mylibE']]]
libs += [['mylibE', 'fileE.cpp', []]]
lookup = {}
foreach step : [1,1,1,1,1,1,1,1,1,1,1,1,1,1,0]
foreach lib : libs
flag = true
deps = []
foreach dep : lib[2]
if dep not in lookup
flag = false
else
deps += lookup[dep]
endif
endforeach
assert(step == 1 or flag, 'error building the dependency graph')
if flag and lib[0] not in lookup
lookup += {lib[0] : library(lib[0], lib[1], link_with : deps)}
endif
endforeach
endforeach
This basically does what I want/need, but it feels like very bad style. Meson should have some functionality to build these acyclic graphs itself.
This lazy function would also solve similar problems that arise if you try to use an executable to generate sources, before building that executable.
I thought of using subprojects instead of subdirs, but that would result in sandbox violations if some libraries share source files with other libraries.
Hello,
lets say your project includes building a lot of libraries, and the dependency graph of these libraries is given by this acyclic graph. You might solve this by writing
This works, but there is one major problem: It breaks once you change the order of those lines. If all of these lines are in the same meson.build file, then putting them into the correct order is easy. But if these lines are scattered across multiple meson.build files in nested subdirectories, then it might no longer be possible (Imagine if libEvar and libCvar are in a subdirectory of libDvar's directory).
One solution would be to write this:
This basically does what I want/need, but it feels like very bad style. Meson should have some functionality to build these acyclic graphs itself.
This lazy function would also solve similar problems that arise if you try to use an executable to generate sources, before building that executable.
I thought of using subprojects instead of subdirs, but that would result in sandbox violations if some libraries share source files with other libraries.