Force dependency to assume header-file
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 1.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 33
Description
# Description
This issue occured during porting a legacy project from CMake to meson-build. I realize that this
task contains some constraints that may be irrelevant in many other cases. However, I need to deal
with the following restrictions that could (currently) not be changed, in order to avoid inference
or incompatibilities with the existing build-system:
* The project uses a compile-time generated C-Source-file that is then included by a different
source-file
* This generated source file contains exported symbols that are configuration dependent (which
implies that it would be extra effort to also generate header-files)
* I want to avoid any changes to the existing build-system and source-files, as the meson build is
currently just created in packagefiles for a wrap (this also implies that I couldn't change any
much about the include of C-files or even rename the file to a header, etc.)
* The generated .c-file is generated by a custom binary, also build by the build-system. Therefore,
this binary also is just required, if the upper build-targets are required (this implies that
I want to avoid `build_always` or `build_by_default` as it would add a lot of compile-time that
may not be necessary in some cases!)
Now my issue:
* I generate the .c-file with a custom-target
* I then need to represent the dependency. I do this by adding `declare_dependency:sources` to my
upstream target
* The problem is now that the generated source is compiled. Which will lead (due to the include in
the main source file) to a redeclaration linker-error - this also means that `build_always` and
`build_by_default` wouldn't resolve my problems, as the generated source-file is still not
treated like a header then
# Demonstrator
I resembled the problem in a small example, see the `meson.build` file below:
```
project('hello', 'c',
version : '0.1',
default_options : ['warning_level=3'])
dep_src_c = custom_target('dep_src_c',
command: ['echo', '''
#include
void print_hello(void){ printf("hello world\n");}
'''],
output: 'dep_src.c',
capture: true,
)
main_c = custom_target('main_c',
command: ['echo', '''
#include
#include "dep_src.c"
int main(void) {
print_hello();
return 0;
}
'''],
output: 'main.c',
capture: true,
)
exe = executable('hello', [],
dependencies: [
declare_dependency(sources:main_c), # This is uncritical
# This is the critical dependency:
declare_dependency(sources: dep_src_c), # Doesn't work out for me
#declare_dependency(extra_files: dep_src_c), # Neither does this
],
include_directories: ['.'],
install : true)
test('basic', exe)
```
# Options
I evaluated several options, like using different other features of `declare_dependency` or
exchanging the `custom_target` by `run_command`. However all of this does neither seem sufficient
nor satisfying.
My initial solution was, to change the parameter `extra_files` of `declare_dependency` to allow
`custom_tgt` types as well. This would be a general necessary improvement. However, I realized that
it wouldn't resolve my problem, as `extra_files` are generated and installed as part of a
build-target but meson-build will not build them as a prerequisite for the compilation process.
However, changing this behavior in meson does exceed my current insight in the meson dependency
internals.
Any feelings about the problem or some proposal?
Contributor guide
Research direction
Start with the meson.build demonstrator and trace how custom_target outputs passed through declare_dependency(sources) and extra_files are scheduled. Reproduce the example, then inspect the dependency handling for a way to make dep_src.c a build prerequisite without compiling it; done means the generated file is available before main.c compilation and the example links without redeclaration errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100