Idiomatic way to encapsulate data in subprojects #15031
Unanswered
mjziebarth
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Dear meson community,
I've come upon the following data encapsulation (or installation) problem for which I have, so far, only found a quite hacky solution.
The setup
I have a subproject that creates a library, say
libA
, and a database, sayA.db
, which is used by said library. I need both in two different projects where they are handled differently (one, P1, is a Python package and the other one, P2, a standalone C++ application). Handling the library in a subproject works like a charm. Handling the database, however, is a totally different story.The subproject boils down to something like this:
So far, everything works great. Both the static library and the database are generated and work as
expected.
The problem
Things have become difficult now that I have tried to encapsulate both targets as subprojects to different projects.
I can easily 'export' the static library from the subproject to any depending project via
declare_dependency
.The issue is the install path of the database. The subproject A could the install path in the
custom_target
call.However, subproject A does not know a priori which install path to use. The Python package P1 has different
requirements than the executable P1, yet both require the same library and database to be built.
The following ideas I had to solve this issue have turned out to be dead ends (so far):
A_db
in the call tosubproject()
. I tried to do that by definingpath parameters in
meson.options
and passing those via thedefault_options
argument of thesubproject()
call. However, this did not seem to work for me. Is that something that should, in theory, work? (I.e. could there
be some defines or namespace changes that could have interfered with this approach?)
custom_target
into the root project and install the generateddatabase file from there. However, when trying to do so with
install_data
(obtaining the path to the generatedfile via the
full_path
(s) of the imported custom target), I encountered the problem that the files have not beengenerated. I reckon that this is probably not a Meson-idiomatic way...
The hacky solution
What has worked for me is to make use of the combination of
depends
,input
, andinstall_dir
of thecustom_target()
function. I've written a small Python scriptroot/copyfile.py
to copy files between paths (clumsy but shouldbe rather OS agnostic), which has then allowed me to use
where
A_db_install_dir
is the P1-P2-dependent install directory, andA_db_file
has been obtained fromA_db
viagiven that
A_db
is only one file.For now, I think I can work with this hack, but it seems quite unidiomatic to me.
Q: Is there an idiomatic way to handle this situation?
There is a chance that I have missed a very obvious solution to this problem, but so far, I have not stumbled upon any.
Beta Was this translation helpful? Give feedback.
All reactions